Wrapper script for ec2-consistent-snapshot
that allows volume ids to be determined on the fly based on mount points in a
configuration file (defaulting to /etc/default/ec2-snap-db
).
Supports LVM and RAID devices in addition to normal block devices.
Requires installation of ec2-consistent-snapshot
and the
Amazon EC2 API Tools in the
PATH
.
Copy the files ec2-instance-env
, ec2-snap-db
, and ec2-volumes-for-mount
to your directory of choice. Ensure that they have executable permissions for
the user who will be running the process (0755 with root ownership should be
fine). All three files must be installed in the same directory.
You may find it convenient to install these files in the same directory as
either ec2-consistent-snapshot
or the Amazon EC2 API Tools (e.g.
/opt/aws/bin
) to avoid having to update the PATH
.
To run ec2-snap-db
for testing purposes, execute it as follows:
ec2-snap-db --verbose --config /path/to/config
If the command is not run as root, it will attempt to use sudo
to execute
ec2-consistent-snapshot
.
When the --config
parameter is not passed, the default configuration file at
/etc/default/ec2-snap-db
will be used (if it exists).
To run from cron, copy the file examples/ec2-snap-db.cron
to
/etc/cron.d/ec2-snap-db
and edit it to meet your needs.
The configuration file for ec2-snap-db
is a standard shell script. By
default, it will be loaded from /etc/default/ec2-snap-db
. The config file is
expected to set the following environment variables:
-
The
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
variables are used to callec2-consistent-snapshot
with the appropriate access credentials. They are also translated intoAWS_ACCESS_KEY
andAWS_SECRET_KEY
for the calls toec2-describe-volumes
andec2-describe-tags
. These credentials must allow theec2:CreateSnapshot
,ec2:DescribeTags
, andec2:DescribeVolumes
actions to be executed for the instance on whichec2-snap-db
is run. -
The
SNAP_DB_MOUNTS
variable is an array containing the list of mount points to snapshot. -
The
SNAP_DB_OPTIONS
variable is an array containing additional options to be passed toec2-consistent-snapshot
, e.g. MySQL or Mongo-related parameters. -
The
SNAP_DB_PREFIX
variable controls the prefix used for the snapshot description. The default value is the value of the instance's Name tag or instance id. If the value contains a single '%s', the instance name will be subsituted into that position in the prefix.
A sample configuration file can be found at examples/ec2-snap-db.default
.
NOTE: Your configuration file will contain AWS secrets, so its permissions should not allow other users to access the file. Owner-only permissions (e.g. 0600) are recommended.