0

Shell script to backup a MySQL database and transmit it via FTP

If you want a Shell script to backup a directory and transmit it via FTP, checkout my earlier post here.

As any good system admin knows, it is important to have up to date backups of things. In order to backup and store a MySQL database containing all the data for a website on a remote Linux server. I came up with the following shell script which dumps the database to a file then connects to a remote FTP server and transmits the resulting .sql file. It then deletes the dump from the remote system. Just remember to fill in the blanks with your own information or it wont work:


You can run this manually but I’d suggest running it via a CRON job at a set interval.
I use this command to run it at 4 every morning:

0 4 * * * /backup/scripts/mysqlBackup.sh

You can use

crontab -l

to list all cron jobs or

crontab -u username -l

to list all cron jobs for a particular user

Subscribe to my feed either by E-mail or by RSS to receive updates as they happen.
Can you improve on any of the tips I’ve discussed here? If you can let me know in the comments.

Jason Edwards