Ejemplo n.º 1
0
def cmd_backup(args, osbs):
    dirname = time.strftime("osbs-backup-{0}-%Y-%m-%d-%H%M%S".format(
        args.instance))
    if args.filename == '-':
        outfile = sys.stdout.buffer if PY3 else sys.stdout
    elif args.filename:
        outfile = args.filename
    else:
        outfile = dirname + ".tar.bz2"

    with paused_builds(osbs,
                       quota_name='pause-backup',
                       ignore_quota_errors=args.ignore_quota_errors):
        with TarWriter(outfile, dirname) as t:
            for resource_type in BACKUP_RESOURCES:
                try:
                    logger.info("dumping %s", resource_type)
                    resources = osbs.dump_resource(resource_type)
                    t.write_file(resource_type + ".json",
                                 json.dumps(resources).encode('ascii'))
                except Exception as e:
                    if args.continue_on_error:
                        logger.warning(
                            "Error during {} backup".format(resource_type),
                            exc_info=True)
                    else:
                        raise e

    if not hasattr(outfile, "write"):
        logger.info("backup archive created: %s", outfile)
Ejemplo n.º 2
0
def test_tarfile(tmpdir, prefix):
    filename = str(tmpdir.join("archive.tar.bz2"))

    with TarWriter(filename, directory=prefix) as t:
        t.write_file("a/b.c", b"foobar")

    assert os.path.exists(filename)

    for f in TarReader(filename):
        assert f.filename == os.path.join(prefix, "a/b.c")
        content = f.fileobj.read()
        assert content == b"foobar"
Ejemplo n.º 3
0
def cmd_backup(args, osbs):
    dirname = time.strftime("osbs-backup-{0}-{1}-%Y-%m-%d-%H%M%S".format(
        args.instance, args.namespace))
    if args.filename == '-':
        outfile = sys.stdout.buffer if PY3 else sys.stdout
    elif args.filename:
        outfile = args.filename
    else:
        outfile = dirname + ".tar.bz2"

    with paused_builds(osbs, quota_name='pause-backup'):
        with TarWriter(outfile, dirname) as t:
            for resource_type in BACKUP_RESOURCES:
                logger.info("dumping %s", resource_type)
                resources = osbs.dump_resource(resource_type)
                t.write_file(resource_type + ".json",
                             json.dumps(resources).encode('ascii'))

    if not hasattr(outfile, "write"):
        logger.info("backup archive created: %s", outfile)