Skip to content

Commit 498134f

Browse files
authored
Merge pull request #196 from kuzmindb/issue_181
Issue 181
2 parents 726d891 + ee80feb commit 498134f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/backup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
217217

218218
if (prev_backup)
219219
{
220+
if (parse_program_version(prev_backup->program_version) > parse_program_version(PROGRAM_VERSION))
221+
elog(ERROR, "pg_probackup binary version is %s, but backup %s version is %s. "
222+
"pg_probackup do not guarantee to be forward compatible. "
223+
"Please upgrade pg_probackup binary.",
224+
PROGRAM_VERSION, base36enc(prev_backup->start_time), prev_backup->program_version);
225+
220226
char prev_backup_filelist_path[MAXPGPATH];
221227

222228
elog(INFO, "Parent backup: %s", base36enc(prev_backup->start_time));

tests/backup.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,3 +2746,56 @@ def test_note_sanity(self):
27462746

27472747
# Clean after yourself
27482748
self.del_test_dir(module_name, fname)
2749+
2750+
# @unittest.skip("skip")
2751+
def test_parent_backup_made_by_newer_version(self):
2752+
"""incremental backup with parent made by newer version"""
2753+
fname = self.id().split('.')[3]
2754+
node = self.make_simple_node(
2755+
base_dir=os.path.join(module_name, fname, 'node'),
2756+
initdb_params=['--data-checksums'])
2757+
2758+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2759+
self.init_pb(backup_dir)
2760+
self.add_instance(backup_dir, 'node', node)
2761+
self.set_archiving(backup_dir, 'node', node)
2762+
node.slow_start()
2763+
2764+
backup_id = self.backup_node(backup_dir, 'node', node)
2765+
2766+
control_file = os.path.join(
2767+
backup_dir, "backups", "node", backup_id,
2768+
"backup.control")
2769+
2770+
version = self.probackup_version
2771+
fake_new_version = str(int(version.split('.')[0]) + 1) + '.0.0'
2772+
2773+
with open(control_file, 'r') as f:
2774+
data = f.read();
2775+
2776+
data = data.replace(version, fake_new_version)
2777+
2778+
with open(control_file, 'w') as f:
2779+
f.write(data);
2780+
2781+
try:
2782+
self.backup_node(backup_dir, 'node', node, backup_type="page")
2783+
# we should die here because exception is what we expect to happen
2784+
self.assertEqual(
2785+
1, 0,
2786+
"Expecting Error because incremental backup should not be possible "
2787+
"if parent made by newer version.\n Output: {0} \n CMD: {1}".format(
2788+
repr(self.output), self.cmd))
2789+
except ProbackupException as e:
2790+
self.assertIn(
2791+
"pg_probackup do not guarantee to be forward compatible. "
2792+
"Please upgrade pg_probackup binary.",
2793+
e.message,
2794+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
2795+
repr(e.message), self.cmd))
2796+
2797+
self.assertEqual(
2798+
self.show_pb(backup_dir, 'node')[1]['status'], "ERROR")
2799+
2800+
# Clean after yourself
2801+
self.del_test_dir(module_name, fname)

tests/helpers/ptrack_helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ def __init__(self, *args, **kwargs):
246246
print('pg_probackup binary is not found')
247247
exit(1)
248248

249+
self.probackup_version = None
250+
251+
try:
252+
self.probackup_version_output = subprocess.check_output(
253+
[self.probackup_path, "--version"],
254+
stderr=subprocess.STDOUT,
255+
).decode('utf-8')
256+
except subprocess.CalledProcessError as e:
257+
raise ProbackupException(e.output.decode('utf-8'))
258+
259+
self.probackup_version = re.search(r"\d+\.\d+\.\d+", self.probackup_version_output).group(0)
260+
249261
if os.name == 'posix':
250262
self.EXTERNAL_DIRECTORY_DELIMITER = ':'
251263
os.environ['PATH'] = os.path.dirname(

0 commit comments

Comments
 (0)