def restore_backup(args): snapshots = SnapshotCollection( args.aws_access_key_id, args.aws_secret_access_key, args.s3_base_path, args.s3_bucket_name ) if args.snapshot_name == 'LATEST': snapshot = snapshots.get_latest() else: snapshot = snapshots.get_snapshot_by_name(args.backup_name) worker = RestoreWorker(aws_access_key_id=args.aws_access_key_id, aws_secret_access_key=args.aws_secret_access_key, snapshot=snapshot) if args.hosts: hosts = args.hosts.split(',') else: hosts = snapshot.hosts target_hosts = args.target_hosts.split(',') worker.restore(args.keyspace, args.table, hosts, target_hosts)
def restore_backup(args): snapshots = SnapshotCollection( args.aws_access_key_id, args.aws_secret_access_key, args.s3_base_path, args.s3_bucket_name ) snapshot = None if not args.local_source or not args.hosts: if args.snapshot_name == 'LATEST': snapshot = snapshots.get_latest() else: snapshot = snapshots.get_snapshot_by_name(args.backup_name) worker = RestoreWorker(aws_access_key_id=args.aws_access_key_id, aws_secret_access_key=args.aws_secret_access_key, snapshot=snapshot, local_source=args.local_source, merge_dir=args.merge_dir) if args.hosts: hosts = args.hosts.split(',') else: hosts = snapshot.hosts target_hosts = args.target_hosts.split(',') worker.restore(args.keyspace, args.table, hosts, target_hosts)
def run_backup(args): if args.user: env.user = args.user env.hosts = sorted(args.hosts.split(',')) if args.new_snapshot: create_snapshot = True else: existing_snapshot = SnapshotCollection( args.aws_access_key_id, args.aws_secret_access_key, args.s3_base_path, args.s3_bucket_name).get_snapshot_for(hosts=env.hosts, keyspaces=args.keyspaces, table=args.table) create_snapshot = existing_snapshot is None worker = BackupWorker(aws_access_key_id=args.aws_access_key_id, aws_secret_access_key=args.aws_secret_access_key, cassandra_data_path=args.cassandra_data_path, nodetool_path=args.nodetool_path) if create_snapshot: logging.info('make a new snapshot') snapshot = Snapshot(base_path=args.s3_base_path, s3_bucket=args.s3_bucket_name, hosts=env.hosts, keyspaces=args.keyspaces, table=args.table) worker.snapshot(snapshot) else: logging.info('add incrementals to snapshot %s' % existing_snapshot) worker.update_snapshot(existing_snapshot)
def run_backup(args): if args.user: env.user = args.user if args.password: env.password = args.password if args.sshkey - filename: env.key_filename = args.sshkey - filename if args.sshport: env.port = args.sshport env.hosts = args.hosts.split(',') if args.new_snapshot: create_snapshot = True else: existing_snapshot = SnapshotCollection( args.aws_access_key_id, args.aws_secret_access_key, args.s3_base_path, args.s3_bucket_name).get_snapshot_for(hosts=env.hosts, keyspaces=args.keyspaces, table=args.table) create_snapshot = existing_snapshot is None worker = BackupWorker(aws_access_key_id=args.aws_access_key_id, aws_secret_access_key=args.aws_secret_access_key, s3_bucket_region=args.s3_bucket_region, s3_ssenc=args.s3_ssenc, s3_connection_host=get_s3_connection_host( args.s3_bucket_region), cassandra_data_path=args.cassandra_data_path, nodetool_path=args.nodetool_path, cassandra_bin_dir=args.cassandra_bin_dir, backup_schema=args.backup_schema, connection_pool_size=args.connection_pool_size) if create_snapshot: logging.info('make a new snapshot') snapshot = Snapshot(base_path=args.s3_base_path, s3_bucket=args.s3_bucket_name, hosts=env.hosts, keyspaces=args.keyspaces, table=args.table) worker.snapshot(snapshot) else: logging.info('add incrementals to snapshot %s' % existing_snapshot) worker.update_snapshot(existing_snapshot)
def list_backups(args): snapshots = SnapshotCollection(args.aws_access_key_id, args.aws_secret_access_key, args.s3_base_path, args.s3_bucket_name) path_snapshots = defaultdict(list) for snapshot in snapshots: base_path = '/'.join(snapshot.base_path.split('/')[:-1]) path_snapshots[base_path].append(snapshot) for path, snapshots in path_snapshots.iteritems(): print '-----------[%s]-----------' % path for snapshot in snapshots: print '\t %r hosts:%r keyspaces:%r table:%r' % ( snapshot, snapshot.hosts, snapshot.keyspaces, snapshot.table) print '------------------------' + '-' * len(path)
def run_backup(args): if args.user: env.user = args.user if args.password: env.password = args.password if args.sshport: env.port = args.sshport if args.sshkey: env.key_filename = args.sshkey if not args.hosts: env.hosts = [socket.gethostname()] env.run = lambda cmd: local(cmd, capture=True) else: env.hosts = args.hosts.split(',') env.run = run keep_new_snapshot = args.keep_new_snapshot delete_old_snapshots = args.delete_old_snapshots delete_backups = args.delete_incremental_backups if args.new_snapshot: create_snapshot = True existing_snapshot = None else: if args.keep_new_snapshot: logging.warn('--new-snapshot not set. Ignoring --keep-new-snapshot ') keep_new_snapshot = False if args.delete_old_snapshots: logging.warn('--new-snapshot not set. Ignoring --delete-old-snapshots') delete_old_snapshots = False if args.delete_incremental_backups: logging.warn('--new-snapshot not set. Ignoring --delete-incremental-backup') delete_backups = False existing_snapshot = SnapshotCollection( args.aws_access_key_id, args.aws_secret_access_key, args.s3_base_path, args.s3_bucket_name ).get_snapshot_for( hosts=env.hosts, keyspaces=args.keyspaces, table=args.table ) create_snapshot = existing_snapshot is None worker = BackupWorker( aws_access_key_id=args.aws_access_key_id, aws_secret_access_key=args.aws_secret_access_key, s3_bucket_region=args.s3_bucket_region, s3_ssenc=args.s3_ssenc, s3_connection_host=get_s3_connection_host(args.s3_bucket_region), cassandra_data_path=args.cassandra_data_path, nodetool_path=args.nodetool_path, cassandra_bin_dir=args.cassandra_bin_dir, backup_schema=args.backup_schema, connection_pool_size=args.connection_pool_size, agent_path=args.agent_path, agent_virtualenv=args.agent_virtualenv, use_sudo=(not args.no_sudo) ) if create_snapshot: logging.info('make a new snapshot') snapshot = Snapshot( base_path=args.s3_base_path, s3_bucket=args.s3_bucket_name, hosts=env.hosts, keyspaces=args.keyspaces, table=args.table ) worker.snapshot(snapshot, keep_new_snapshot=keep_new_snapshot, delete_old_snapshots=delete_old_snapshots, delete_backups=delete_backups) else: logging.info('add incrementals to snapshot %s' % existing_snapshot) worker.update_snapshot(existing_snapshot)