Skip to content

Instantly share code, notes, and snippets.

@aslamhadi
Last active January 17, 2024 11:37
Show Gist options
  • Save aslamhadi/13cd5068b56dcbe9878f36adf99f6a6d to your computer and use it in GitHub Desktop.
Save aslamhadi/13cd5068b56dcbe9878f36adf99f6a6d to your computer and use it in GitHub Desktop.
Shell script to dump mysql db and upload it to Back Blaze
#!/bin/bash
DB_NAME=""
DB_PASSWORD=""
DB_USER=""
DB_HOST=""
TODAY_DATE="$(date +'%d_%m_%Y_%H_%M_%S')"
FILENAME="$DB_NAME$TODAY_DATE".gz
BACKUP_DIR="/home/aslam/backup/$FILENAME"
# dump db in backup folder
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')"
mysqldump -u $DB_USER -p$DB_PASSWORD -h $DB_HOST -e --opt -c $DB_NAME | gzip -c > $BACKUP_DIR
echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')"
# upload to b2
B2_ACC_ID=""
B2_APP_KEY=""
B2_BUCKET_NAME=""
echo "starting upload db to b2 at $(date +'%d-%m-%Y %H:%M:%S')"
/usr/local/bin/b2 authorize-account $B2_ACC_ID $B2_APP_KEY
/usr/local/bin/b2 upload_file $B2_BUCKET_NAME $BACKUP_DIR $FILENAME
echo "finished uploading db to b2 at $(date +'%d-%m-%Y %H:%M:%S')"
exit 0
@aslamhadi
Copy link
Author

How to run

  • pip install --ignore-installed b2
  • chmod +x backup.sh
  • bash backup.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment