Created
May 15, 2017 09:28
-
-
Save AbhishekGhosh/f1992249cc7fbeb4f43c3f04346f7c0b to your computer and use it in GitHub Desktop.
mysql backup and upload to FTP
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 | |
############### Infos - Edit them accordingly ######################## | |
DATE=`date +%Y-%m-%d_%H%M` | |
LOCAL_BACKUP_DIR="/backups" | |
DB_NAME="database_name" | |
DB_USER="root" | |
DB_PASSWORD="root_password" | |
FTP_SERVER="111.111.111.111" | |
FTP_USERNAME="ftp-user" | |
FTP_PASSWORD="ftp-pass" | |
FTP_UPLOAD_DIR="/upload" | |
LOG_FILE=/backups/backup-DATE.log | |
############### Local Backup ######################## | |
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $LOCAL_BACKUP_DIR/$DATE-$DB_NAME.sql.gz | |
############### UPLOAD to FTP Server ################ | |
ftp -nv $FTP_SERVER << EndFTP | |
user "$FTP_USERNAME" "$FTP_PASSWORD" | |
binary | |
cd $FTP_UPLOAD_DIR | |
lcd $LOCAL_BACKUP_DIR | |
put "$DATE-$DB_NAME.sql.gz" | |
bye | |
EndFTP | |
############### Check and save log, also send an email ################ | |
if test $? = 0 | |
then | |
echo "Database Successfully Uploaded to the Ftp Server!" | |
echo -e "Database Successfully created and uploaded to the FTP Server!" | mail -s "Backup from $DATE" your_email@email.com | |
else | |
echo "Error in database Upload to Ftp Server" > $LOG_FILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment