Esempio n. 1
0
def restore_main(bin_dir, datafs, backup_location, verbose, additional,
                 blob_storage_source, backup_blobs, only_blobs, **kwargs):
    """Main method, gets called by generated bin/restore."""
    date = None
    if len(sys.argv) > 1:
        date = sys.argv[1]
        logger.debug("Argument passed to bin/restore, we assume it is "
                     "a date that we have to pass to repozo: %s.", date)
        logger.info("Date restriction: restoring state at %s." % date)

    question = '\n'
    if not only_blobs:
        question += "This will replace the filestorage (Data.fs).\n"
    if backup_blobs:
        question += "This will replace the blobstorage.\n"
    question += "Are you sure?"
    if not utils.ask(question, default=False, exact=True):
        logger.info("Not restoring.")
        sys.exit(0)

    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir, datafs, backup_location, verbose, additional, date)
        if result and backup_blobs:
            logger.error("Halting execution due to error; not restoring "
                         "blobs.")
            sys.exit(1)

    if not backup_blobs:
        return
    if not blob_storage_source:
        logger.error("No blob storage source specified")
        sys.exit(1)
    result = repoborunner.restore_main(bin_dir, blob_storage_source,
                                       backup_location, verbose, date)
Esempio n. 2
0
def restore_main(bin_dir, storages, verbose, backup_blobs,
                 only_blobs, use_rsync, restore_snapshot=False,
                 pre_command='', post_command='',
                 **kwargs):
    """Main method, gets called by generated bin/restore."""
    date = None
    if len(sys.argv) > 1:
        date = sys.argv[1]
        logger.debug("Argument passed to bin/restore, we assume it is "
                     "a date that we have to pass to repozo: %s.", date)
        logger.info("Date restriction: restoring state at %s." % date)

    question = '\n'
    if not only_blobs:
        question += "This will replace the filestorage (Data.fs).\n"
    if backup_blobs:
        question += "This will replace the blobstorage.\n"
    question += "Are you sure?"
    if not utils.ask(question, default=False, exact=True):
        logger.info("Not restoring.")
        sys.exit(0)

    utils.execute_or_fail(pre_command)
    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir, storages, verbose, date,
            restore_snapshot)
        if result and backup_blobs:
            logger.error("Halting execution due to error; not restoring "
                         "blobs.")
            sys.exit(1)

    if not backup_blobs:
        utils.execute_or_fail(post_command)
        return
    for storage in storages:
        blobdir = storage['blobdir']
        if restore_snapshot:
            blob_backup_location = storage['blob_snapshot_location']
        else:
            blob_backup_location = storage['blob_backup_location']
        if not blobdir:
            logger.info("No blob dir defined for %s storage" % \
                                                (storage['storage']))
            continue
        if not blobdir:
            logger.error("No blob storage source specified")
            sys.exit(1)
        logger.info("Restoring blobs from %s to %s", blob_backup_location,
                    blobdir)
        copyblobs.restore_blobs(blob_backup_location, blobdir,
                                use_rsync=use_rsync, date=date)
    utils.execute_or_fail(post_command)
