diff --git a/delete.c b/delete.c index 284ed800..4c410eee 100644 --- a/delete.c +++ b/delete.c @@ -349,12 +349,10 @@ delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli, bool delete_all) * they were originally written, in case this worries you. */ if (IsXLogFileName(arcde->d_name) || - IsPartialXLogFileName(arcde->d_name) || - IsBackupHistoryFileName(arcde->d_name)) + IsPartialXLogFileName(arcde->d_name)) { if (XLogRecPtrIsInvalid(oldest_lsn) || - strncmp(arcde->d_name, oldestSegmentNeeded, - XLOG_FNAME_LEN) < 0) + strcmp(arcde->d_name + 8, oldestSegmentNeeded + 8) < 0) { /* * Use the original file name again now, including any diff --git a/tests/option_test.py b/tests/option_test.py index c973bfaa..ee52343e 100644 --- a/tests/option_test.py +++ b/tests/option_test.py @@ -89,7 +89,21 @@ class OptionTest(ProbackupTest, unittest.TestCase): self.clean_pb(node) self.assertEqual(self.init_pb(node), six.b("")) - # TODO: keep data generations + # Command line parameters should override file values + self.init_pb(node) + with open(path.join(self.backup_dir(node), "pg_probackup.conf"), "a") as conf: + conf.write("REDUNDANCY=1\n") + + self.assertEqual( + self.retention_show(node, ["--redundancy", "2"]), + six.b("# retention policy\nREDUNDANCY=2\n") + ) + + # User cannot send --system-identifier parameter via command line + self.assertEqual( + self.backup_pb(node, options=["--system-identifier", "123"]), + six.b("ERROR: option system-identifier cannot be specified in command line\n") + ) # invalid value in pg_probackup.conf with open(path.join(self.backup_dir(node), "pg_probackup.conf"), "a") as conf: diff --git a/tests/pb_lib.py b/tests/pb_lib.py index 32a1e174..393aa6e7 100644 --- a/tests/pb_lib.py +++ b/tests/pb_lib.py @@ -195,6 +195,14 @@ class ProbackupTest(object): return self.run_pb(options + cmd_list) + def retention_show(self, node, options=[]): + cmd_list = [ + "-B", self.backup_dir(node), + "retention", "show", + ] + + return self.run_pb(options + cmd_list) + def get_control_data(self, node): pg_controldata = node.get_bin_path("pg_controldata") out_data = {} diff --git a/tests/retention_test.py b/tests/retention_test.py index 5712eeaf..5a4ef3a3 100644 --- a/tests/retention_test.py +++ b/tests/retention_test.py @@ -1,7 +1,7 @@ import unittest import os from datetime import datetime, timedelta -from os import path +from os import path, listdir from .pb_lib import ProbackupTest from testgres import stop_all @@ -35,9 +35,23 @@ class RetentionTest(ProbackupTest, unittest.TestCase): self.assertEqual(len(self.show_pb(node)), 4) # Purge backups - self.retention_purge_pb(node) + log = self.retention_purge_pb(node) self.assertEqual(len(self.show_pb(node)), 2) + # Check that WAL segments were deleted + min_wal = None + max_wal = None + for line in log.splitlines(): + if line.startswith(b"INFO: removed min WAL segment"): + min_wal = line[31:-1] + elif line.startswith(b"INFO: removed max WAL segment"): + max_wal = line[31:-1] + for wal_name in listdir(path.join(self.backup_dir(node), "wal")): + if not wal_name.endswith(".backup"): + wal_name_b = wal_name.encode('ascii') + self.assertEqual(wal_name_b[8:] > min_wal[8:], True) + self.assertEqual(wal_name_b[8:] > max_wal[8:], True) + node.stop() def test_retention_window_2(self):