def backup(args): conn = bsu_backup.auth(args.profile, args.region, args.client_cert, args.endpoint) if args.instance_id: res = bsu_backup.find_instance_by_id(conn, args.instance_id) elif args.instances_tags: res = bsu_backup.find_instances_by_tags(conn, args.instances_tags) elif args.volume_id: res = bsu_backup.find_volume_by_id(conn, args.volume_id) elif args.volumes_tags: res = bsu_backup.find_volumes_by_tags(conn, args.volumes_tags) if res: if args.rotate_days: bsu_backup.rotate_days_snapshots( conn, res, args.rotate_days, args.rotate_only ) elif args.rotate: bsu_backup.rotate_snapshots(conn, res, args.rotate, args.rotate_only) else: bsu_backup.rotate_snapshots(conn, res, 10, args.rotate_only) bsu_backup.create_snapshots(conn, res) return True
def test_rotate_snapshots2(self): with Stubber(self.ec2) as stubber: stubber.add_response( "describe_snapshots", fixtures.snapshots1, { "Filters": [ { "Name": "volume-id", "Values": ["vol-59b94d63"] }, { "Name": "description", "Values": [ "osc-bsu-backup EF50CF3A80164A5EABAF8C78B2314C65" ], }, ] }, ) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-30e1c236"}) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-cf4748a5"}) self.assertEqual( bsu.rotate_snapshots(self.ec2, ["vol-59b94d63"], 9), None)
def test_rotate_snapshots1(self): with Stubber(self.ec2) as stubber: stubber.add_response( "describe_snapshots", fixtures.snapshots1, { "Filters": [ { "Name": "volume-id", "Values": ["vol-59b94d63"] }, { "Name": "description", "Values": [ "osc-bsu-backup EF50CF3A80164A5EABAF8C78B2314C65" ], }, ] }, ) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-d5caf847"}) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-30e1c236"}) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-cf4748a5"}) stubber.add_response( "describe_snapshots", fixtures.snapshots2, { "Filters": [ { "Name": "volume-id", "Values": ["vol-640141cf"] }, { "Name": "description", "Values": [ "osc-bsu-backup EF50CF3A80164A5EABAF8C78B2314C65" ], }, ] }, ) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-9c3c5d34"}) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-fa25ee50"}) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-e6996c10"}) stubber.add_response("delete_snapshot", {}, {"SnapshotId": "snap-8f3436c0"}) self.assertEqual( bsu.rotate_snapshots(self.ec2, ["vol-59b94d63", "vol-640141cf"], 8), None, )
def test_rotate_snapshots6(self): with Stubber(self.ec2) as stubber: stubber.add_response( "describe_snapshots", {"Snapshots": []}, {"Filters": [ { "Name": "volume-id", "Values": ["aaaa"] }, ]}, ) self.assertEqual(bsu.rotate_snapshots(self.ec2, ["aaaa"], 14), None)
def test_rotate_snapshots3(self): with Stubber(self.ec2) as stubber: stubber.add_response( "describe_snapshots", fixtures.snapshots1, { "Filters": [ { "Name": "volume-id", "Values": ["vol-59b94d63"] }, ] }, ) self.assertEqual( bsu.rotate_snapshots(self.ec2, ["vol-59b94d63"], 12), None)
def test_rotate_snapshots6(self): with Stubber(self.ec2) as stubber: stubber.add_response( "describe_snapshots", {"Snapshots": []}, { "Filters": [ { "Name": "volume-id", "Values": ["aaaa"] }, { "Name": "description", "Values": [ "osc-bsu-backup EF50CF3A80164A5EABAF8C78B2314C65" ], }, ] }, ) self.assertEqual(bsu.rotate_snapshots(self.ec2, ["aaaa"], 14), None)
def test_rotate_snapshots5(self): with Stubber(self.ec2) as stubber: stubber.add_response( "describe_snapshots", fixtures.snapshots1, { "Filters": [ { "Name": "volume-id", "Values": ["vol-59b94d63"] }, { "Name": "description", "Values": [ "osc-bsu-backup EF50CF3A80164A5EABAF8C78B2314C65" ], }, ] }, ) self.assertEqual( bsu.rotate_snapshots(self.ec2, ["vol-59b94d63"], 5487812), None)