Created
May 14, 2014 19:36
-
-
Save izazueta/f855d893ab22875bb7e9 to your computer and use it in GitHub Desktop.
Quick MySQL database backup and FTP upload script
http://jvaldezch.wordpress.com/2013/04/04/quick-mysql-database-backup-and-ftp-upload-script/
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="dbname" | |
DB_FILE="$DB_NAME-`date +%Y%m%d_%H%M%S`" | |
DB_BK_FOLDER="/your/folder/" | |
DB_BACKUP="$DB_BK_FOLDER$DB_FILE" | |
DB_USER="dbuser" | |
DB_PASSWD="dbpws" | |
FTP_SERVER="x.x.x.x" | |
FTP_USER="ftpuser" | |
FTP_PASSW="ftpws" | |
echo "Creating MySQL Dump" | |
mysqldump -u $DB_USER -p$DB_PASSWD --lock-tables=false $DB_NAME > $DB_BACKUP.sql | |
echo "Compressing database" | |
tar czvf $DB_BACKUP.tar.gz $DB_BACKUP.sql | |
echo "File permissions " | |
chown owner.owner $DB_BACKUP.tar.gz | |
echo "Delete dump file" | |
rm $DB_BACKUP.sql | |
echo "Upload to FTP" | |
ftp -v -n $FTP_SERVER 20 <<END_OF_SESSION | |
user $FTP_USER $FTP_PASSW | |
$FILETYPE | |
lcd $DB_BK_FOLDER | |
put $DB_FILE.tar.gz | |
bye | |
END_OF_SESSION | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment