Last active
March 28, 2024 16:14
-
-
Save firestar/8e57ae573bdabf60610537442ea8d753 to your computer and use it in GitHub Desktop.
MySQL Backup to Google Drive (requires gdrive)
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 | |
# backup Path | |
BACKUP_PATH="./mysql" | |
# database settings | |
DB_NAME=$1 | |
DB_USER="user" | |
DB_PASS="password" | |
# current timestamp | |
TIMESTAMP=$(date +%s) | |
# google drive folder | |
googleFolderID="insertgooglefolderidhere" | |
FILENAME=${DB_NAME}_${TIMESTAMP}.sql | |
# svn up the content | |
cd ${BACKUP_PATH} | |
# remove previous backups | |
rm ./*.sql | |
rm ./*.gz | |
# dump the database using the mysql administrator - so we can see all dbs | |
mysqldump -u$DB_USER -p$DB_PASS --opt --routines --skip-extended-insert --compact --force "${DB_NAME}" > "${FILENAME}" | |
# compress file | |
tar -czvf ${FILENAME}.gz ${FILENAME} | |
# upload file to google drive | |
$GOPATH/bin/gdrive upload --parent ${googleFolderID} ${FILENAME}.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
called with ./mysql dbname