Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions task.sh
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
#! /bin/bash

BACKUP_DIR="$HOME/backups/mysql/shopdb"
mkdir -p "$BACKUP_DIR" || { echo "Error: could not create backup directory $BACKUP_DIR"; exit 1; }

if [ -z "$DB_USER" ] || [ -z "$DB_PASSWORD" ]; then
echo "Error: DB_USER and DB_PASSWORD must be set as environment variables."
exit 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exit 1 within this one-line if block is not terminated with a semicolon or newline before fi; in this form the shell will report a syntax error. Add ; after exit 1 (or put it on its own properly terminated line) so the if statement is valid.

fi

TIMESTAMP=$(date +%Y%m%d_%H%M%S)

echo "INFO: Creating full backup of ShopDB"
mysqldump -u "$DB_USER" -p"$DB_PASSWORD" ShopDB --result-file="$BACKUP_DIR/full_backup_$TIMESTAMP.sql"

echo "INFO: Restoring full backup into ShopDBReserve"
mysql -u "$DB_USER" -p"$DB_PASSWORD" ShopDBReserve < "$BACKUP_DIR/full_backup_$TIMESTAMP.sql"


echo "INFO: Creating data-only backup of ShopDB"
mysqldump -u "$DB_USER" -p"$DB_PASSWORD" --no-create-info ShopDB --result-file="$BACKUP_DIR/data_backup_$TIMESTAMP.sql"

echo "INFO: Restoring data backup into ShopDBDevelopment"
mysql -u "$DB_USER" -p"$DB_PASSWORD" ShopDBDevelopment < "$BACKUP_DIR/data_backup_$TIMESTAMP.sql"

echo "INFO: Backup and restore procedure completed successfully."
Loading