Esempio n. 3
0
def restore_main(bin_dir, storages, verbose, backup_blobs,
                 only_blobs, use_rsync, restore_snapshot=False, pre_command='',
                 post_command='', gzip_blob=False, alt_restore=False,
                 **kwargs):
    """Main method, gets called by generated bin/restore."""
    if restore_snapshot and alt_restore:
        logger.error("Cannot use both restore_snapshot and alt_restore.")
        sys.exit(1)
    date = None
    # Try to find a date in the command line arguments
    for arg in sys.argv:
        if arg in ('-q', '-n', '--quiet', '--no-prompt'):
            continue
        if arg.find('restore') != -1:
            continue

        # We can assume this argument is a date
        date = arg
        logger.debug("Argument passed to bin/restore, we assume it is "
                     "a date that we have to pass to repozo: %s.", date)
        logger.info("Date restriction: restoring state at %s." % date)
        break

    question = '\n'
    if not only_blobs:
        question += "This will replace the filestorage:\n"
        for storage in storages:
            question += "    %s\n" % storage.get('datafs')
    if backup_blobs:
        question += "This will replace the blobstorage:\n"
        for storage in storages:
            if storage.get('blobdir'):
                question += "    %s\n" % storage.get('blobdir')
    question += "Are you sure?"
    if not kwargs.get('no_prompt'):
        if not utils.ask(question, default=False, exact=True):
            logger.info("Not restoring.")
            sys.exit(0)

    utils.execute_or_fail(pre_command)
    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir, storages, verbose, date,
            restore_snapshot, alt_restore)
        if result:
            if backup_blobs:
                logger.error("Halting execution due to error; not restoring "
                             "blobs.")
            else:
                logger.error("Halting execution due to error.")
            sys.exit(1)

    if not backup_blobs:
        utils.execute_or_fail(post_command)
        return
    for storage in storages:
        blobdir = storage['blobdir']
        if not blobdir:
            logger.info("No blob dir defined for %s storage" %
                        storage['storage'])
            continue
        if restore_snapshot:
            blob_backup_location = storage['blob_snapshot_location']
        elif alt_restore:
            blob_backup_location = storage['blob_alt_location']
        else:
            blob_backup_location = storage['blob_backup_location']
        if not blob_backup_location:
            logger.error("No blob storage source specified")
            sys.exit(1)
        logger.info("Restoring blobs from %s to %s", blob_backup_location,
                    blobdir)
        copyblobs.restore_blobs(blob_backup_location, blobdir,
                                use_rsync=use_rsync, date=date,
                                gzip_blob=gzip_blob)
    utils.execute_or_fail(post_command)
def restore_main(
    bin_dir,
    storages,
    verbose,
    backup_blobs,
    only_blobs,
    use_rsync,
    restore_snapshot=False,
    pre_command="",
    post_command="",
    archive_blob=False,
    alt_restore=False,
    rsync_options="",
    quick=True,
    zip_restore=False,
    blob_timestamps=False,
    incremental_blobs=False,
    **kwargs
):

    """Main method, gets called by generated bin/restore."""
    # First run several checks, and get the date that should be restored.
    date = restore_check(
        bin_dir,
        storages,
        verbose,
        backup_blobs,
        only_blobs,
        use_rsync,
        restore_snapshot=restore_snapshot,
        pre_command=pre_command,
        post_command=post_command,
        archive_blob=archive_blob,
        alt_restore=alt_restore,
        rsync_options=rsync_options,
        quick=quick,
        zip_restore=zip_restore,
        blob_timestamps=blob_timestamps,
        incremental_blobs=incremental_blobs,
        **kwargs
    )
    # Checks have passed, now do the real restore.
    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir, storages, verbose, date, restore_snapshot, alt_restore, zip_restore
        )
        if result:
            if backup_blobs:
                logger.error("Halting execution due to error; not restoring " "blobs.")
            else:
                logger.error("Halting execution due to error.")
            sys.exit(1)

    if not backup_blobs:
        utils.execute_or_fail(post_command)
        return
    for storage in storages:
        blobdir = storage["blobdir"]
        if not blobdir:
            continue
        blob_backup_location = storage["blob_backup_location"]
        logger.info("Restoring blobs from %s to %s", blob_backup_location, blobdir)
        result = copyblobs.restore_blobs(
            blob_backup_location,
            blobdir,
            use_rsync=use_rsync,
            date=date,
            archive_blob=archive_blob,
            rsync_options=rsync_options,
            timestamps=blob_timestamps,
        )
        if result:
            logger.error("Halting execution due to error.")
            sys.exit(1)
    utils.execute_or_fail(post_command)
