Last active
May 7, 2022 18:04
-
-
Save dwdraju/d6bde53d16735bf2ae661be042a694e4 to your computer and use it in GitHub Desktop.
Send MySQL Backup to Google Cloud Storage(GCS)
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 | |
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") | |
BACKUP_DIR="/home/ubuntu/backup/$TIMESTAMP" | |
MYSQL_USER="****" | |
MYSQL=/usr/bin/mysql | |
MYSQL_PASSWORD="****" | |
MYSQLDUMP=/usr/bin/mysqldump | |
mkdir -p "$BACKUP_DIR/" | |
databases="db1 db2 db3 db4" | |
for db in $databases; do | |
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db --routines | gzip > "$BACKUP_DIR/$db-$TIMESTAMP.gz" | |
gsutil cp $BACKUP_DIR/$db-$TIMESTAMP.gz gs://mydb-$db-backup/ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in case if someone wants to run this script with
cron
,gsutil
would need additional context. add following to the beginning of the script.