Database Reference
In-Depth Information
Using a Remote (Cloud-Based) Datastore
The script described in the previous section has a separate function for creating and storing the archive. This makes it
relatively easy to modify the script so that it uses an external datastore to store the backup archive. Table 9-2 provides
a couple of examples, but many more other mechanisms are possible.
Table 9-2. Remote (Cloud-Based) Backup Storage Options
Method
Description
rsync/ftp/tftp or scp to another server
You can use rsync to move the archive to a backup storage machine.
s3 storage
S3 storage is a good place to put your backups if you run your system on
EC2 because storage costs are low and Amazon makes redundant copies.
We will examine the S3 method of storing your backup; however, the same principles apply to any of the other
mechanisms.
This example uses the s3cmd utility (written in python) available from http://s3tools.org . On Ubuntu,
you can install this script using the sudo apt-get install s3cmd command; on Mac OSX, this script is
available from the MacPorts collection. On Fedora, CentOS, and RedHat, you can acquire the yum package from
http://s3tools.org , and then install it using yum .
Once you have installed the package, run s3cmd -configure to set your Amazon S3 credentials. Note that you
only need to supply two keys: AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY . The s3cmd utility will create a config file
that contains the information you need in this file: ~/.s3cfg .
Here are the changes that you need to make for your backup script to work with S3:
# _do_store_archive <Database> <Dump_dir> <Dest_Dir> <Dest_file>
BACKUP_S3_CONFIG=~/.s3cfg
BACKUP_S3_BUCKET=somecompany.somebucket
S3CMD_BIN=/usr/bin/s3cmd
function _do_store_archive {
UNIQ_FILE="aws"`date "+%s"`
cd $2
tar -cvzf $BACKUP_TMP/$UNIQ_FILE dump
$S3CMD_BIN --config $BACKUP_S3_CONFIG put $BACKUP_TMP/$UNIQ_FILE \
s3://$BACKUP_S3_BUCKET/$1/$4
rm -f $BACKUP_TMP/$UNIQ_FILE
}
Table 9-3 lists some variables that you need to configure to make this adapted script work.
Table 9-3. Configuring the Variables of Your Adapted Backup Script
Variable
Description
BACKUP_S3_CONFIG
The path to the s3cmd configuration file that was created when you ran s3cmd -configure to
save the details of your S3 account.
BACKUP_S3_BUCKET
The name of the bucket where that you want the script to store backups.
S3CMD_BIN
The path to the s3cmd executable program, again use which s3cmd to find it on your system.
 
Search WWH ::




Custom Search