def restore_check(
    bin_dir,
    storages,
    verbose,
    backup_blobs,
    only_blobs,
    use_rsync,
    restore_snapshot=False,
    pre_command="",
    post_command="",
    archive_blob=False,
    alt_restore=False,
    rsync_options="",
    quick=True,
    zip_restore=False,
    blob_timestamps=False,
    **kwargs
):
    """Method to check that a restore will work.

    Returns the chosen date, if any.
    """
    explicit_restore_opts = [restore_snapshot, alt_restore, zip_restore]
    if sum([1 for opt in explicit_restore_opts if opt]) > 1:
        logger.error(
            "Must use at most one option of restore_snapshot, "
            "alt_restore and zip_restore."
        )
        sys.exit(1)
    # Try to find a date in the command line arguments
    date = utils.get_date_from_args()

    if not kwargs.get("no_prompt"):
        question = "\n"
        if not only_blobs:
            question += "This will replace the filestorage:\n"
            for storage in storages:
                question += "    {0}\n".format(storage.get("datafs"))
        if backup_blobs:
            question += "This will replace the blobstorage:\n"
            for storage in storages:
                if storage.get("blobdir"):
                    question += "    {0}\n".format(storage.get("blobdir"))
        question += "Are you sure?"
        if not utils.ask(question, default=False, exact=True):
            logger.info("Not restoring.")
            sys.exit(0)

    utils.execute_or_fail(pre_command)

    # First run some checks.
    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir,
            storages,
            verbose,
            date,
            restore_snapshot,
            alt_restore,
            zip_restore,
            only_check=True,
        )
        if result:
            logger.error("Halting execution: " "restoring filestorages would fail.")
            sys.exit(1)
    if backup_blobs:
        check_blobs(
            storages,
            use_rsync,
            restore_snapshot=restore_snapshot,
            archive_blob=archive_blob,
            alt_restore=alt_restore,
            rsync_options=rsync_options,
            zip_restore=zip_restore,
            blob_timestamps=blob_timestamps,
            date=date,
        )
    return date
Esempio n. 6
0
def restore_main(bin_dir,
                 storages,
                 verbose,
                 backup_blobs,
                 only_blobs,
                 use_rsync,
                 restore_snapshot=False,
                 pre_command='',
                 post_command='',
                 gzip_blob=False,
                 alt_restore=False,
                 rsync_options='',
                 quick=True,
                 zip_restore=False,
                 **kwargs):
    """Main method, gets called by generated bin/restore."""
    explicit_restore_opts = [restore_snapshot, alt_restore, zip_restore]
    if sum([1 for opt in explicit_restore_opts if opt]) > 1:
        logger.error("Must use at most one option of restore_snapshot, "
                     "alt_restore and zip_restore.")
        sys.exit(1)
    date = None
    # Try to find a date in the command line arguments
    for arg in sys.argv:
        if arg in ('-q', '-n', '--quiet', '--no-prompt'):
            continue
        if arg.find('restore') != -1:
            continue

        # We can assume this argument is a date
        date = arg
        logger.debug(
            "Argument passed to bin/restore, we assume it is "
            "a date that we have to pass to repozo: %s.", date)
        logger.info("Date restriction: restoring state at %s." % date)
        break

    question = '\n'
    if not only_blobs:
        question += "This will replace the filestorage:\n"
        for storage in storages:
            question += "    %s\n" % storage.get('datafs')
    if backup_blobs:
        question += "This will replace the blobstorage:\n"
        for storage in storages:
            if storage.get('blobdir'):
                question += "    %s\n" % storage.get('blobdir')
    question += "Are you sure?"
    if not kwargs.get('no_prompt'):
        if not utils.ask(question, default=False, exact=True):
            logger.info("Not restoring.")
            sys.exit(0)

    utils.execute_or_fail(pre_command)
    if not only_blobs:
        result = repozorunner.restore_main(bin_dir, storages, verbose, date,
                                           restore_snapshot, alt_restore,
                                           zip_restore)
        if result:
            if backup_blobs:
                logger.error("Halting execution due to error; not restoring "
                             "blobs.")
            else:
                logger.error("Halting execution due to error.")
            sys.exit(1)

    if not backup_blobs:
        utils.execute_or_fail(post_command)
        return
    for storage in storages:
        blobdir = storage['blobdir']
        if not blobdir:
            logger.info("No blob dir defined for %s storage" %
                        storage['storage'])
            continue
        if restore_snapshot:
            blob_backup_location = storage['blob_snapshot_location']
        elif alt_restore:
            blob_backup_location = storage['blob_alt_location']
        elif zip_restore:
            blob_backup_location = storage['blob_zip_location']
        else:
            blob_backup_location = storage['blob_backup_location']
        if not blob_backup_location:
            logger.error("No blob storage source specified")
            sys.exit(1)
        logger.info("Restoring blobs from %s to %s", blob_backup_location,
                    blobdir)
        copyblobs.restore_blobs(blob_backup_location,
                                blobdir,
                                use_rsync=use_rsync,
                                date=date,
                                gzip_blob=gzip_blob,
                                rsync_options=rsync_options)
    utils.execute_or_fail(post_command)
