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"
def cmd_restore(args, osbs): if args.BACKUP_ARCHIVE == '-': infile = sys.stdin.buffer if PY3 else sys.stdin # pylint: disable=no-member else: infile = args.BACKUP_ARCHIVE asciireader = codecs.getreader('ascii') with paused_builds(osbs, quota_name='pause-backup', ignore_quota_errors=args.ignore_quota_errors): for f in TarReader(infile): resource_type = os.path.basename(f.filename).split('.')[0] if resource_type not in BACKUP_RESOURCES: logger.warning("Unknown resource type for %s, skipping", f.filename) continue logger.info("restoring %s", resource_type) osbs.restore_resource(resource_type, json.load(asciireader(f.fileobj)), continue_on_error=args.continue_on_error) f.fileobj.close() logger.info("backup recovery complete!")