1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-07-16 07:14:15 +02:00

tests: added tests.retention_test.RetentionTest.test_retention_window_3

This commit is contained in:
Grigory Smolkin
2019-03-11 14:53:32 +03:00
parent b20d04e55f
commit cb805f7e7c

View File

@ -122,38 +122,31 @@ class RetentionTest(ProbackupTest, unittest.TestCase):
self.del_test_dir(module_name, fname) self.del_test_dir(module_name, fname)
# @unittest.skip("123") # @unittest.skip("123")
def test_retention_wal(self): def test_retention_window_3(self):
"""purge backups using window-based retention policy""" """purge all backups using window-based retention policy"""
fname = self.id().split('.')[3] fname = self.id().split('.')[3]
node = self.make_simple_node( node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'), base_dir=os.path.join(module_name, fname, 'node'),
initdb_params=['--data-checksums'], initdb_params=['--data-checksums'])
pg_options={'wal_level': 'replica'}
)
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup') backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir) self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node) self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node) self.set_archiving(backup_dir, 'node', node)
node.slow_start() node.slow_start()
node.safe_psql(
"postgres",
"create table t_heap as select i as id, md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,100500) i")
# Take FULL BACKUP # Take FULL BACKUP
self.backup_node(backup_dir, 'node', node) backup_id_1 = self.backup_node(backup_dir, 'node', node)
node.safe_psql(
"postgres", # Take second FULL BACKUP
"insert into t_heap select i as id, md5(i::text) as text, " backup_id_2 = self.backup_node(backup_dir, 'node', node)
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,100500) i") # Take third FULL BACKUP
backup_id_3 = self.backup_node(backup_dir, 'node', node)
self.backup_node(backup_dir, 'node', node)
backups = os.path.join(backup_dir, 'backups', 'node') backups = os.path.join(backup_dir, 'backups', 'node')
days_delta = 5
for backup in os.listdir(backups): for backup in os.listdir(backups):
if backup == 'pg_probackup.conf': if backup == 'pg_probackup.conf':
continue continue
@ -161,18 +154,15 @@ class RetentionTest(ProbackupTest, unittest.TestCase):
os.path.join( os.path.join(
backups, backup, "backup.control"), "a") as conf: backups, backup, "backup.control"), "a") as conf:
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format( conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
datetime.now() - timedelta(days=days_delta))) datetime.now() - timedelta(days=3)))
days_delta -= 1
# Make backup to be keeped
self.backup_node(backup_dir, 'node', node, backup_type="page")
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 3)
# Purge backups # Purge backups
self.delete_expired( self.delete_expired(
backup_dir, 'node', options=['--retention-window=2']) backup_dir, 'node', options=['--retention-window=1'])
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2) self.assertEqual(len(self.show_pb(backup_dir, 'node')), 0)
print(self.show_pb(
backup_dir, 'node', as_json=False, as_text=True))
# Clean after yourself # Clean after yourself
self.del_test_dir(module_name, fname) self.del_test_dir(module_name, fname)