ebs-snapshots
allows you to create and clean up AWS EBS snapshots according to a schedule.
(Thanks for skymill
for the basis of this work: https://github.com/skymill/automated-ebs-snapshots)
This requires AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
, which should be set in ~/.aws/credentials
.
AWS_REGION=your_region \
AWS_BACKUP_REGION=your_backup_region \
BACKUP_CONFIG=s3://your-bucket/snapshots-config.yml \
python main.py
This starts a long-running process that will take snapshots according to the config file.
BACKUP_CONFIG
may be a local file, an s3 path, or inline YAML/JSON.
Configuration files are written in yaml (a superset of JSON) format. Top level keys are volume ids. These map to a dict of parameters:
interval
- frequency of snapshots: hourly, daily, monthly, yearlymax_snapshots
- max snapshots to keep, 0 keeps allname
- name of snapshot, written to EC2 tag 'Name"
Here is an example configuration file to automate snapshots for two volumes:
vol-fake1234:
interval: daily
max_snapshots: 0
name: Fake database
vol-fake5678:
interval: hourly
max_snapshots: 48
You must specify these env vars in order to connect to AWS and to choose the configuration file.
AWS_ACCESS_KEY_ID # Your AWS Credentials
AWS_SECRET_ACCESS_KEY # Your AWS Credentials
AWS_REGION # AWS Region, e.g. us-west-1
AWS_BACKUP_REGION # AWS Region for backups, e.g. us-west-2
BACKUP_CONFIG # Path to backup config. May be local file or s3 path (see "Configuration")
You'll need to grant the proper IAM permissions to the AWS credentials you're using.
- ec2 volume, snapshot, and tag, permissions - to create snapshots of volumes and tag them
- s3 bucket permissions - allows reading your config file from an s3 path
See the included example policy.
Build the docker image:
docker build --tag=local/ebs-snapshots $(pwd)
Run as a docker container, making sure to specify required env vars:
docker run \
-e AWS_ACCESS_KEY_ID_ID=$AWS_ACCESS_KEY_ID_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e AWS_REGION=$AWS_REGION \
-e BACKUP_CONFIG=$BACKUP_CONFIG \
local/ebs-snapshots
make test