Last active
May 19, 2019 21:36
-
-
Save mbpcoder/7c4884b0075c45d0bec10db2b135d35c to your computer and use it in GitHub Desktop.
Mysql Database Backup and Send over FTP
This file contains hidden or 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 | |
#DESCRIPTION: automatic daily mysql backup | |
#CRON: | |
# example cron for daily db backup @ 9:15 am | |
# min hr mday month wday command | |
# 15 9 * * * /Users/[your user name]/scripts/mysql_backup.sh | |
#RESTORE FROM BACKUP | |
#$ gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname] | |
# include mysql and mysqldump binaries for cron bash user | |
PATH=$PATH:/usr/local/mysql/bin | |
#============================================================================== | |
# METHODS | |
BACKUP_FILE="/tmp/backup/$(date +%F).database_name.sql.gz" | |
printf "$BACKUP_FILE\n" | |
ls | |
function backup_database(){ | |
$(mysqldump -u username -p'password' database_name --ignore-table=table_name | gzip -9 > $BACKUP_FILE) | |
} | |
function send_to_ftp(){ | |
scp $BACKUP_FILE admin:[email protected]:/home/admin/backup | |
} | |
function send_to_gdrive(){ | |
/home/backup/gdrive upload --parent directory_token $BACKUP_FILE | |
} | |
#============================================================================== | |
# RUN SCRIPT | |
#============================================================================== | |
backup_database | |
send_to_ftp | |
send_to_gdrive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment