Skip to content

Commit 0d1430d

Browse files
committed
Adding some documentation, and the ability to specify the maximum number of snapshots per volume to keep
1 parent d5f5eea commit 0d1430d

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
lines changed

README.rst

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,98 @@
11
Backup Monkey
22
=============
33

4-
A monkey that makes sure you have snapshots of all your EBS volumes
4+
A monkey that makes sure you have a backup of your EBS volumes in case something goes wrong.
55

6+
It is designed specifically for Amazon Web Services (AWS), and using Python and Boto.
7+
8+
This script is designed to be run on a schedule, probably by CRON.
9+
10+
Usage
11+
-----
12+
13+
::
14+
15+
usage: backup-monkey [-h] [--region REGION]
16+
[--max-snapshots-per-volume SNAPSHOTS] [--snapshot-only]
17+
[--remove-only] [--verbose] [--version]
18+
19+
Loops through all EBS volumes, and snapshots them, then loops through all
20+
snapshots, and removes the oldest ones.
21+
22+
optional arguments:
23+
-h, --help show this help message and exit
24+
--region REGION the region to loop through and snapshot (default is
25+
current region of EC2 instance this is running on).
26+
E.g. us-east-1
27+
--max-snapshots-per-volume SNAPSHOTS
28+
the maximum number of snapshots to keep per EBS
29+
volume. The oldest snapshots will be deleted.
30+
Default: 3
31+
--snapshot-only Only snapshot EBS volumes, do not remove old snapshots
32+
--remove-only Only remove old snapshots, do not create new snapshots
33+
--verbose, -v enable verbose output (-vvv for more)
34+
--version display version number and exit
35+
36+
37+
38+
Examples
39+
--------
40+
41+
Create snapshots of all EBS volumes in us-east-1:
42+
43+
::
44+
45+
backup-monkey --region us-east-1
46+
47+
Delete snapshots of EBS volumes in us-west-1 where a volume has more than 5 snapshots:
48+
49+
::
50+
51+
backup-monkey --region us-west-1 --max-snapshots-per-volume 5 --remove-only
52+
53+
54+
Installation
55+
------------
56+
57+
You can install Backup Monkey using the usual PyPI channels. Example:
58+
59+
::
60+
61+
sudo pip install backup_monkey
62+
63+
You can find the package details here: https://pypi.python.org/pypi/backup_monkey
64+
65+
66+
Warning
67+
-------
68+
69+
Make no mistake. This script WILL delete snapshots. This script WILL create
70+
snapshots, which can cost you money. There really are no warranties or
71+
guarantees. For costs, refer to http://aws.amazon.com/ec2/pricing/
72+
73+
74+
About Answers for AWS
75+
---------------------
76+
77+
This code was written by `Peter
78+
Sankauskas <https://twitter.com/pas256>`__, founder of `Answers for
79+
AWS <http://answersforaws.com/>`__ - a company focused on helping business learn
80+
how to use AWS, without doing it the hard way. If you are looking for help
81+
with AWS, please `contact us <http://answersforaws.com/contact/>`__.
82+
83+
84+
License
85+
-------
86+
87+
Copyright 2013 Answers for AWS LLC
88+
89+
Licensed under the Apache License, Version 2.0 (the "License"); you may
90+
not use this file except in compliance with the License. You may obtain
91+
a copy of the License at
92+
93+
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
94+
law or agreed to in writing, software distributed under the License is
95+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
96+
KIND, either express or implied. See the License for the specific
97+
language governing permissions and limitations under the License.
98+

lib/backup_monkey/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414

1515
__author__ = 'Peter Sankauskas'
16-
__version__ = '0.5.0'
16+
__version__ = '0.9.0'

lib/backup_monkey/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def run():
3636
parser = argparse.ArgumentParser(description='Loops through all EBS volumes, and snapshots them, then loops through all snapshots, and removes the oldest ones.')
3737
parser.add_argument('--region', metavar='REGION',
3838
help='the region to loop through and snapshot (default is current region of EC2 instance this is running on). E.g. us-east-1')
39+
parser.add_argument('--max-snapshots-per-volume', metavar='SNAPSHOTS', default=3, type=int,
40+
help='the maximum number of snapshots to keep per EBS volume. The oldest snapshots will be deleted. Default: 3')
3941
parser.add_argument('--snapshot-only', action='store_true', default=False,
4042
help='Only snapshot EBS volumes, do not remove old snapshots')
4143
parser.add_argument('--remove-only', action='store_true', default=False,
@@ -65,7 +67,7 @@ def run():
6567
log.debug("Running in region: %s", region)
6668

6769
try:
68-
monkey = BackupMonkey(region)
70+
monkey = BackupMonkey(region, args.max_snapshots_per_volume)
6971

7072
if not args.remove_only:
7173
monkey.snapshot_volumes()

lib/backup_monkey/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525

2626
class BackupMonkey(object):
27-
def __init__(self, region):
27+
def __init__(self, region, max_snapshots_per_volume):
2828
self._region = region
2929
self._prefix = 'BACKUP_MONKEY'
30-
self._snapshots_per_volume = 3
30+
self._snapshots_per_volume = max_snapshots_per_volume
3131

3232
log.info("Connecting to region %s", self._region)
3333
self._conn = ec2.connect_to_region(self._region)

0 commit comments

Comments
 (0)