Skip to content

Instantly share code, notes, and snippets.

@jahil
Last active August 29, 2015 14:08
Show Gist options
  • Save jahil/c369b375f837f840bec4 to your computer and use it in GitHub Desktop.
Save jahil/c369b375f837f840bec4 to your computer and use it in GitHub Desktop.
EBS Backup and Rotation Script
#!/bin/bash
export EC2_PRIVATE_KEY=~/.ec2/pk.pem
export EC2_CERT=~/.ec2/cert.pem
ec2-create-snapshot vol-ab0921c0 -d "Intellinar Server ROOT - $(date +'%d-%m-%Y')"
ec2-create-snapshot vol-110d257a -d "Intellinar Data - $(date +'%d-%m-%Y')"
ec2-create-snapshot vol-8bbb93e0 -d "Database Server aka RDS - $(date +'%d-%m-%Y')"
Purge EBS Snapshots
-------------------
export EC2_PRIVATE_KEY=~/.ec2/pk.pem
export EC2_CERT=~/.ec2/cert.pem
ec2-describe-snapshots | sort -r -k 5 | sed 1,7d | awk '{print "Deleting snapshot: " $2}; system("ec2-delete-snapshot " $2)'
''''
{
"Statement": [
{
"Sid": "Stmt1311252614644",
"Action": [
"ec2:CreateSnapshot",
"ec2:CreateTags",
"ec2:CreateVolume",
"ec2:DeleteSnapshot",
"ec2:DeleteTags",
"ec2:DescribeInstances",
"ec2:DescribeSnapshotAttribute",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:DescribeVolumes"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
''''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment