Tag Archives: windows

Linux / Windows : Automatically backup mysql (on linux) and tranfer backup file to windows (via FTP)

Automatically backup mysql (on linux) and tranfer backup file to windows (via FTP).
This task will involve 2 types of environment (OS), Windows and Linux.

[Windows Section]
1. Setup FTP server on your windows environment using windows own software or third party software.
2. Create an account and allow connection only from the server(Linux) IP address.

[Linux Section]
1. Create an account on mysql with backup privileges ONLY (normally all read privileges).
2. Create an folder in your home directory. Example : /home/anas/mysql_backup_scheduler
3. Create an empty shell file inside /home/anas/mysql_backup_scheduler. Example: backup_and_ftp.sh
4. Inside backup_and_ftp.sh , put the content below and replace accordingly : –

---- BOF -----

#!/bin/bash

DATEC="/bin/date"
DATE=`${DATEC} +%Y%m%d_%H%M`
DATEM=`${DATEC} +%Y-%m-%d`
DBNAME=""
DBBACKUP="$DBNAME"-${DATE}.sql
HOST=''
USER=''
PASSWD=''

cd /home/anas/mysql_backup_scheduler/
/usr/bin/mysqldump -u -p --databases "$DBNAME" > ${DBBACKUP}

echo "Done Backup ..." ${DATE}

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put ${DBBACKUP}
quit
END_SCRIPT

echo "Done Upload ..." ${DATE}

#rm ${DBBACKUP} # uncomment only when you want to delete old files
exit 0

---- EOF ----

Finally, add this script to your cron.