Created
October 27, 2011 02:54
-
-
Save ejsarge/1318674 to your computer and use it in GitHub Desktop.
Purging ec2 snapshots using tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Chef Name: osm_db_snapshot.sh | |
00 01 * * * /usr/local/sbin/osm_db_snapshot.sh | |
# Chef Name: ec2-purge-snapshots-osm-db | |
10 03 * * * /usr/local/sbin/ec2-purge-snapshots.rb -t env=prod -t contents=osm_db -h 48 -d 0 -w 0 -m 0 -a /root/.aws_access_key -e /root/.aws_secret_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export JAVA_HOME=/usr/lib/jvm/java-6-sun | |
export EC2_HOME=/opt/ec2-api-tools | |
description="\"prod OSM Database backup at `date`\"" | |
TMPFILE_JSON=$(mktemp /tmp/databagXXXXXXXXXX.json) | |
xfs_freeze -f /var/lib/postgresql/8.4/osm | |
snapshot_id=$(ec2-create-snapshot vol-118b9b7b -K /home/ubuntu/aws/pk-SnapshotUser.pem -C /home/ubuntu/aws/cert-SnapshotUser.pem -d "$description" | awk -F'\t' '{ printf "%s", $2 }') | |
xfs_freeze -u /var/lib/postgresql/8.4/osm | |
ec2-create-tags $snapshot_id --tag env=prod --tag contents=osm_db -K /home/ubuntu/aws/pk-SnapshotUser.pem -C /home/ubuntu/aws/cert-SnapshotUser.pem | |
cat <<END > $TMPFILE_JSON | |
{"id":"osm_db","snapshot-id": "$snapshot_id"} | |
END | |
knife data bag from file snapshots-prod $TMPFILE_JSON -c /etc/chef/client.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Backing up and purging old snapshots on Amazon EC2. See Amazon EC2: Purging Old Snapshots for details of why and how to use this.