2017-02-12 22:42:10 +02:00
|
|
|
import os
|
2017-06-27 11:43:45 +02:00
|
|
|
import unittest
|
2017-02-12 22:42:10 +02:00
|
|
|
from datetime import datetime, timedelta
|
2019-08-05 22:35:51 +02:00
|
|
|
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
|
2019-06-27 00:41:21 +02:00
|
|
|
from time import sleep
|
2019-10-08 16:47:41 +02:00
|
|
|
from distutils.dir_util import copy_tree
|
2017-02-12 22:42:10 +02:00
|
|
|
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
module_name = 'retention'
|
|
|
|
|
2017-02-12 22:42:10 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
class RetentionTest(ProbackupTest, unittest.TestCase):
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2017-05-22 13:17:43 +02:00
|
|
|
# @unittest.skip("skip")
|
|
|
|
# @unittest.expectedFailure
|
2017-05-05 15:21:49 +02:00
|
|
|
def test_retention_redundancy_1(self):
|
|
|
|
"""purge backups using redundancy-based retention policy"""
|
|
|
|
fname = self.id().split('.')[3]
|
2018-06-02 19:35:37 +02:00
|
|
|
node = self.make_simple_node(
|
2018-12-26 21:59:13 +02:00
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2019-04-22 19:52:00 +02:00
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-06-20 12:57:23 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-12-25 16:48:49 +02:00
|
|
|
node.slow_start()
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2019-10-04 09:36:56 +02:00
|
|
|
self.set_config(
|
|
|
|
backup_dir, 'node', options=['--retention-redundancy=1'])
|
2017-05-05 15:21:49 +02:00
|
|
|
|
|
|
|
# Make backups to be purged
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
2017-05-05 15:21:49 +02:00
|
|
|
# Make backups to be keeped
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 4)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2019-10-04 09:36:56 +02:00
|
|
|
output_before = self.show_archive(backup_dir, 'node', tli=1)
|
|
|
|
|
2017-05-05 15:21:49 +02:00
|
|
|
# Purge backups
|
2019-03-25 16:15:46 +02:00
|
|
|
log = self.delete_expired(
|
|
|
|
backup_dir, 'node', options=['--expired', '--wal'])
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2019-10-04 09:36:56 +02:00
|
|
|
output_after = self.show_archive(backup_dir, 'node', tli=1)
|
2018-01-28 03:36:27 +02:00
|
|
|
|
2019-10-04 09:36:56 +02:00
|
|
|
self.assertEqual(
|
|
|
|
output_before['max-segno'],
|
|
|
|
output_after['max-segno'])
|
|
|
|
|
|
|
|
self.assertNotEqual(
|
|
|
|
output_before['min-segno'],
|
|
|
|
output_after['min-segno'])
|
2018-01-28 03:36:27 +02:00
|
|
|
|
2019-10-04 09:36:56 +02:00
|
|
|
# Check that WAL segments were deleted
|
|
|
|
min_wal = output_after['min-segno']
|
|
|
|
max_wal = output_after['max-segno']
|
2018-01-28 03:36:27 +02:00
|
|
|
|
2017-06-27 11:43:45 +02:00
|
|
|
for wal_name in os.listdir(os.path.join(backup_dir, 'wal', 'node')):
|
2017-05-05 15:21:49 +02:00
|
|
|
if not wal_name.endswith(".backup"):
|
2019-10-08 13:33:52 +02:00
|
|
|
|
|
|
|
if self.archive_compress:
|
2019-12-26 23:39:35 +02:00
|
|
|
wal_name = wal_name[-27:]
|
2019-10-08 13:33:52 +02:00
|
|
|
wal_name = wal_name[:-3]
|
|
|
|
else:
|
2019-12-26 23:39:35 +02:00
|
|
|
wal_name = wal_name[-24:]
|
2019-10-08 13:33:52 +02:00
|
|
|
|
|
|
|
self.assertTrue(wal_name >= min_wal)
|
|
|
|
self.assertTrue(wal_name <= max_wal)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2017-06-27 07:42:52 +02:00
|
|
|
# Clean after yourself
|
2017-07-12 16:28:28 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2019-05-06 20:22:16 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-05-05 15:21:49 +02:00
|
|
|
def test_retention_window_2(self):
|
|
|
|
"""purge backups using window-based retention policy"""
|
|
|
|
fname = self.id().split('.')[3]
|
2018-06-02 19:35:37 +02:00
|
|
|
node = self.make_simple_node(
|
2018-12-26 21:59:13 +02:00
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2019-04-22 19:52:00 +02:00
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-06-20 12:57:23 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-12-25 16:48:49 +02:00
|
|
|
node.slow_start()
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2018-01-18 03:35:27 +02:00
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backup_dir,
|
|
|
|
'backups',
|
|
|
|
'node',
|
|
|
|
"pg_probackup.conf"), "a") as conf:
|
2017-05-05 15:21:49 +02:00
|
|
|
conf.write("retention-redundancy = 1\n")
|
|
|
|
conf.write("retention-window = 1\n")
|
|
|
|
|
|
|
|
# Make backups to be purged
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
2017-05-05 15:21:49 +02:00
|
|
|
# Make backup to be keeped
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2017-06-27 11:43:45 +02:00
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
2017-05-05 15:21:49 +02:00
|
|
|
days_delta = 5
|
2017-06-27 11:43:45 +02:00
|
|
|
for backup in os.listdir(backups):
|
2017-06-20 12:57:23 +02:00
|
|
|
if backup == 'pg_probackup.conf':
|
|
|
|
continue
|
2018-01-18 03:35:27 +02:00
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
2017-05-05 15:21:49 +02:00
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=days_delta)))
|
|
|
|
days_delta -= 1
|
|
|
|
|
|
|
|
# Make backup to be keeped
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 4)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
|
|
|
# Purge backups
|
2019-03-25 16:15:46 +02:00
|
|
|
self.delete_expired(backup_dir, 'node', options=['--expired'])
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
2017-05-05 15:21:49 +02:00
|
|
|
|
2017-06-27 07:42:52 +02:00
|
|
|
# Clean after yourself
|
2017-07-12 16:28:28 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-12-19 12:17:58 +02:00
|
|
|
|
2019-05-06 20:22:16 +02:00
|
|
|
# @unittest.skip("skip")
|
2019-03-11 13:53:32 +02:00
|
|
|
def test_retention_window_3(self):
|
|
|
|
"""purge all backups using window-based retention policy"""
|
2017-12-19 12:17:58 +02:00
|
|
|
fname = self.id().split('.')[3]
|
2018-01-18 03:35:27 +02:00
|
|
|
node = self.make_simple_node(
|
2018-12-26 21:59:13 +02:00
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2019-03-11 13:53:32 +02:00
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
2017-12-19 12:17:58 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-12-25 16:48:49 +02:00
|
|
|
node.slow_start()
|
2017-12-19 12:17:58 +02:00
|
|
|
|
2019-05-06 20:22:16 +02:00
|
|
|
# take FULL BACKUP
|
2019-03-11 13:53:32 +02:00
|
|
|
backup_id_1 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# Take second FULL BACKUP
|
|
|
|
backup_id_2 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# Take third FULL BACKUP
|
|
|
|
backup_id_3 = self.backup_node(backup_dir, 'node', node)
|
2017-12-19 12:17:58 +02:00
|
|
|
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup == 'pg_probackup.conf':
|
|
|
|
continue
|
2018-01-18 03:35:27 +02:00
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
2017-12-19 12:17:58 +02:00
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
2019-03-11 13:53:32 +02:00
|
|
|
datetime.now() - timedelta(days=3)))
|
2017-12-19 12:17:58 +02:00
|
|
|
|
|
|
|
# Purge backups
|
2018-01-18 03:35:27 +02:00
|
|
|
self.delete_expired(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_dir, 'node', options=['--retention-window=1', '--expired'])
|
2019-03-15 17:25:03 +02:00
|
|
|
|
2019-03-11 13:53:32 +02:00
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 0)
|
|
|
|
|
|
|
|
print(self.show_pb(
|
|
|
|
backup_dir, 'node', as_json=False, as_text=True))
|
2017-12-19 12:17:58 +02:00
|
|
|
|
2019-03-15 17:25:03 +02:00
|
|
|
# count wal files in ARCHIVE
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_retention_window_4(self):
|
|
|
|
"""purge all backups using window-based retention policy"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
2019-05-06 20:22:16 +02:00
|
|
|
# take FULL BACKUPs
|
2019-03-15 17:25:03 +02:00
|
|
|
backup_id_1 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
backup_id_2 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
backup_id_3 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup == 'pg_probackup.conf':
|
|
|
|
continue
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
self.delete_pb(backup_dir, 'node', backup_id_2)
|
|
|
|
self.delete_pb(backup_dir, 'node', backup_id_3)
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
self.delete_expired(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--retention-window=1', '--expired', '--wal'])
|
2019-03-15 17:25:03 +02:00
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 0)
|
|
|
|
|
|
|
|
print(self.show_pb(
|
|
|
|
backup_dir, 'node', as_json=False, as_text=True))
|
|
|
|
|
|
|
|
# count wal files in ARCHIVE
|
|
|
|
wals_dir = os.path.join(backup_dir, 'wal', 'node')
|
2019-03-27 09:10:18 +02:00
|
|
|
# n_wals = len(os.listdir(wals_dir))
|
2019-03-15 17:25:03 +02:00
|
|
|
|
2019-03-27 09:10:18 +02:00
|
|
|
# self.assertTrue(n_wals > 0)
|
2019-03-15 17:25:03 +02:00
|
|
|
|
2019-03-27 09:10:18 +02:00
|
|
|
# self.delete_expired(
|
|
|
|
# backup_dir, 'node',
|
|
|
|
# options=['--retention-window=1', '--expired', '--wal'])
|
2019-03-15 17:25:03 +02:00
|
|
|
|
|
|
|
# count again
|
|
|
|
n_wals = len(os.listdir(wals_dir))
|
|
|
|
self.assertTrue(n_wals == 0)
|
|
|
|
|
2017-12-19 12:17:58 +02:00
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
2019-03-25 16:15:46 +02:00
|
|
|
def test_window_expire_interleaved_incremental_chains(self):
|
2019-03-23 01:16:42 +02:00
|
|
|
"""complicated case of interleaved backup chains"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
2019-05-06 20:22:16 +02:00
|
|
|
# take FULL BACKUPs
|
2019-03-23 01:16:42 +02:00
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change FULLb backup status to ERROR
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
2019-03-23 01:16:42 +02:00
|
|
|
# Take PAGEa1 backup
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
|
|
|
# Change FULLb backup status to OK
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa1 and FULLa to ERROR
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
|
|
|
|
2019-03-23 01:16:42 +02:00
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
|
|
|
|
2019-03-23 01:16:42 +02:00
|
|
|
# Now we start to play with first generation of PAGE backups
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEb1 and FULLb to ERROR
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
2019-03-23 01:16:42 +02:00
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa1 and FULLa to OK
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-23 01:16:42 +02:00
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
2019-03-23 01:16:42 +02:00
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-23 01:16:42 +02:00
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
|
|
|
# Change PAGEa2 and FULLa to ERROR
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
2019-03-23 01:16:42 +02:00
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEb1 and FULLb to OK
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
|
|
|
|
2019-03-23 01:16:42 +02:00
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa2 and FULla to OK
|
2019-03-23 01:16:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
2019-06-27 12:09:42 +02:00
|
|
|
if backup not in [page_id_a2, page_id_b2, 'pg_probackup.conf']:
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
self.delete_expired(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--retention-window=1', '--expired'])
|
2019-03-23 01:16:42 +02:00
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 6)
|
|
|
|
|
|
|
|
print(self.show_pb(
|
|
|
|
backup_dir, 'node', as_json=False, as_text=True))
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_redundancy_expire_interleaved_incremental_chains(self):
|
|
|
|
"""complicated case of interleaved backup chains"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
2019-05-06 20:22:16 +02:00
|
|
|
# take FULL BACKUPs
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# Change FULL B backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
|
|
|
# Take PAGEa1 backup
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
|
|
|
# Change FULLb backup status to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa1 and FULLa backup status to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
# Now we start to play with first generation of PAGE backups
|
|
|
|
# Change PAGEb1 status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# Change PAGEa1 status to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
|
|
|
# Change PAGEa2 and FULLa status to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEb1 and FULLb status to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa2 and FULLa status to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--retention-redundancy=1', '--expired'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 3)
|
|
|
|
|
|
|
|
print(self.show_pb(
|
|
|
|
backup_dir, 'node', as_json=False, as_text=True))
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_window_merge_interleaved_incremental_chains(self):
|
|
|
|
"""complicated case of interleaved backup chains"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# Take FULL BACKUPs
|
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change FULLb backup status to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
# Take PAGEa1 backup
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
|
|
|
# Change FULLb to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
|
|
|
# Change PAGEa1 backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
# Now we start to play with first generation of PAGE backups
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEb1 and FULLb to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa1 to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'OK')
|
|
|
|
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
2019-06-27 12:09:42 +02:00
|
|
|
|
|
|
|
# Change PAGEa2 and FULLa to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEb1 and FULLb to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# Change PAGEa2 and FULLa to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
2019-06-27 12:09:42 +02:00
|
|
|
if backup not in [page_id_a2, page_id_b2, 'pg_probackup.conf']:
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--retention-window=1', '--expired', '--merge-expired'])
|
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Merge incremental chain between full backup {0} and backup {1}".format(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_id_a, page_id_a2),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Rename merged full backup {0} to {1}".format(
|
|
|
|
backup_id_a, page_id_a2), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Merge incremental chain between full backup {0} and backup {1}".format(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_id_b, page_id_b2),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Rename merged full backup {0} to {1}".format(
|
|
|
|
backup_id_b, page_id_b2), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_window_merge_interleaved_incremental_chains_1(self):
|
|
|
|
"""
|
|
|
|
PAGEb3
|
|
|
|
PAGEb2
|
|
|
|
PAGEb1
|
|
|
|
PAGEa1
|
|
|
|
FULLb
|
|
|
|
FULLa
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2019-04-25 12:29:43 +02:00
|
|
|
initdb_params=['--data-checksums'],
|
2019-04-25 12:31:40 +02:00
|
|
|
pg_options={'autovacuum':'off'})
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
2020-05-23 12:48:16 +02:00
|
|
|
node.pgbench_init(scale=5)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# Take FULL BACKUPs
|
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
2020-05-23 12:48:16 +02:00
|
|
|
pgbench = node.pgbench(options=['-t', '20', '-c', '1'])
|
2019-03-25 16:15:46 +02:00
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
2020-05-23 12:48:16 +02:00
|
|
|
pgbench = node.pgbench(options=['-t', '20', '-c', '1'])
|
2019-03-25 16:15:46 +02:00
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
# Change FULL B backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
pgdata_a1 = self.pgdata_content(node.data_dir)
|
|
|
|
|
2020-05-23 12:48:16 +02:00
|
|
|
pgbench = node.pgbench(options=['-t', '20', '-c', '1'])
|
2019-03-25 16:15:46 +02:00
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
|
|
|
# Change FULL B backup status to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
|
|
|
# Change PAGEa1 backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2020-05-23 12:48:16 +02:00
|
|
|
pgbench = node.pgbench(options=['-t', '20', '-c', '1'])
|
2019-03-25 16:15:46 +02:00
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2020-05-23 12:48:16 +02:00
|
|
|
pgbench = node.pgbench(options=['-t', '20', '-c', '1'])
|
2019-03-25 16:15:46 +02:00
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
page_id_b3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
pgdata_b3 = self.pgdata_content(node.data_dir)
|
|
|
|
|
2020-05-23 12:48:16 +02:00
|
|
|
pgbench = node.pgbench(options=['-t', '20', '-c', '1'])
|
2019-03-25 16:15:46 +02:00
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
# PAGEb3 OK
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Change PAGEa1 backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'OK')
|
|
|
|
|
|
|
|
# PAGEb3 OK
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup in [page_id_a1, page_id_b3, 'pg_probackup.conf']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--retention-window=1', '--expired', '--merge-expired'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[1]['id'],
|
|
|
|
page_id_b3)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[0]['id'],
|
|
|
|
page_id_a1)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[1]['backup-mode'],
|
|
|
|
'FULL')
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[0]['backup-mode'],
|
|
|
|
'FULL')
|
|
|
|
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Data correctness of PAGEa3
|
|
|
|
self.restore_node(backup_dir, 'node', node, backup_id=page_id_a1)
|
|
|
|
pgdata_restored_a1 = self.pgdata_content(node.data_dir)
|
|
|
|
self.compare_pgdata(pgdata_a1, pgdata_restored_a1)
|
|
|
|
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Data correctness of PAGEb3
|
|
|
|
self.restore_node(backup_dir, 'node', node, backup_id=page_id_b3)
|
|
|
|
pgdata_restored_b3 = self.pgdata_content(node.data_dir)
|
|
|
|
self.compare_pgdata(pgdata_b3, pgdata_restored_b3)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
2019-05-28 11:41:03 +02:00
|
|
|
def test_basic_window_merge_multiple_descendants(self):
|
2019-03-25 16:15:46 +02:00
|
|
|
"""
|
|
|
|
PAGEb3
|
|
|
|
| PAGEa3
|
|
|
|
-----------------------------retention window
|
|
|
|
PAGEb2 /
|
|
|
|
| PAGEa2 / should be deleted
|
|
|
|
PAGEb1 \ /
|
|
|
|
| PAGEa1
|
|
|
|
FULLb |
|
|
|
|
FULLa
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2019-04-30 19:18:40 +02:00
|
|
|
initdb_params=['--data-checksums'],
|
|
|
|
pg_options={'autovacuum': 'off'})
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
node.pgbench_init(scale=3)
|
|
|
|
|
|
|
|
# Take FULL BACKUPs
|
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# Change FULLb backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change FULLb to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEa1 to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEa1 to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'OK')
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEb1 and FULLb to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEb1 and FULLb to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEa2 and FULLa to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'ERROR')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLa ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEb2 and PAGEb1 to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b2, 'ERROR')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
# and FULL stuff
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
2019-03-25 16:15:46 +02:00
|
|
|
# PAGEb2 ERROR
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
page_id_a3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
2019-06-29 02:19:31 +02:00
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# PAGEa3 OK
|
|
|
|
# PAGEb2 ERROR
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
2019-06-27 12:09:42 +02:00
|
|
|
# FULLb ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
# FULLa OK
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEa3 to ERROR
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a3, 'ERROR')
|
|
|
|
|
2019-06-29 02:19:31 +02:00
|
|
|
# Change PAGEb2, PAGEb1 and FULLb to OK
|
2019-03-25 16:15:46 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b2, 'OK')
|
2019-06-29 02:19:31 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
2019-06-27 12:09:42 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
page_id_b3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb3 OK
|
|
|
|
# PAGEa3 ERROR
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 ERROR
|
2019-06-29 02:19:31 +02:00
|
|
|
# PAGEb1 OK
|
2019-03-25 16:15:46 +02:00
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Change PAGEa3, PAGEa2 and PAGEb1 status to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a3, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
|
|
|
|
|
|
|
# PAGEb3 OK
|
|
|
|
# PAGEa3 OK
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Check that page_id_a3 and page_id_a2 are both direct descendants of page_id_a1
|
|
|
|
self.assertEqual(
|
2019-06-29 02:19:31 +02:00
|
|
|
self.show_pb(
|
|
|
|
backup_dir, 'node', backup_id=page_id_a3)['parent-backup-id'],
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_a1)
|
|
|
|
|
|
|
|
self.assertEqual(
|
2019-06-29 02:19:31 +02:00
|
|
|
self.show_pb(
|
|
|
|
backup_dir, 'node', backup_id=page_id_a2)['parent-backup-id'],
|
2019-03-25 16:15:46 +02:00
|
|
|
page_id_a1)
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup in [page_id_a3, page_id_b3, 'pg_probackup.conf']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
2020-02-21 21:19:52 +02:00
|
|
|
'--retention-window=1', '--delete-expired',
|
2019-03-25 16:15:46 +02:00
|
|
|
'--merge-expired', '--log-level-console=log'])
|
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# Merging chain A
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Merge incremental chain between full backup {0} and backup {1}".format(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_id_a, page_id_a3),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"INFO: Rename merged full backup {0} to {1}".format(
|
|
|
|
backup_id_a, page_id_a3), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
# self.assertIn(
|
|
|
|
# "WARNING: Backup {0} has multiple valid descendants. "
|
|
|
|
# "Automatic merge is not possible.".format(
|
|
|
|
# page_id_a1), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"LOG: Consider backup {0} for purge".format(
|
|
|
|
page_id_a2), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# Merge chain B
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Merge incremental chain between full backup {0} and backup {1}".format(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_id_b, page_id_b3),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"INFO: Rename merged full backup {0} to {1}".format(
|
|
|
|
backup_id_b, page_id_b3), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Delete: {0}".format(page_id_a2), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[1]['id'],
|
|
|
|
page_id_b3)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[0]['id'],
|
|
|
|
page_id_a3)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[1]['backup-mode'],
|
|
|
|
'FULL')
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[0]['backup-mode'],
|
|
|
|
'FULL')
|
|
|
|
|
|
|
|
# Clean after yourself
|
2020-06-19 09:39:29 +02:00
|
|
|
self.del_test_dir(module_name, fname, [node])
|
2020-02-21 21:19:52 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_basic_window_merge_multiple_descendants_1(self):
|
|
|
|
"""
|
|
|
|
PAGEb3
|
|
|
|
| PAGEa3
|
|
|
|
-----------------------------retention window
|
|
|
|
PAGEb2 /
|
|
|
|
| PAGEa2 /
|
|
|
|
PAGEb1 \ /
|
|
|
|
| PAGEa1
|
|
|
|
FULLb |
|
|
|
|
FULLa
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'],
|
|
|
|
pg_options={'autovacuum': 'off'})
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
node.pgbench_init(scale=3)
|
|
|
|
|
|
|
|
# Take FULL BACKUPs
|
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
# Change FULLb backup status to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
# Change FULLb to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
|
|
|
# Change PAGEa1 to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 ERROR
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
# Change PAGEa1 to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a1, 'OK')
|
|
|
|
|
|
|
|
# Change PAGEb1 and FULLb to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Change PAGEb1 and FULLb to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
|
|
|
# Change PAGEa2 and FULLa to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'ERROR')
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa ERROR
|
|
|
|
|
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa ERROR
|
|
|
|
|
|
|
|
# Change PAGEb2 and PAGEb1 to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b2, 'ERROR')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'ERROR')
|
|
|
|
|
|
|
|
# and FULL stuff
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_a, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
|
|
|
# PAGEb2 ERROR
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
page_id_a3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
# pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
# pgbench.wait()
|
|
|
|
|
|
|
|
# PAGEa3 OK
|
|
|
|
# PAGEb2 ERROR
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 ERROR
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb ERROR
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Change PAGEa3 to ERROR
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a3, 'ERROR')
|
|
|
|
|
|
|
|
# Change PAGEb2, PAGEb1 and FULLb to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b2, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'OK')
|
|
|
|
|
|
|
|
page_id_b3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# PAGEb3 OK
|
|
|
|
# PAGEa3 ERROR
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 ERROR
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
|
|
|
|
|
|
|
# Change PAGEa3, PAGEa2 and PAGEb1 status to OK
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a3, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_a2, 'OK')
|
|
|
|
self.change_backup_status(backup_dir, 'node', page_id_b1, 'OK')
|
|
|
|
|
|
|
|
# PAGEb3 OK
|
|
|
|
# PAGEa3 OK
|
|
|
|
# PAGEb2 OK
|
|
|
|
# PAGEa2 OK
|
|
|
|
# PAGEb1 OK
|
|
|
|
# PAGEa1 OK
|
|
|
|
# FULLb OK
|
|
|
|
# FULLa OK
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
# Check that page_id_a3 and page_id_a2 are both direct descendants of page_id_a1
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(
|
|
|
|
backup_dir, 'node', backup_id=page_id_a3)['parent-backup-id'],
|
|
|
|
page_id_a1)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(
|
|
|
|
backup_dir, 'node', backup_id=page_id_a2)['parent-backup-id'],
|
|
|
|
page_id_a1)
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup in [page_id_a3, page_id_b3, 'pg_probackup.conf']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--retention-window=1',
|
|
|
|
'--merge-expired', '--log-level-console=log'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 3)
|
|
|
|
|
|
|
|
# Merging chain A
|
2019-03-25 16:15:46 +02:00
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Merge incremental chain between full backup {0} and backup {1}".format(
|
|
|
|
backup_id_a, page_id_a3),
|
|
|
|
output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"INFO: Rename merged full backup {0} to {1}".format(
|
|
|
|
backup_id_a, page_id_a3), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
# self.assertIn(
|
|
|
|
# "WARNING: Backup {0} has multiple valid descendants. "
|
|
|
|
# "Automatic merge is not possible.".format(
|
|
|
|
# page_id_a1), output)
|
|
|
|
|
|
|
|
# Merge chain B
|
2019-03-25 16:15:46 +02:00
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"Merge incremental chain between full backup {0} and backup {1}".format(
|
|
|
|
backup_id_b, page_id_b3), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertIn(
|
2020-02-21 21:19:52 +02:00
|
|
|
"INFO: Rename merged full backup {0} to {1}".format(
|
|
|
|
backup_id_b, page_id_b3), output)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[2]['id'],
|
|
|
|
page_id_b3)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[1]['id'],
|
|
|
|
page_id_a3)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[0]['id'],
|
2020-02-21 21:19:52 +02:00
|
|
|
page_id_a2)
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[2]['backup-mode'],
|
|
|
|
'FULL')
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[1]['backup-mode'],
|
2020-02-21 21:19:52 +02:00
|
|
|
'FULL')
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
self.show_pb(backup_dir, 'node')[0]['backup-mode'],
|
2020-02-21 21:19:52 +02:00
|
|
|
'PAGE')
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--retention-window=1',
|
|
|
|
'--delete-expired', '--log-level-console=log'])
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
2020-06-19 09:39:29 +02:00
|
|
|
self.del_test_dir(module_name, fname, [node])
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_window_chains(self):
|
|
|
|
"""
|
|
|
|
PAGE
|
|
|
|
-------window
|
|
|
|
PAGE
|
|
|
|
PAGE
|
|
|
|
FULL
|
|
|
|
PAGE
|
|
|
|
PAGE
|
|
|
|
FULL
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2019-04-22 19:52:00 +02:00
|
|
|
initdb_params=['--data-checksums'],
|
|
|
|
pg_options={'autovacuum': 'off'})
|
2019-03-25 16:15:46 +02:00
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
node.pgbench_init(scale=3)
|
|
|
|
|
|
|
|
# Chain A
|
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# Chain B
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
page_id_b3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup in [page_id_b3, 'pg_probackup.conf']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--retention-window=1', '--expired',
|
|
|
|
'--merge-expired', '--log-level-console=log'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 1)
|
|
|
|
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
pgdata_restored = self.pgdata_content(node.data_dir)
|
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_window_chains_1(self):
|
|
|
|
"""
|
|
|
|
PAGE
|
|
|
|
-------window
|
|
|
|
PAGE
|
|
|
|
PAGE
|
|
|
|
FULL
|
|
|
|
PAGE
|
|
|
|
PAGE
|
|
|
|
FULL
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
node.pgbench_init(scale=3)
|
|
|
|
|
|
|
|
# Chain A
|
|
|
|
backup_id_a = self.backup_node(backup_dir, 'node', node)
|
|
|
|
page_id_a1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
page_id_a2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# Chain B
|
|
|
|
backup_id_b = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
page_id_b1 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
page_id_b2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
page_id_b3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
for backup in os.listdir(backups):
|
|
|
|
if backup in [page_id_b3, 'pg_probackup.conf']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, backup, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--retention-window=1',
|
|
|
|
'--merge-expired', '--log-level-console=log'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 4)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
"There are no backups to delete by retention policy",
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
"Retention merging finished",
|
|
|
|
output)
|
|
|
|
|
|
|
|
output = self.delete_expired(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--retention-window=1',
|
|
|
|
'--expired', '--log-level-console=log'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 1)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
"There are no backups to merge by retention policy",
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
"Purging finished",
|
|
|
|
output)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2019-06-27 12:09:42 +02:00
|
|
|
@unittest.skip("skip")
|
2019-03-25 16:15:46 +02:00
|
|
|
def test_window_error_backups(self):
|
|
|
|
"""
|
|
|
|
PAGE ERROR
|
|
|
|
-------window
|
|
|
|
PAGE ERROR
|
|
|
|
PAGE ERROR
|
|
|
|
PAGE ERROR
|
|
|
|
FULL ERROR
|
|
|
|
FULL
|
|
|
|
-------redundancy
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# Take FULL BACKUPs
|
|
|
|
backup_id_a1 = self.backup_node(backup_dir, 'node', node)
|
2019-08-01 22:57:14 +02:00
|
|
|
gdb = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page', gdb=True)
|
|
|
|
|
|
|
|
page_id_a3 = self.backup_node(
|
2019-03-25 16:15:46 +02:00
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# Change FULLb backup status to ERROR
|
2019-06-27 00:41:21 +02:00
|
|
|
self.change_backup_status(backup_dir, 'node', backup_id_b, 'ERROR')
|
|
|
|
|
2019-08-01 22:57:14 +02:00
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_window_error_backups_1(self):
|
|
|
|
"""
|
|
|
|
DELTA
|
|
|
|
PAGE ERROR
|
|
|
|
FULL
|
|
|
|
-------window
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# Take FULL BACKUP
|
|
|
|
full_id = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# Take PAGE BACKUP
|
|
|
|
gdb = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page', gdb=True)
|
|
|
|
|
|
|
|
gdb.set_breakpoint('pg_stop_backup')
|
|
|
|
gdb.run_until_break()
|
|
|
|
gdb.remove_all_breakpoints()
|
|
|
|
gdb._execute('signal SIGINT')
|
|
|
|
gdb.continue_execution_until_error()
|
|
|
|
|
|
|
|
page_id = self.show_pb(backup_dir, 'node')[1]['id']
|
|
|
|
|
|
|
|
# Take DELTA backup
|
|
|
|
delta_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta',
|
|
|
|
options=['--retention-window=2', '--delete-expired'])
|
|
|
|
|
|
|
|
# Take FULL BACKUP
|
|
|
|
full2_id = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 4)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_window_error_backups_2(self):
|
|
|
|
"""
|
|
|
|
DELTA
|
|
|
|
PAGE ERROR
|
|
|
|
FULL
|
|
|
|
-------window
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# Take FULL BACKUP
|
|
|
|
full_id = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# Take PAGE BACKUP
|
|
|
|
gdb = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page', gdb=True)
|
|
|
|
|
|
|
|
gdb.set_breakpoint('pg_stop_backup')
|
|
|
|
gdb.run_until_break()
|
2019-10-04 09:36:56 +02:00
|
|
|
gdb._execute('signal SIGKILL')
|
2019-08-01 22:57:14 +02:00
|
|
|
gdb.continue_execution_until_error()
|
|
|
|
|
|
|
|
page_id = self.show_pb(backup_dir, 'node')[1]['id']
|
|
|
|
|
2019-10-23 10:32:23 +02:00
|
|
|
if self.get_version(node) < 90600:
|
|
|
|
node.safe_psql(
|
|
|
|
'postgres',
|
|
|
|
'SELECT pg_catalog.pg_stop_backup()')
|
|
|
|
|
2019-08-01 22:57:14 +02:00
|
|
|
# Take DELTA backup
|
|
|
|
delta_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta',
|
|
|
|
options=['--retention-window=2', '--delete-expired'])
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 3)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
# self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_retention_redundancy_overlapping_chains(self):
|
|
|
|
""""""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
if self.get_version(node) < 90600:
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
return unittest.skip('Skipped because ptrack support is disabled')
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
self.set_config(
|
|
|
|
backup_dir, 'node', options=['--retention-redundancy=1'])
|
|
|
|
|
|
|
|
# Make backups to be purged
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
|
|
|
|
|
|
|
# Make backups to be keeped
|
|
|
|
gdb = self.backup_node(backup_dir, 'node', node, gdb=True)
|
|
|
|
gdb.set_breakpoint('backup_files')
|
|
|
|
gdb.run_until_break()
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
|
|
|
|
|
|
|
gdb.remove_all_breakpoints()
|
|
|
|
gdb.continue_execution_until_exit()
|
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
log = self.delete_expired(
|
|
|
|
backup_dir, 'node', options=['--expired', '--wal'])
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
|
|
|
|
2019-10-08 16:47:41 +02:00
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
|
2019-08-01 22:57:14 +02:00
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2019-06-27 00:41:21 +02:00
|
|
|
def test_retention_redundancy_overlapping_chains(self):
|
|
|
|
""""""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
2019-07-12 17:01:28 +02:00
|
|
|
if self.get_version(node) < 90600:
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
return unittest.skip('Skipped because ptrack support is disabled')
|
|
|
|
|
2019-06-27 00:41:21 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
self.set_config(
|
|
|
|
backup_dir, 'node', options=['--retention-redundancy=1'])
|
|
|
|
|
|
|
|
# Make backups to be purged
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
|
|
|
|
|
|
|
# Make backups to be keeped
|
|
|
|
gdb = self.backup_node(backup_dir, 'node', node, gdb=True)
|
|
|
|
gdb.set_breakpoint('backup_files')
|
|
|
|
gdb.run_until_break()
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
|
|
|
|
|
|
|
gdb.remove_all_breakpoints()
|
|
|
|
gdb.continue_execution_until_exit()
|
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type="page")
|
|
|
|
|
|
|
|
# Purge backups
|
|
|
|
log = self.delete_expired(
|
|
|
|
backup_dir, 'node', options=['--expired', '--wal'])
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
|
|
|
|
|
2019-10-08 16:47:41 +02:00
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
|
2019-06-27 00:41:21 +02:00
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2019-08-05 22:35:51 +02:00
|
|
|
|
2019-08-05 23:01:05 +02:00
|
|
|
def test_wal_purge_victim(self):
|
2019-08-05 22:35:51 +02:00
|
|
|
"""
|
2019-08-05 23:01:05 +02:00
|
|
|
https://github.com/postgrespro/pg_probackup/issues/103
|
2019-08-05 22:35:51 +02:00
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2019-08-05 23:01:05 +02:00
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2019-08-05 22:35:51 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# Make ERROR incremental backup
|
|
|
|
try:
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type='page')
|
|
|
|
# we should die here because exception is what we expect to happen
|
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because page backup should not be possible "
|
|
|
|
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd))
|
|
|
|
except ProbackupException as e:
|
2020-04-03 17:08:53 +02:00
|
|
|
self.assertTrue(
|
|
|
|
"WARNING: Valid backup on current timeline 1 is not found" in e.message and
|
|
|
|
"ERROR: Create new full backup before an incremental one" in e.message,
|
2019-08-05 22:35:51 +02:00
|
|
|
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
|
|
|
|
repr(e.message), self.cmd))
|
|
|
|
|
|
|
|
page_id = self.show_pb(backup_dir, 'node')[0]['id']
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
|
|
|
|
# Make FULL backup
|
2019-10-08 16:47:41 +02:00
|
|
|
full_id = self.backup_node(backup_dir, 'node', node, options=['--delete-wal'])
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
# we should die here because exception is what we expect to happen
|
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because page backup should not be possible "
|
|
|
|
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd))
|
|
|
|
except ProbackupException as e:
|
|
|
|
self.assertIn(
|
|
|
|
"INFO: Backup {0} WAL segments are valid".format(full_id),
|
|
|
|
e.message)
|
|
|
|
self.assertIn(
|
|
|
|
"WARNING: Backup {0} has missing parent 0".format(page_id),
|
|
|
|
e.message)
|
2019-08-05 22:35:51 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2019-08-28 19:12:13 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_failed_merge_redundancy_retention(self):
|
|
|
|
"""
|
|
|
|
Check that retention purge works correctly with MERGING backups
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(
|
|
|
|
module_name, fname, 'node'),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# FULL1 backup
|
|
|
|
full_id = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
delta_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
# FULL2 backup
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
# FULL3 backup
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
# DELTA BACKUP
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='delta')
|
|
|
|
|
|
|
|
self.set_config(
|
|
|
|
backup_dir, 'node', options=['--retention-redundancy=2'])
|
|
|
|
|
|
|
|
self.set_config(
|
|
|
|
backup_dir, 'node', options=['--retention-window=2'])
|
|
|
|
|
|
|
|
# create pair of MERGING backup as a result of failed merge
|
|
|
|
gdb = self.merge_backup(
|
|
|
|
backup_dir, 'node', delta_id, gdb=True)
|
2020-02-21 21:19:52 +02:00
|
|
|
gdb.set_breakpoint('backup_non_data_file')
|
2019-08-28 19:12:13 +02:00
|
|
|
gdb.run_until_break()
|
|
|
|
gdb.continue_execution_until_break(2)
|
|
|
|
gdb._execute('signal SIGKILL')
|
|
|
|
|
|
|
|
# "expire" first full backup
|
|
|
|
backups = os.path.join(backup_dir, 'backups', 'node')
|
|
|
|
with open(
|
|
|
|
os.path.join(
|
|
|
|
backups, full_id, "backup.control"), "a") as conf:
|
|
|
|
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
|
|
|
|
datetime.now() - timedelta(days=3)))
|
|
|
|
|
|
|
|
# run retention merge
|
|
|
|
self.delete_expired(
|
|
|
|
backup_dir, 'node', options=['--delete-expired'])
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
'MERGING',
|
|
|
|
self.show_pb(backup_dir, 'node', full_id)['status'],
|
|
|
|
'Backup STATUS should be "MERGING"')
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
'MERGING',
|
|
|
|
self.show_pb(backup_dir, 'node', delta_id)['status'],
|
|
|
|
'Backup STATUS should be "MERGING"')
|
|
|
|
|
|
|
|
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 10)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
def test_wal_depth_1(self):
|
|
|
|
"""
|
|
|
|
|-------------B5----------> WAL timeline3
|
|
|
|
|-----|-------------------------> WAL timeline2
|
|
|
|
B1 B2---| B3 B4-------B6-----> WAL timeline1
|
|
|
|
|
|
|
|
wal-depth=2
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
|
|
|
pg_options={
|
|
|
|
'archive_timeout': '30s',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'autovacuum': 'off'})
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
self.set_config(backup_dir, 'node', options=['--archive-timeout=60s'])
|
|
|
|
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# FULL
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
B1 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# PAGE
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
B2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# generate_some more data
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
target_xid = node.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
B3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
B4 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# Timeline 2
|
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_restored'))
|
|
|
|
|
|
|
|
node_restored.cleanup()
|
|
|
|
|
|
|
|
output = self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
options=[
|
|
|
|
'--recovery-target-xid={0}'.format(target_xid),
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'Restore of backup {0} completed'.format(B2),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.set_auto_conf(node_restored, options={'port': node_restored.port})
|
|
|
|
|
|
|
|
node_restored.slow_start()
|
|
|
|
|
|
|
|
node_restored.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
target_xid = node_restored.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
node_restored.pgbench_init(scale=2)
|
|
|
|
|
|
|
|
# Timeline 3
|
|
|
|
node_restored.cleanup()
|
|
|
|
|
|
|
|
output = self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
options=[
|
|
|
|
'--recovery-target-xid={0}'.format(target_xid),
|
|
|
|
'--recovery-target-timeline=2',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'Restore of backup {0} completed'.format(B2),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.set_auto_conf(node_restored, options={'port': node_restored.port})
|
|
|
|
|
|
|
|
node_restored.slow_start()
|
|
|
|
|
|
|
|
node_restored.pgbench_init(scale=1)
|
|
|
|
B5 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_restored, data_dir=node_restored.data_dir)
|
|
|
|
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
B6 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
lsn = self.show_archive(backup_dir, 'node', tli=2)['switchpoint']
|
|
|
|
|
|
|
|
self.validate_pb(
|
|
|
|
backup_dir, 'node', backup_id=B2,
|
|
|
|
options=['--recovery-target-lsn={0}'.format(lsn)])
|
|
|
|
|
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_wal_purge(self):
|
|
|
|
"""
|
|
|
|
-------------------------------------> tli5
|
|
|
|
---------------------------B6--------> tli4
|
|
|
|
S2`---------------> tli3
|
|
|
|
S1`------------S2---B4-------B5--> tli2
|
|
|
|
B1---S1-------------B2--------B3------> tli1
|
|
|
|
|
|
|
|
B* - backups
|
|
|
|
S* - switchpoints
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
TLI5 will be purged entirely
|
|
|
|
B6--------> tli4
|
|
|
|
S2`---------------> tli3
|
|
|
|
S1`------------S2---B4-------B5--> tli2
|
|
|
|
B1---S1-------------B2--------B3------> tli1
|
|
|
|
|
|
|
|
wal-depth=2
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_config(backup_dir, 'node', options=['--archive-timeout=60s'])
|
|
|
|
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# STREAM FULL
|
|
|
|
stream_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=['--stream'])
|
|
|
|
|
|
|
|
node.stop()
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# FULL
|
|
|
|
B1 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
target_xid = node.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-08 16:47:41 +02:00
|
|
|
node.pgbench_init(scale=5)
|
|
|
|
|
|
|
|
# B2 FULL on TLI1
|
|
|
|
B2 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
node.pgbench_init(scale=4)
|
|
|
|
B3 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
node.pgbench_init(scale=4)
|
|
|
|
|
2020-10-30 01:47:06 +02:00
|
|
|
self.delete_pb(backup_dir, 'node', options=['--delete-wal'])
|
|
|
|
|
2019-10-08 16:47:41 +02:00
|
|
|
# TLI 2
|
|
|
|
node_tli2 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli2'))
|
|
|
|
node_tli2.cleanup()
|
|
|
|
|
|
|
|
output = self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli2,
|
|
|
|
options=[
|
|
|
|
'--recovery-target-xid={0}'.format(target_xid),
|
|
|
|
'--recovery-target-timeline=1'.format(target_xid),
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: Restore of backup {0} completed'.format(B1),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.set_auto_conf(node_tli2, options={'port': node_tli2.port})
|
|
|
|
node_tli2.slow_start()
|
|
|
|
node_tli2.pgbench_init(scale=4)
|
|
|
|
|
|
|
|
target_xid = node_tli2.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-08 16:47:41 +02:00
|
|
|
node_tli2.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
B4 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_tli2, data_dir=node_tli2.data_dir)
|
|
|
|
node_tli2.pgbench_init(scale=3)
|
|
|
|
|
|
|
|
B5 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_tli2, data_dir=node_tli2.data_dir)
|
|
|
|
node_tli2.pgbench_init(scale=1)
|
|
|
|
node_tli2.cleanup()
|
|
|
|
|
|
|
|
# TLI3
|
|
|
|
node_tli3 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli3'))
|
|
|
|
node_tli3.cleanup()
|
|
|
|
|
|
|
|
# Note, that successful validation here is a happy coincidence
|
|
|
|
output = self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli3,
|
|
|
|
options=[
|
|
|
|
'--recovery-target-xid={0}'.format(target_xid),
|
|
|
|
'--recovery-target-timeline=2',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: Restore of backup {0} completed'.format(B1),
|
|
|
|
output)
|
|
|
|
self.set_auto_conf(node_tli3, options={'port': node_tli3.port})
|
|
|
|
node_tli3.slow_start()
|
|
|
|
node_tli3.pgbench_init(scale=5)
|
|
|
|
node_tli3.cleanup()
|
|
|
|
|
|
|
|
# TLI4
|
|
|
|
node_tli4 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli4'))
|
|
|
|
node_tli4.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli4, backup_id=stream_id,
|
|
|
|
options=[
|
|
|
|
'--recovery-target=immediate',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.set_auto_conf(node_tli4, options={'port': node_tli4.port})
|
|
|
|
self.set_archiving(backup_dir, 'node', node_tli4)
|
|
|
|
node_tli4.slow_start()
|
|
|
|
|
|
|
|
node_tli4.pgbench_init(scale=5)
|
|
|
|
|
|
|
|
B6 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_tli4, data_dir=node_tli4.data_dir)
|
|
|
|
node_tli4.pgbench_init(scale=5)
|
|
|
|
node_tli4.cleanup()
|
|
|
|
|
|
|
|
# TLI5
|
|
|
|
node_tli5 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli5'))
|
|
|
|
node_tli5.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli5, backup_id=stream_id,
|
|
|
|
options=[
|
|
|
|
'--recovery-target=immediate',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.set_auto_conf(node_tli5, options={'port': node_tli5.port})
|
|
|
|
self.set_archiving(backup_dir, 'node', node_tli5)
|
|
|
|
node_tli5.slow_start()
|
|
|
|
node_tli5.pgbench_init(scale=10)
|
|
|
|
|
|
|
|
# delete '.history' file of TLI4
|
|
|
|
os.remove(os.path.join(backup_dir, 'wal', 'node', '00000004.history'))
|
|
|
|
# delete '.history' file of TLI5
|
|
|
|
os.remove(os.path.join(backup_dir, 'wal', 'node', '00000005.history'))
|
|
|
|
|
|
|
|
output = self.delete_pb(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--delete-wal', '--dry-run',
|
|
|
|
'--log-level-console=verbose'])
|
|
|
|
|
|
|
|
self.assertIn(
|
2019-12-26 23:39:35 +02:00
|
|
|
'INFO: On timeline 4 WAL segments between 000000040000000000000002 '
|
|
|
|
'and 000000040000000000000006 can be removed',
|
2019-10-08 16:47:41 +02:00
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: On timeline 5 all files can be removed',
|
|
|
|
output)
|
|
|
|
|
|
|
|
show_tli1_before = self.show_archive(backup_dir, 'node', tli=1)
|
|
|
|
show_tli2_before = self.show_archive(backup_dir, 'node', tli=2)
|
|
|
|
show_tli3_before = self.show_archive(backup_dir, 'node', tli=3)
|
|
|
|
show_tli4_before = self.show_archive(backup_dir, 'node', tli=4)
|
|
|
|
show_tli5_before = self.show_archive(backup_dir, 'node', tli=5)
|
|
|
|
|
|
|
|
self.assertTrue(show_tli1_before)
|
|
|
|
self.assertTrue(show_tli2_before)
|
|
|
|
self.assertTrue(show_tli3_before)
|
|
|
|
self.assertTrue(show_tli4_before)
|
|
|
|
self.assertTrue(show_tli5_before)
|
|
|
|
|
|
|
|
output = self.delete_pb(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--delete-wal', '--log-level-console=verbose'])
|
|
|
|
|
|
|
|
self.assertIn(
|
2019-12-26 23:39:35 +02:00
|
|
|
'INFO: On timeline 4 WAL segments between 000000040000000000000002 '
|
|
|
|
'and 000000040000000000000006 will be removed',
|
2019-10-08 16:47:41 +02:00
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: On timeline 5 all files will be removed',
|
|
|
|
output)
|
|
|
|
|
|
|
|
show_tli1_after = self.show_archive(backup_dir, 'node', tli=1)
|
|
|
|
show_tli2_after = self.show_archive(backup_dir, 'node', tli=2)
|
|
|
|
show_tli3_after = self.show_archive(backup_dir, 'node', tli=3)
|
|
|
|
show_tli4_after = self.show_archive(backup_dir, 'node', tli=4)
|
|
|
|
show_tli5_after = self.show_archive(backup_dir, 'node', tli=5)
|
|
|
|
|
|
|
|
self.assertEqual(show_tli1_before, show_tli1_after)
|
|
|
|
self.assertEqual(show_tli2_before, show_tli2_after)
|
|
|
|
self.assertEqual(show_tli3_before, show_tli3_after)
|
|
|
|
self.assertNotEqual(show_tli4_before, show_tli4_after)
|
|
|
|
self.assertNotEqual(show_tli5_before, show_tli5_after)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli4_before['min-segno'],
|
2019-12-26 23:39:35 +02:00
|
|
|
'000000040000000000000002')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli4_after['min-segno'],
|
2019-12-26 23:39:35 +02:00
|
|
|
'000000040000000000000006')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertFalse(show_tli5_after)
|
|
|
|
|
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_wal_depth_2(self):
|
|
|
|
"""
|
|
|
|
-------------------------------------> tli5
|
|
|
|
---------------------------B6--------> tli4
|
|
|
|
S2`---------------> tli3
|
|
|
|
S1`------------S2---B4-------B5--> tli2
|
|
|
|
B1---S1-------------B2--------B3------> tli1
|
|
|
|
|
|
|
|
B* - backups
|
|
|
|
S* - switchpoints
|
|
|
|
wal-depth=2
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
TLI5 will be purged entirely
|
|
|
|
B6--------> tli4
|
|
|
|
S2`---------------> tli3
|
|
|
|
S1`------------S2 B4-------B5--> tli2
|
|
|
|
B1---S1 B2--------B3------> tli1
|
|
|
|
|
|
|
|
wal-depth=2
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_config(backup_dir, 'node', options=['--archive-timeout=60s'])
|
|
|
|
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# STREAM FULL
|
|
|
|
stream_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=['--stream'])
|
|
|
|
|
|
|
|
node.stop()
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# FULL
|
|
|
|
B1 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
target_xid = node.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-08 16:47:41 +02:00
|
|
|
node.pgbench_init(scale=5)
|
|
|
|
|
|
|
|
# B2 FULL on TLI1
|
|
|
|
B2 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
node.pgbench_init(scale=4)
|
|
|
|
B3 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
node.pgbench_init(scale=4)
|
|
|
|
|
|
|
|
# TLI 2
|
|
|
|
node_tli2 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli2'))
|
|
|
|
node_tli2.cleanup()
|
|
|
|
|
|
|
|
output = self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli2,
|
|
|
|
options=[
|
|
|
|
'--recovery-target-xid={0}'.format(target_xid),
|
|
|
|
'--recovery-target-timeline=1'.format(target_xid),
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: Restore of backup {0} completed'.format(B1),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.set_auto_conf(node_tli2, options={'port': node_tli2.port})
|
|
|
|
node_tli2.slow_start()
|
|
|
|
node_tli2.pgbench_init(scale=4)
|
|
|
|
|
|
|
|
target_xid = node_tli2.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-08 16:47:41 +02:00
|
|
|
node_tli2.pgbench_init(scale=1)
|
|
|
|
|
|
|
|
B4 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_tli2, data_dir=node_tli2.data_dir)
|
|
|
|
node_tli2.pgbench_init(scale=3)
|
|
|
|
|
|
|
|
B5 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_tli2, data_dir=node_tli2.data_dir)
|
|
|
|
node_tli2.pgbench_init(scale=1)
|
|
|
|
node_tli2.cleanup()
|
|
|
|
|
|
|
|
# TLI3
|
|
|
|
node_tli3 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli3'))
|
|
|
|
node_tli3.cleanup()
|
|
|
|
|
|
|
|
# Note, that successful validation here is a happy coincidence
|
|
|
|
output = self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli3,
|
|
|
|
options=[
|
|
|
|
'--recovery-target-xid={0}'.format(target_xid),
|
|
|
|
'--recovery-target-timeline=2',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: Restore of backup {0} completed'.format(B1),
|
|
|
|
output)
|
|
|
|
self.set_auto_conf(node_tli3, options={'port': node_tli3.port})
|
|
|
|
node_tli3.slow_start()
|
|
|
|
node_tli3.pgbench_init(scale=5)
|
|
|
|
node_tli3.cleanup()
|
|
|
|
|
|
|
|
# TLI4
|
|
|
|
node_tli4 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli4'))
|
|
|
|
node_tli4.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli4, backup_id=stream_id,
|
|
|
|
options=[
|
|
|
|
'--recovery-target=immediate',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.set_auto_conf(node_tli4, options={'port': node_tli4.port})
|
|
|
|
self.set_archiving(backup_dir, 'node', node_tli4)
|
|
|
|
node_tli4.slow_start()
|
|
|
|
|
|
|
|
node_tli4.pgbench_init(scale=5)
|
|
|
|
|
|
|
|
B6 = self.backup_node(
|
|
|
|
backup_dir, 'node', node_tli4, data_dir=node_tli4.data_dir)
|
|
|
|
node_tli4.pgbench_init(scale=5)
|
|
|
|
node_tli4.cleanup()
|
|
|
|
|
|
|
|
# TLI5
|
|
|
|
node_tli5 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node_tli5'))
|
|
|
|
node_tli5.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_tli5, backup_id=stream_id,
|
|
|
|
options=[
|
|
|
|
'--recovery-target=immediate',
|
|
|
|
'--recovery-target-action=promote'])
|
|
|
|
|
|
|
|
self.set_auto_conf(node_tli5, options={'port': node_tli5.port})
|
|
|
|
self.set_archiving(backup_dir, 'node', node_tli5)
|
|
|
|
node_tli5.slow_start()
|
|
|
|
node_tli5.pgbench_init(scale=10)
|
|
|
|
|
|
|
|
# delete '.history' file of TLI4
|
|
|
|
os.remove(os.path.join(backup_dir, 'wal', 'node', '00000004.history'))
|
|
|
|
# delete '.history' file of TLI5
|
|
|
|
os.remove(os.path.join(backup_dir, 'wal', 'node', '00000005.history'))
|
|
|
|
|
|
|
|
output = self.delete_pb(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=[
|
|
|
|
'--delete-wal', '--dry-run',
|
|
|
|
'--wal-depth=2', '--log-level-console=verbose'])
|
|
|
|
|
|
|
|
start_lsn_B2 = self.show_pb(backup_dir, 'node', B2)['start-lsn']
|
|
|
|
self.assertIn(
|
|
|
|
'On timeline 1 WAL is protected from purge at {0}'.format(start_lsn_B2),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
2019-10-09 12:23:14 +02:00
|
|
|
'LOG: Archive backup {0} to stay consistent protect from '
|
2019-12-26 23:39:35 +02:00
|
|
|
'purge WAL interval between 000000010000000000000004 '
|
2020-04-03 17:08:53 +02:00
|
|
|
'and 000000010000000000000005 on timeline 1'.format(B1), output)
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
start_lsn_B4 = self.show_pb(backup_dir, 'node', B4)['start-lsn']
|
|
|
|
self.assertIn(
|
|
|
|
'On timeline 2 WAL is protected from purge at {0}'.format(start_lsn_B4),
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
2019-10-09 12:23:14 +02:00
|
|
|
'LOG: Timeline 3 to stay reachable from timeline 1 protect '
|
2020-04-03 17:08:53 +02:00
|
|
|
'from purge WAL interval between 000000020000000000000006 and '
|
|
|
|
'000000020000000000000009 on timeline 2', output)
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertIn(
|
2019-10-09 12:23:14 +02:00
|
|
|
'LOG: Timeline 3 to stay reachable from timeline 1 protect '
|
2019-12-26 23:39:35 +02:00
|
|
|
'from purge WAL interval between 000000010000000000000004 and '
|
2020-04-03 17:08:53 +02:00
|
|
|
'000000010000000000000006 on timeline 1', output)
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
show_tli1_before = self.show_archive(backup_dir, 'node', tli=1)
|
|
|
|
show_tli2_before = self.show_archive(backup_dir, 'node', tli=2)
|
|
|
|
show_tli3_before = self.show_archive(backup_dir, 'node', tli=3)
|
|
|
|
show_tli4_before = self.show_archive(backup_dir, 'node', tli=4)
|
|
|
|
show_tli5_before = self.show_archive(backup_dir, 'node', tli=5)
|
|
|
|
|
|
|
|
self.assertTrue(show_tli1_before)
|
|
|
|
self.assertTrue(show_tli2_before)
|
|
|
|
self.assertTrue(show_tli3_before)
|
|
|
|
self.assertTrue(show_tli4_before)
|
|
|
|
self.assertTrue(show_tli5_before)
|
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
sleep(5)
|
|
|
|
|
2019-10-08 16:47:41 +02:00
|
|
|
output = self.delete_pb(
|
|
|
|
backup_dir, 'node',
|
|
|
|
options=['--delete-wal', '--wal-depth=2', '--log-level-console=verbose'])
|
|
|
|
|
2020-02-21 21:19:52 +02:00
|
|
|
# print(output)
|
|
|
|
|
2019-10-08 16:47:41 +02:00
|
|
|
show_tli1_after = self.show_archive(backup_dir, 'node', tli=1)
|
|
|
|
show_tli2_after = self.show_archive(backup_dir, 'node', tli=2)
|
|
|
|
show_tli3_after = self.show_archive(backup_dir, 'node', tli=3)
|
|
|
|
show_tli4_after = self.show_archive(backup_dir, 'node', tli=4)
|
|
|
|
show_tli5_after = self.show_archive(backup_dir, 'node', tli=5)
|
|
|
|
|
|
|
|
self.assertNotEqual(show_tli1_before, show_tli1_after)
|
|
|
|
self.assertNotEqual(show_tli2_before, show_tli2_after)
|
|
|
|
self.assertEqual(show_tli3_before, show_tli3_after)
|
|
|
|
self.assertNotEqual(show_tli4_before, show_tli4_after)
|
|
|
|
self.assertNotEqual(show_tli5_before, show_tli5_after)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli4_before['min-segno'],
|
2019-12-26 23:39:35 +02:00
|
|
|
'000000040000000000000002')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli4_after['min-segno'],
|
2019-12-26 23:39:35 +02:00
|
|
|
'000000040000000000000006')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertFalse(show_tli5_after)
|
|
|
|
|
|
|
|
self.assertTrue(show_tli1_after['lost-segments'])
|
|
|
|
self.assertTrue(show_tli2_after['lost-segments'])
|
|
|
|
self.assertFalse(show_tli3_after['lost-segments'])
|
|
|
|
self.assertFalse(show_tli4_after['lost-segments'])
|
|
|
|
self.assertFalse(show_tli5_after)
|
|
|
|
|
|
|
|
self.assertEqual(len(show_tli1_after['lost-segments']), 1)
|
|
|
|
self.assertEqual(len(show_tli2_after['lost-segments']), 1)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli1_after['lost-segments'][0]['begin-segno'],
|
2020-04-03 17:08:53 +02:00
|
|
|
'000000010000000000000007')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli1_after['lost-segments'][0]['end-segno'],
|
2020-04-03 17:08:53 +02:00
|
|
|
'00000001000000000000000A')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli2_after['lost-segments'][0]['begin-segno'],
|
2020-04-03 17:08:53 +02:00
|
|
|
'00000002000000000000000A')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
show_tli2_after['lost-segments'][0]['end-segno'],
|
2020-04-03 17:08:53 +02:00
|
|
|
'00000002000000000000000A')
|
2019-10-08 16:47:41 +02:00
|
|
|
|
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
|
|
|
|
self.del_test_dir(module_name, fname)
|
2019-10-09 12:23:14 +02:00
|
|
|
|
|
|
|
def test_basic_wal_depth(self):
|
|
|
|
"""
|
|
|
|
B1---B1----B3-----B4----B5------> tli1
|
|
|
|
|
|
|
|
Expected result with wal-depth=1:
|
|
|
|
B1 B1 B3 B4 B5------> tli1
|
|
|
|
|
|
|
|
wal-depth=1
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'])
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_config(backup_dir, 'node', options=['--archive-timeout=60s'])
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# FULL
|
|
|
|
node.pgbench_init(scale=1)
|
|
|
|
B1 = self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
|
|
|
|
# B2
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
B2 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# B3
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
B3 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# B4
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
B4 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
|
|
|
|
|
|
|
# B5
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
B5 = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page',
|
|
|
|
options=['--wal-depth=1', '--delete-wal'])
|
|
|
|
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
target_xid = node.safe_psql(
|
|
|
|
"postgres",
|
2020-10-30 01:47:06 +02:00
|
|
|
"select txid_current()").decode('utf-8').rstrip()
|
2019-10-09 12:23:14 +02:00
|
|
|
|
|
|
|
self.switch_wal_segment(node)
|
|
|
|
|
|
|
|
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
|
|
|
|
pgbench.wait()
|
|
|
|
|
|
|
|
tli1 = self.show_archive(backup_dir, 'node', tli=1)
|
|
|
|
|
|
|
|
# check that there are 4 lost_segments intervals
|
|
|
|
self.assertEqual(len(tli1['lost-segments']), 4)
|
|
|
|
|
|
|
|
output = self.validate_pb(
|
|
|
|
backup_dir, 'node', B5,
|
|
|
|
options=['--recovery-target-xid={0}'.format(target_xid)])
|
|
|
|
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'INFO: Backup validation completed successfully on time',
|
|
|
|
output)
|
|
|
|
|
|
|
|
self.assertIn(
|
|
|
|
'xid {0} and LSN'.format(target_xid),
|
|
|
|
output)
|
|
|
|
|
|
|
|
for backup_id in [B1, B2, B3, B4]:
|
|
|
|
try:
|
|
|
|
self.validate_pb(
|
|
|
|
backup_dir, 'node', backup_id,
|
|
|
|
options=['--recovery-target-xid={0}'.format(target_xid)])
|
|
|
|
# we should die here because exception is what we expect to happen
|
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because page backup should not be possible "
|
|
|
|
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd))
|
|
|
|
except ProbackupException as e:
|
|
|
|
self.assertIn(
|
|
|
|
"ERROR: Not enough WAL records to xid {0}".format(target_xid),
|
|
|
|
e.message)
|
|
|
|
|
|
|
|
self.validate_pb(backup_dir, 'node')
|
|
|
|
|
2020-06-19 09:39:29 +02:00
|
|
|
self.del_test_dir(module_name, fname, [node])
|