def get_latest_snapshot(key, access, name): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(name, True) if domain == None: domain = sdb.create_domain(name) return domain.get_item('snapshot', True)['snapshot']
def delete_snapshot(key, access, name, snapshot_id): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(name, True) if domain == None: domain = sdb.create_domain(name) return domain.delete_item(domain.get_item(snapshot_id))
def get_all_snapshots(key, access, name): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(name, True) if domain == None: domain = sdb.create_domain(name) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot'".format(name) snapshots = domain.select(select, consistent_read=True) return snapshots
def SDB(domain_name): """ Create connection to SimpleDB and return the specifed domain. domain_name - the SimpleDB domain you wish to return """ conn = SDBConnection(ACCESS_KEY_ID,SECRET_ACCESS_KEY) domain = conn.lookup(domain_name) if not domain: domain = conn.create_domain(domain_name) return domain
def get_all_snapshots(key, access, name): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(name, True) if domain == None: domain = sdb.create_domain(name) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot'".format( name) snapshots = domain.select(select, consistent_read=True) return snapshots
def get_expired_snapshots(key, access, cluster): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(cluster, True) if domain == None: domain = sdb.create_domain(cluster) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot' and expires < '{1}'".format( cluster, now) snapshots = domain.select(select, consistent_read=True) return snapshots
def get_expired_snapshots(key, access, cluster): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(cluster, True) if domain == None: domain = sdb.create_domain(cluster) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) select = "select * from `{0}` where itemName() > 'snap-' and itemName() != 'snapshot' and expires < '{1}'".format( cluster, now ) snapshots = domain.select(select, consistent_read=True) return snapshots
def add_snapshot(key, access, cluster, name, snapshot): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(cluster, True) if domain == None: domain = sdb.create_domain(cluster) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) # add the snapshot for expiration backup = domain.new_item(snapshot[0]) backup.add_value('name', name) backup.add_value('snapshot', snapshot[0]) backup.add_value('created', now) backup.add_value('expires', snapshot[1]) backup.save()
def add_snapshot(key, access, cluster, name, snapshot): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(cluster, True) if domain == None: domain = sdb.create_domain(cluster) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) # add the snapshot for expiration backup = domain.new_item(snapshot[0]) backup.add_value("name", name) backup.add_value("snapshot", snapshot[0]) backup.add_value("created", now) backup.add_value("expires", snapshot[1]) backup.save()
def get_latest_snapshot(key, access, cluster, name): sdb = SDBConnection(key, access, region=region_info) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) domain = sdb.lookup(cluster, True) if domain == None: domain = sdb.create_domain(cluster) select = "select * from `{0}` where name = '{1}' and created < '{2}' order by created desc limit 1".format( cluster, name, now) snapshots = domain.select(select, consistent_read=True) try: snapshot = snapshots.next() return snapshot['snapshot'] except: return None
def get_latest_snapshot(key, access, cluster, name): sdb = SDBConnection(key, access, region=region_info) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) domain = sdb.lookup(cluster, True) if domain == None: domain = sdb.create_domain(cluster) select = "select * from `{0}` where name = '{1}' and created < '{2}' order by created desc limit 1".format( cluster, name, now ) snapshots = domain.select(select, consistent_read=True) try: snapshot = snapshots.next() return snapshot["snapshot"] except: return None
def add_snapshot(key, access, name, snapshot): sdb = SDBConnection(key, access, region=region_info) domain = sdb.lookup(name, True) if domain == None: domain = sdb.create_domain(name) now = strftime("%Y-%m-%d %H:%M:%S", gmtime()) # add the snapshot for expiration backup = domain.new_item(snapshot[0]) backup.add_value('snapshot', snapshot[0]) backup.add_value('created', now) backup.add_value('expires', snapshot[1]) backup.save() # add the latest (for automatic restores) latest = domain.new_item('snapshot') latest.add_value('snapshot', snapshot[0]) latest.save()