def test_get_archived_file(self, pghoard): wal_seg_prev_tli = "00000001000000000000000F" wal_seg = "00000002000000000000000F" wal_file = "xlog/{}".format(wal_seg) # NOTE: create WAL header for the "previous" timeline, this should be accepted content = wal_header_for_file(wal_seg_prev_tli) wal_dir = get_pg_wal_directory( pghoard.config["backup_sites"][pghoard.test_site]) archive_path = os.path.join(pghoard.test_site, wal_file) compressor = pghoard.Compressor() compressed_content = compressor.compress(content) + ( compressor.flush() or b"") metadata = { "compression-algorithm": pghoard.config["compression"]["algorithm"], "original-file-size": len(content), } store = pghoard.transfer_agents[0].get_object_storage( pghoard.test_site) store.store_file_from_memory(archive_path, compressed_content, metadata=metadata) restore_command(site=pghoard.test_site, xlog=wal_seg, output=None, host="127.0.0.1", port=pghoard.config["http_port"]) restore_target = os.path.join(wal_dir, wal_seg) restore_command(site=pghoard.test_site, xlog=wal_seg, output=restore_target, host="127.0.0.1", port=pghoard.config["http_port"]) assert os.path.exists(restore_target) is True with open(restore_target, "rb") as fp: restored_data = fp.read() assert content == restored_data # test the same thing using restore as 'pghoard_postgres_command' tmp_out = os.path.join(wal_dir, restore_target + ".cmd") postgres_command.main([ "--host", "localhost", "--port", str(pghoard.config["http_port"]), "--site", pghoard.test_site, "--mode", "restore", "--output", tmp_out, "--xlog", wal_seg, ]) with open(tmp_out, "rb") as fp: restored_data = fp.read() assert content == restored_data
def test_get_archived_file(self, pghoard): wal_seg_prev_tli = "00000001000000000000000F" wal_seg = "00000002000000000000000F" wal_file = "xlog/{}".format(wal_seg) # NOTE: create WAL header for the "previous" timeline, this should be accepted content = wal_header_for_file(wal_seg_prev_tli) wal_dir = get_pg_wal_directory(pghoard.config["backup_sites"][pghoard.test_site]) archive_path = os.path.join(pghoard.test_site, wal_file) compressor = pghoard.Compressor() compressed_content = compressor.compress(content) + (compressor.flush() or b"") metadata = { "compression-algorithm": pghoard.config["compression"]["algorithm"], "original-file-size": len(content), } store = pghoard.transfer_agents[0].get_object_storage(pghoard.test_site) store.store_file_from_memory(archive_path, compressed_content, metadata=metadata) restore_command(site=pghoard.test_site, xlog=wal_seg, output=None, host="127.0.0.1", port=pghoard.config["http_port"]) restore_target = os.path.join(wal_dir, wal_seg) restore_command(site=pghoard.test_site, xlog=wal_seg, output=restore_target, host="127.0.0.1", port=pghoard.config["http_port"]) assert os.path.exists(restore_target) is True with open(restore_target, "rb") as fp: restored_data = fp.read() assert content == restored_data # test the same thing using restore as 'pghoard_postgres_command' tmp_out = os.path.join(wal_dir, restore_target + ".cmd") postgres_command.main([ "--host", "localhost", "--port", str(pghoard.config["http_port"]), "--site", pghoard.test_site, "--mode", "restore", "--output", tmp_out, "--xlog", wal_seg, ]) with open(tmp_out, "rb") as fp: restored_data = fp.read() assert content == restored_data