Skip to content

Commit

Permalink
Merge pull request #27 from Daviey/master
Browse files Browse the repository at this point in the history
Add support to always take a snapshot on run
  • Loading branch information
sebdah authored Feb 27, 2020
2 parents 9595bc4 + 92aec08 commit 5ac9a03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions automated_ebs_snapshots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ def main():

if args.run:
snapshot_manager.run(connection)

if args.forcerun:
snapshot_manager.run(connection, force=True)
7 changes: 7 additions & 0 deletions automated_ebs_snapshots/command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@
'--run',
action='count',
help='Run the watcher to ensure snapshots')

actions_ag.add_argument(
'--forcerun',
action='count',
help='Similar to --run, but always take a snapshot and purge '
'snapshots that should be removed.')

args = parser.parse_args()

if args.version:
Expand Down
10 changes: 5 additions & 5 deletions automated_ebs_snapshots/snapshot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)


def run(connection):
def run(connection, force=False):
""" Ensure that we have snapshots for a given volume
:type connection: boto.ec2.connection.EC2Connection
Expand All @@ -20,7 +20,7 @@ def run(connection):
volumes = volume_manager.get_watched_volumes(connection)

for volume in volumes:
_ensure_snapshot(connection, volume)
_ensure_snapshot(connection, volume, force)
_remove_old_snapshots(connection, volume)


Expand All @@ -40,7 +40,7 @@ def _create_snapshot(volume):
return snapshot


def _ensure_snapshot(connection, volume):
def _ensure_snapshot(connection, volume, force):
""" Ensure that a given volume has an appropriate snapshot
:type connection: boto.ec2.connection.EC2Connection
Expand All @@ -64,8 +64,8 @@ def _ensure_snapshot(connection, volume):

snapshots = connection.get_all_snapshots(filters={'volume-id': volume.id})

# Create a snapshot if we don't have any
if not snapshots:
# Create a snapshot if there are not already any or if forced
if not snapshots or force:
_create_snapshot(volume)
return

Expand Down

0 comments on commit 5ac9a03

Please sign in to comment.