示例#1
0
def gc():
    """Deletes old stellar tables that are not used anymore"""
    def after_delete(database):
        print "Deleted table %s" % database

    app = Stellar()
    app.delete_orphan_snapshots(after_delete)
示例#2
0
def gc():
    """Deletes old stellar tables that are not used anymore"""
    def after_delete(database):
        print "Deleted table %s" % database

    app = Stellar()
    app.delete_orphan_snapshots(after_delete)
示例#3
0
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)
示例#4
0
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"
示例#5
0
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"
示例#6
0
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)
示例#7
0
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)
示例#8
0
def list():
    """Returns a list of snapshots"""
    snapshots = Stellar().get_snapshots()

    print '\n'.join('%s: %s' %
                    (s.snapshot_name,
                     humanize.naturaltime(datetime.utcnow() - s.created_at))
                    for s in snapshots)
示例#9
0
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."
示例#10
0
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."
示例#11
0
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)