A tool to create mysql server backups and optionally compress them and save them on a remote S3 server.
It is built on top of mysqldump
, gzip
and aws-shell
.
Run with -h
for for help / usage information:
sh mysql-backup-s3.sh -h
The -h
option displays a help message, which briefly describes usage.
The -v
option will output extra information.
The -u
option, which requires the mysql username parameter, allows to set the mysql user to use to connect to the database server. Default to root
.
The -p
option, which requires the mysql password parameter, allows to set the mysql password to connect to the database server. Is empty (unused) by default.
The -s
option can be used to save a different file for every different databases of the server.
If this option is not set, the file will be saved as mysql.sql
. If it is set it will be multiple files instead, having the name of the database (dbname.sql
).
The -z
option can be used to enabled gzip compression on the files. The resulting filenames will be mysql.sql.gz
or dbname.sql.gz
.
The
gzip
tool needs to be installed on the machine for compression to work.
The -l
option can be used to specify a local path to create a local backup.
The -r
option can be used to specify a bucket/folder (on Amazon S3) to create a remote backup.
This feature uses the aws-shell
utility (and its aws
binary).
Install this tool:
pip install aws-shell
Configure your account with:
aws configure
In your crontab, add the following line to run a full daily backup to S3 of your database:
# Run every 4 hours
0 0,4,8,12,16,20 * * * /bin/bash /root/tools/mysql-backup-s3.sh -s -z -r s3bucket/mysql/ -u backups -p password