Skip to content

Instantly share code, notes, and snippets.

@izazueta
Created May 14, 2014 19:36
Show Gist options
  • Save izazueta/f855d893ab22875bb7e9 to your computer and use it in GitHub Desktop.
Save izazueta/f855d893ab22875bb7e9 to your computer and use it in GitHub Desktop.
#!/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