Last active
January 17, 2024 11:37
-
-
Save aslamhadi/13cd5068b56dcbe9878f36adf99f6a6d to your computer and use it in GitHub Desktop.
Shell script to dump mysql db and upload it to Back Blaze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to run