Now you know how to back up your files and code to Amazon S3, but what about databases? Luckily, help is at hand. The Linux
s3cmd script can easily be used to back up your MySQL databases. To make things easier, I’ve created a script that you can use to back up all your databases into a folder, which is then synched with your S3 bucket.
The below script can be used via command line with a bit of configuration. All you need to do is set the
S3Bucket variables at the top of the script and you can start backing up your databases.
You can use the above script in a cron too, so your server is backed up regularly. The below cronjob will run the MySQL database backup script everyday at 2am:
Once the script has completed, you’ll see a folder on your S3 Bucket with the date of the backup. If you run the script multiple times in a day, the latest version of your database will be synched to the same folder.