A simple bash script for backing up your MySQL databases and virtual hosts' files to AWS S3.
It basically finds every database hosted on your MySQL (or drop-in replacements like MariaDB and Percona) server, create dumps and archives them, then sends those archives with files on your virtual hosts root to S3. Since it uses sync
functionality of AWS CLI, it actually mirrors your web root and database archives to S3, more like rsync
than a blind FTP upload. Especially if you choose to use --delete
parameter while synchronizing, which can be set through the settings file. Check settings.conf.sample for the set of parameters I use for my transfers.
Though it can be triggered manually, the script is designed to run as a daily cron job. If you don't want a particular database to be dumped synchronized every day, you may exlude it in the settings file. You can also exclude directories from your webroot. Again, please check settings.conf.sample for details.
- Clone the repo to your server, wherever you like. Preferably at
/root/
. - Copy settings.conf.sample to
settings.conf
at the script directory and edit it with your credentials and preferences. - Set a daily cron and if everything works, you'll start receiving daily backup reports.
Needs AWS CLI for synchronizing to S3 and sending notification emails through SES. Also needs 7zip for archiving. Tested only on Debian 7 and 8 but should work on other distributions as well.
This script is licensed under MIT License, which allows you to freely use or modify it as you see fit, without guaranteeing any results. Please read LICENSE file for details.
- DKIM signing seems to fail while using
send-raw-email
, which may cause false-positive spam alerts in some e-mail providers. However, SPF & DMARC still passes and these two should suffice for majority of inboxes.send-raw-email
is currently a necessity for sending attachments with AWS CLI.
Make rotation an option that can be controlled through the settings file.- Interactively create the settings file.
- Create buckets while creating the settings file.