def rename(old_name, new_name): """Renames a snapshot""" app = Stellar() snapshot = app.get_snapshot(old_name) if not snapshot: print "Couldn't find snapshot %s" % old_name sys.exit(1) new_snapshot = app.get_snapshot(new_name) if new_snapshot: print "Snapshot with name %s already exists" % new_name sys.exit(1) app.rename_snapshot(snapshot, new_name) print "Renamed snapshot %s to %s" % (old_name, new_name)
def snapshot(name): """Takes a snapshot of the database""" app = Stellar() name = name or app.default_snapshot_name if app.get_snapshot(name): print "Snapshot with name %s already exists" % name sys.exit(1) else: def before_copy(table_name): print "Snapshotting database %s" % table_name app.create_snapshot(name, before_copy=before_copy)
def remove(name): """Removes a snapshot""" app = Stellar() snapshot = app.get_snapshot(name) if not snapshot: print "Couldn't find snapshot %s" % name sys.exit(1) print "Deleting snapshot %s" % name app.remove_snapshot(snapshot) print "Deleted"
def restore(name): """Restores the database from a snapshot""" app = Stellar() if not name: snapshot = app.get_latest_snapshot() if not snapshot: print ( "Couldn't find any snapshots for project %s" % self.config['project_name'] ) sys.exit(1) else: snapshot = app.get_snapshot(name) if not snapshot: print ( "Couldn't find snapshot with name %s.\n" "You can list snapshots with 'stellar list'" % name ) sys.exit(1) # Check if slaves are ready if not snapshot.slaves_ready: if app.is_copy_process_running(snapshot): sys.stdout.write( 'Waiting for background process(%s) to finish' % snapshot.worker_pid ) sys.stdout.flush() while not snapshot.slaves_ready: sys.stdout.write('.') sys.stdout.flush() sleep(1) app.db.session.refresh(snapshot) print '' else: print 'Background process missing, doing slow restore.' app.inline_slave_copy(snapshot) app.restore(snapshot) print "Restore complete."
def restore(name): """Restores the database from a snapshot""" app = Stellar() if not name: snapshot = app.get_latest_snapshot() if not snapshot: print("Couldn't find any snapshots for project %s" % self.config['project_name']) sys.exit(1) else: snapshot = app.get_snapshot(name) if not snapshot: print( "Couldn't find snapshot with name %s.\n" "You can list snapshots with 'stellar list'" % name) sys.exit(1) # Check if slaves are ready if not snapshot.slaves_ready: if app.is_copy_process_running(snapshot): sys.stdout.write('Waiting for background process(%s) to finish' % snapshot.worker_pid) sys.stdout.flush() while not snapshot.slaves_ready: sys.stdout.write('.') sys.stdout.flush() sleep(1) app.db.session.refresh(snapshot) print '' else: print 'Background process missing, doing slow restore.' app.inline_slave_copy(snapshot) app.restore(snapshot) print "Restore complete."