6. Backup MySQL DB from Amazon RDS to Amazon S3

Example of setup that allow you to to backup your RDS database to S3 storage.

  • One of the great features of this solution is that our RDS class creates snapshot of current db and then starts new instance of DB from which backup is made so you have 100% guarantee of consistent data without affecting live instance whatsoever.
  • Data are stored in the CSV files individually per table, so you can easily get data form just selected tables

Amazon RDS database - example ini file

 1 ;;; Amazon RDS configuration
 2 storage.mysqlAmazonRds.storage = mysql
 3 storage.mysqlAmazonRds.dbinstance = <dbinstancename>
 4 storage.mysqlAmazonRds.region = REGION_EU_W1
 5 storage.mysqlAmazonRds.dbinstanceclass = db.m1.small
 6 
 7 ;;; we want to backup all databases on server
 8 storage.mysql.dbname = *
 9 
10 ;;; connect to mysql server on RDS to build backup
11 ;storage.mysql.port = 3306
12 storage.mysql.user = username
13 storage.mysql.password = userpassword
14 
15 ;;; databases will be backuped under this folder
16 storage.mysql.basedir = "~/Backups/amazonRdsDb"
17 
18 compare.sqlite.file="~/Backups/xtbackupCompare.db"
19 
20 storage.s3.bucket=<Amazon S3 bucket name>
21 
22 ;storage.s3.key.access=<access key>
23 ;storage.s3.key.secret=<secret>
24 
25 storage.s3.update=true
26 
27 ;;; let us put everything together
28 engine.outputs[]=cli
29 engine.local=mysqlAmazonRds
30 engine.remote=s3
31 engine.compare=sqlite

line 3: DB Instance Identifier as specified in the AWS console

line 4: you can specify where the backup instance should be created

line 5: you can specify class of instance, allows some saving if you use smaller instance that used for the live instance

line 18: new need to set compare service, we use sqlite version(only one implemented at the time of writing this) set it up in a persistent space (not tmp)

line 22-23: Generate "Access Keys" in Security Credentials in your AWS console
This needs to be filled in if you want ot use s3 as storage, however preferred way is to use private INI file that can be stored in the more secure folder with limited access. That way you can avoid accidentally committing your AWS credentials to potentially public repositories and losing $$$ in the process http://pulse.me/s/13oajD.
So if you do not use separate INI file please uncomment this lines and fill in credentials.

line 25: should upload/remove of data be executed? (yes/no/simulate)
yes - will transfer data to S3
no - will not start update process
simulate - will output progress, but will not really transfer data