Esempio n. 7
0
def restore_main(
        bin_dir,
        storages,
        verbose,
        backup_blobs,
        only_blobs,
        use_rsync,
        restore_snapshot=False,
        pre_command='',
        post_command='',
        archive_blob=False,
        alt_restore=False,
        rsync_options='',
        quick=True,
        zip_restore=False,
        blob_timestamps=False,
        incremental_blobs=False,
        **kwargs):

    """Main method, gets called by generated bin/restore."""
    # First run several checks, and get the date that should be restored.
    date = restore_check(
        bin_dir,
        storages,
        verbose,
        backup_blobs,
        only_blobs,
        use_rsync,
        restore_snapshot=restore_snapshot,
        pre_command=pre_command,
        post_command=post_command,
        archive_blob=archive_blob,
        alt_restore=alt_restore,
        rsync_options=rsync_options,
        quick=quick,
        zip_restore=zip_restore,
        blob_timestamps=blob_timestamps,
        incremental_blobs=incremental_blobs,
        **kwargs)
    # Checks have passed, now do the real restore.
    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir, storages, verbose, date,
            restore_snapshot, alt_restore, zip_restore)
        if result:
            if backup_blobs:
                logger.error('Halting execution due to error; not restoring '
                             'blobs.')
            else:
                logger.error('Halting execution due to error.')
            sys.exit(1)

    if not backup_blobs:
        utils.execute_or_fail(post_command)
        return
    for storage in storages:
        blobdir = storage['blobdir']
        if not blobdir:
            continue
        blob_backup_location = storage['blob_backup_location']
        logger.info('Restoring blobs from %s to %s', blob_backup_location,
                    blobdir)
        result = copyblobs.restore_blobs(
            blob_backup_location,
            blobdir,
            use_rsync=use_rsync,
            date=date,
            archive_blob=archive_blob,
            rsync_options=rsync_options,
            timestamps=blob_timestamps,
        )
        if result:
            logger.error('Halting execution due to error.')
            sys.exit(1)
    utils.execute_or_fail(post_command)
Esempio n. 8
0
def restore_check(
        bin_dir,
        storages,
        verbose,
        backup_blobs,
        only_blobs,
        use_rsync,
        restore_snapshot=False,
        pre_command='',
        post_command='',
        archive_blob=False,
        alt_restore=False,
        rsync_options='',
        quick=True,
        zip_restore=False,
        blob_timestamps=False,
        **kwargs):
    """Method to check that a restore will work.

    Returns the chosen date, if any.
    """
    explicit_restore_opts = [restore_snapshot, alt_restore, zip_restore]
    if sum([1 for opt in explicit_restore_opts if opt]) > 1:
        logger.error('Must use at most one option of restore_snapshot, '
                     'alt_restore and zip_restore.')
        sys.exit(1)
    # Try to find a date in the command line arguments
    date = utils.get_date_from_args()

    if not kwargs.get('no_prompt'):
        question = '\n'
        if not only_blobs:
            question += 'This will replace the filestorage:\n'
            for storage in storages:
                question += '    {0}\n'.format(storage.get('datafs'))
        if backup_blobs:
            question += 'This will replace the blobstorage:\n'
            for storage in storages:
                if storage.get('blobdir'):
                    question += '    {0}\n'.format(storage.get('blobdir'))
        question += 'Are you sure?'
        if not utils.ask(question, default=False, exact=True):
            logger.info('Not restoring.')
            sys.exit(0)

    utils.execute_or_fail(pre_command)

    # First run some checks.
    if not only_blobs:
        result = repozorunner.restore_main(
            bin_dir, storages, verbose, date,
            restore_snapshot, alt_restore, zip_restore, only_check=True)
        if result:
            logger.error('Halting execution: '
                         'restoring filestorages would fail.')
            sys.exit(1)
    if backup_blobs:
        check_blobs(
            storages,
            use_rsync,
            restore_snapshot=restore_snapshot,
            archive_blob=archive_blob,
            alt_restore=alt_restore,
            rsync_options=rsync_options,
            zip_restore=zip_restore,
            blob_timestamps=blob_timestamps,
            date=date,
        )
    return date