Cron job to backup all MySQL databases in your VPS host

0 Comment

With this script, you can backup your all your MySQL databases. You need to have SSH access to your hosting. You can also extend functionality to backup to another remote location.

Login as root and create a cron job to backup the databases (mine runs every day at 3 am)

crontab -e
0 3 * * * /backup/db/ > /dev/null 2>&1

The script will create a directory by date, dump the databases there, then delete older backup a day before your defined number of backups to keep.

Optionally, on your local machine or another remote host, you can use scp tool to copy those folders as you wish over ssh. That’s beyond the scope of this post.

Backup path must not be accessible from web!

If you would like to explore how to use scp, let me know!

Tags: , , , ,