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

    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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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 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)