1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-05 11:00:22 +02:00
pg_probackup/tests/backup_test.py

999 lines
36 KiB
Python
Raw Normal View History

import unittest
2017-06-20 12:57:23 +02:00
import os
from time import sleep
2017-06-27 07:42:52 +02:00
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
2017-07-12 16:28:28 +02:00
module_name = 'backup'
2017-07-12 16:28:28 +02:00
class BackupTest(ProbackupTest, unittest.TestCase):
2017-05-03 13:14:48 +02:00
# @unittest.skip("skip")
# @unittest.expectedFailure
2017-06-07 16:52:07 +02:00
# PGPRO-707
2017-05-03 13:14:48 +02:00
def test_backup_modes_archive(self):
"""standart backup modes with ARCHIVE WAL method"""
fname = self.id().split('.')[3]
2018-01-17 20:15:49 +02:00
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
2017-05-03 13:14:48 +02:00
initdb_params=['--data-checksums'],
2018-01-17 20:15:49 +02:00
pg_options={
2019-03-01 18:19:56 +02:00
'ptrack_enable': 'on'})
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-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
backup_id = self.backup_node(backup_dir, 'node', node)
show_backup = self.show_pb(backup_dir, 'node')[0]
2017-05-03 13:14:48 +02:00
2018-06-02 19:35:37 +02:00
self.assertEqual(show_backup['status'], "OK")
self.assertEqual(show_backup['backup-mode'], "FULL")
2017-05-03 13:14:48 +02:00
# postmaster.pid and postmaster.opts shouldn't be copied
excluded = True
2018-01-17 20:15:49 +02:00
db_dir = os.path.join(
backup_dir, "backups", 'node', backup_id, "database")
2017-06-20 12:57:23 +02:00
for f in os.listdir(db_dir):
2018-01-17 20:15:49 +02:00
if (
os.path.isfile(os.path.join(db_dir, f)) and
(
f == "postmaster.pid" or
f == "postmaster.opts"
)
):
excluded = False
self.assertEqual(excluded, True)
2017-05-03 13:14:48 +02:00
# page backup mode
2018-01-17 20:15:49 +02:00
page_backup_id = self.backup_node(
backup_dir, 'node', node, backup_type="page")
2017-05-03 13:14:48 +02:00
2017-05-03 17:05:19 +02:00
# print self.show_pb(node)
2017-06-20 12:57:23 +02:00
show_backup = self.show_pb(backup_dir, 'node')[1]
2018-06-02 19:35:37 +02:00
self.assertEqual(show_backup['status'], "OK")
self.assertEqual(show_backup['backup-mode'], "PAGE")
2017-05-03 13:14:48 +02:00
# Check parent backup
self.assertEqual(
2017-06-20 12:57:23 +02:00
backup_id,
2018-01-17 20:15:49 +02:00
self.show_pb(
backup_dir, 'node',
2018-06-02 19:35:37 +02:00
backup_id=show_backup['id'])["parent-backup-id"])
2017-05-03 13:14:48 +02:00
# ptrack backup mode
2017-06-20 12:57:23 +02:00
self.backup_node(backup_dir, 'node', node, backup_type="ptrack")
2017-05-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
show_backup = self.show_pb(backup_dir, 'node')[2]
2018-06-02 19:35:37 +02:00
self.assertEqual(show_backup['status'], "OK")
self.assertEqual(show_backup['backup-mode'], "PTRACK")
2017-05-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
# Check parent backup
self.assertEqual(
page_backup_id,
2018-01-17 20:15:49 +02:00
self.show_pb(
backup_dir, 'node',
2018-06-02 19:35:37 +02:00
backup_id=show_backup['id'])["parent-backup-id"])
2017-06-20 12:57:23 +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-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
# @unittest.skip("skip")
2017-05-03 13:14:48 +02:00
def test_smooth_checkpoint(self):
"""full backup with smooth checkpoint"""
fname = self.id().split('.')[3]
2018-01-17 20:15:49 +02:00
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
2019-03-01 18:19:56 +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-06-20 12:57:23 +02:00
2018-01-17 20:15:49 +02:00
self.backup_node(
backup_dir, 'node', node,
options=["-C"])
2018-06-02 19:35:37 +02:00
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
2017-06-20 12:57:23 +02:00
node.stop()
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-06-27 07:42:52 +02:00
# @unittest.skip("skip")
2017-06-20 12:57:23 +02:00
def test_incremental_backup_without_full(self):
"""page-level backup without validated full backup"""
fname = self.id().split('.')[3]
2018-01-17 20:15:49 +02:00
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
2017-06-20 12:57:23 +02:00
initdb_params=['--data-checksums'],
2019-03-01 18:19:56 +02:00
pg_options={'ptrack_enable': 'on'})
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-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
try:
self.backup_node(backup_dir, 'node', node, backup_type="page")
# we should die here because exception is what we expect to happen
2018-01-17 20:15:49 +02:00
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))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2017-12-13 10:15:42 +02:00
self.assertIn(
2018-01-17 20:15:49 +02:00
"ERROR: Valid backup on current timeline is not found. "
"Create new FULL backup before an incremental one.",
2017-12-13 10:15:42 +02:00
e.message,
2018-01-17 20:15:49 +02:00
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
repr(e.message), self.cmd))
2017-05-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
sleep(1)
2017-05-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
try:
self.backup_node(backup_dir, 'node', node, backup_type="ptrack")
# we should die here because exception is what we expect to happen
2018-01-17 20:15:49 +02:00
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))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2017-12-13 10:15:42 +02:00
self.assertIn(
2018-01-17 20:15:49 +02:00
"ERROR: Valid backup on current timeline is not found. "
"Create new FULL backup before an incremental one.",
2017-12-13 10:15:42 +02:00
e.message,
2018-01-17 20:15:49 +02:00
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
repr(e.message), self.cmd))
2017-06-20 12:57:23 +02:00
2018-01-17 20:15:49 +02:00
self.assertEqual(
2018-06-02 19:35:37 +02:00
self.show_pb(backup_dir, 'node')[0]['status'],
2018-01-17 20:15:49 +02:00
"ERROR")
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-03 13:14:48 +02:00
# @unittest.skip("skip")
2017-06-20 12:57:23 +02:00
def test_incremental_backup_corrupt_full(self):
"""page-level backup with corrupted full backup"""
2017-05-03 13:14:48 +02:00
fname = self.id().split('.')[3]
2018-01-17 20:15:49 +02:00
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
2017-05-03 13:14:48 +02:00
initdb_params=['--data-checksums'],
2019-03-01 18:19:56 +02:00
pg_options={'ptrack_enable': 'on'})
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-06-20 12:57:23 +02:00
backup_id = self.backup_node(backup_dir, 'node', node)
2018-01-17 20:15:49 +02:00
file = os.path.join(
backup_dir, "backups", "node", backup_id,
"database", "postgresql.conf")
2017-06-20 12:57:23 +02:00
os.remove(file)
2017-05-03 13:14:48 +02:00
try:
2017-06-27 07:42:52 +02:00
self.validate_pb(backup_dir, 'node')
2017-06-20 12:57:23 +02:00
# we should die here because exception is what we expect to happen
2018-01-17 20:15:49 +02:00
self.assertEqual(
1, 0,
"Expecting Error because of validation of corrupted backup.\n"
" Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2018-01-17 20:15:49 +02:00
self.assertTrue(
"INFO: Validate backups of the instance 'node'" in e.message and
"WARNING: Backup file".format(
2018-01-17 20:15:49 +02:00
file) in e.message and
"is not found".format(file) in e.message and
"WARNING: Backup {0} data files are corrupted".format(
2018-01-17 20:15:49 +02:00
backup_id) in e.message and
"WARNING: Some backups are not valid" in e.message,
2018-01-17 20:15:49 +02:00
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
repr(e.message), self.cmd))
2017-06-20 12:57:23 +02:00
2017-06-27 07:42:52 +02:00
try:
self.backup_node(backup_dir, 'node', node, backup_type="page")
# we should die here because exception is what we expect to happen
2018-01-17 20:15:49 +02:00
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))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2017-12-13 10:15:42 +02:00
self.assertIn(
2018-01-17 20:15:49 +02:00
"ERROR: Valid backup on current timeline is not found. "
"Create new FULL backup before an incremental one.",
2017-12-13 10:15:42 +02:00
e.message,
2018-01-17 20:15:49 +02:00
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
repr(e.message), self.cmd))
2017-05-03 13:14:48 +02:00
2018-01-17 20:15:49 +02:00
self.assertEqual(
self.show_pb(backup_dir, 'node', backup_id)['status'], "CORRUPT")
self.assertEqual(
2018-06-02 19:35:37 +02:00
self.show_pb(backup_dir, 'node')[1]['status'], "ERROR")
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-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
# @unittest.skip("skip")
2017-05-03 13:14:48 +02:00
def test_ptrack_threads(self):
"""ptrack multi thread backup mode"""
2017-05-15 01:43:05 +02:00
fname = self.id().split('.')[3]
2018-01-17 20:15:49 +02:00
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
2017-05-15 01:43:05 +02:00
initdb_params=['--data-checksums'],
2019-03-01 18:19:56 +02:00
pg_options={'ptrack_enable': 'on'})
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-03 13:14:48 +02:00
2018-01-17 20:15:49 +02:00
self.backup_node(
backup_dir, 'node', node,
backup_type="full", options=["-j", "4"])
2018-06-02 19:35:37 +02:00
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
2017-05-03 13:14:48 +02:00
2018-01-17 20:15:49 +02:00
self.backup_node(
backup_dir, 'node', node,
backup_type="ptrack", options=["-j", "4"])
2018-06-02 19:35:37 +02:00
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
2017-05-03 13:14:48 +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-03 13:14:48 +02:00
2017-06-20 12:57:23 +02:00
# @unittest.skip("skip")
2017-05-03 13:14:48 +02:00
def test_ptrack_threads_stream(self):
"""ptrack multi thread backup mode and stream"""
fname = self.id().split('.')[3]
2018-01-17 20:15:49 +02:00
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
2017-05-03 13:14:48 +02:00
set_replication=True,
initdb_params=['--data-checksums'],
2018-01-17 20:15:49 +02:00
pg_options={
'ptrack_enable': 'on',
2019-03-01 18:19:56 +02:00
'max_wal_senders': '2'})
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)
2018-12-25 16:48:49 +02:00
node.slow_start()
2017-05-03 13:14:48 +02:00
2018-01-17 20:15:49 +02:00
self.backup_node(
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
2017-05-03 13:14:48 +02:00
2018-06-02 19:35:37 +02:00
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['status'], "OK")
2018-01-17 20:15:49 +02:00
self.backup_node(
backup_dir, 'node', node,
backup_type="ptrack", options=["-j", "4", "--stream"])
2018-06-02 19:35:37 +02:00
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['status'], "OK")
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)
# @unittest.skip("skip")
def test_page_corruption_heal_via_ptrack_1(self):
"""make node, corrupt some page, check that backup failed"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'],
2019-03-01 18:19:56 +02:00
pg_options={'max_wal_senders': '2'})
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
2018-12-25 16:48:49 +02:00
node.slow_start()
self.backup_node(
backup_dir, 'node', node,
backup_type="full", options=["-j", "4", "--stream"])
node.safe_psql(
"postgres",
"create table t_heap as select 1 as id, md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,1000) i")
node.safe_psql(
"postgres",
"CHECKPOINT;")
heap_path = node.safe_psql(
"postgres",
"select pg_relation_filepath('t_heap')").rstrip()
with open(os.path.join(node.data_dir, heap_path), "rb+", 0) as f:
f.seek(9000)
f.write(b"bla")
f.flush()
f.close
self.backup_node(
backup_dir, 'node', node, backup_type="full",
2018-11-12 10:51:58 +02:00
options=["-j", "4", "--stream", "--log-level-file=verbose"])
# open log file and check
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
log_content = f.read()
2018-01-18 17:56:33 +02:00
self.assertIn('block 1, try to fetch via SQL', log_content)
2018-03-03 10:42:10 +02:00
self.assertIn('SELECT pg_catalog.pg_ptrack_get_block', log_content)
f.close
self.assertTrue(
2018-06-02 19:35:37 +02:00
self.show_pb(backup_dir, 'node')[1]['status'] == 'OK',
"Backup Status should be OK")
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_page_corruption_heal_via_ptrack_2(self):
"""make node, corrupt some page, check that backup failed"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'],
2019-03-01 18:19:56 +02:00
pg_options={'max_wal_senders': '2'})
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
2018-12-25 16:48:49 +02:00
node.slow_start()
self.backup_node(
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
node.safe_psql(
"postgres",
"create table t_heap as select 1 as id, md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,1000) i")
node.safe_psql(
"postgres",
"CHECKPOINT;")
heap_path = node.safe_psql(
"postgres",
"select pg_relation_filepath('t_heap')").rstrip()
node.stop()
with open(os.path.join(node.data_dir, heap_path), "rb+", 0) as f:
f.seek(9000)
f.write(b"bla")
f.flush()
f.close
2018-12-25 16:48:49 +02:00
node.slow_start()
try:
self.backup_node(
backup_dir, 'node', node,
backup_type="full", options=["-j", "4", "--stream"])
# we should die here because exception is what we expect to happen
self.assertEqual(
1, 0,
"Expecting Error because of page "
"corruption in PostgreSQL instance.\n"
" Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue(
"WARNING: File" in e.message and
"blknum" in e.message and
"have wrong checksum" in e.message and
"try to fetch via SQL" in e.message and
"WARNING: page verification failed, "
"calculated checksum" in e.message and
"ERROR: query failed: "
"ERROR: invalid page in block" in e.message and
2018-03-03 10:42:10 +02:00
"query was: SELECT pg_catalog.pg_ptrack_get_block_2" in e.message,
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
repr(e.message), self.cmd))
self.assertTrue(
2018-06-02 19:35:37 +02:00
self.show_pb(backup_dir, 'node')[1]['status'] == 'ERROR',
"Backup Status should be ERROR")
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
2018-01-28 03:36:27 +02:00
def test_tablespace_in_pgdata_pgpro_1376(self):
"""PGPRO-1376 """
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'],
2019-03-01 18:19:56 +02:00
pg_options={'max_wal_senders': '2'})
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
2018-12-25 16:48:49 +02:00
node.slow_start()
self.create_tblspace_in_node(
node, 'tblspace1',
2018-04-28 17:49:34 +02:00
tblspc_path=(
os.path.join(
node.data_dir, 'somedirectory', '100500'))
)
2018-04-25 21:15:05 +02:00
self.create_tblspace_in_node(
node, 'tblspace2',
tblspc_path=(os.path.join(node.data_dir))
)
node.safe_psql(
"postgres",
"create table t_heap1 tablespace tblspace1 as select 1 as id, "
"md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,1000) i")
node.safe_psql(
"postgres",
2018-04-25 21:15:05 +02:00
"create table t_heap2 tablespace tblspace2 as select 1 as id, "
"md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,1000) i")
backup_id_1 = self.backup_node(
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
2018-04-25 21:15:05 +02:00
node.safe_psql(
"postgres",
"drop table t_heap2")
node.safe_psql(
"postgres",
"drop tablespace tblspace2")
self.backup_node(
2018-04-25 21:15:05 +02:00
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
pgdata = self.pgdata_content(node.data_dir)
relfilenode = node.safe_psql(
"postgres",
2018-04-25 21:15:05 +02:00
"select 't_heap1'::regclass::oid"
).rstrip()
list = []
for root, dirs, files in os.walk(os.path.join(
2018-12-27 21:40:23 +02:00
backup_dir, 'backups', 'node', backup_id_1)):
for file in files:
if file == relfilenode:
path = os.path.join(root, file)
list = list + [path]
# We expect that relfilenode occures only once
if len(list) > 1:
message = ""
for string in list:
message = message + string + "\n"
self.assertEqual(
2018-01-26 17:29:31 +02:00
1, 0,
"Following file copied twice by backup:\n {0}".format(
message)
)
2018-04-25 21:15:05 +02:00
node.cleanup()
self.restore_node(
backup_dir, 'node', node, options=["-j", "4"])
if self.paranoia:
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_tablespace_handling(self):
"""
make node, take full backup, check that restore with
tablespace mapping will end with error, take page backup,
check that restore with tablespace mapping will end with
success
"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={
'max_wal_senders': '2'})
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
node.slow_start()
self.backup_node(
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
tblspace1_old_path = self.get_tblspace_path(node, 'tblspace1_old')
tblspace2_old_path = self.get_tblspace_path(node, 'tblspace2_old')
self.create_tblspace_in_node(
node, 'some_lame_tablespace')
self.create_tblspace_in_node(
node, 'tblspace1',
tblspc_path=tblspace1_old_path)
self.create_tblspace_in_node(
node, 'tblspace2',
tblspc_path=tblspace2_old_path)
node.safe_psql(
"postgres",
"create table t_heap_lame tablespace some_lame_tablespace "
"as select 1 as id, md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,1000) i")
node.safe_psql(
"postgres",
"create table t_heap2 tablespace tblspace2 as select 1 as id, "
"md5(i::text) as text, "
"md5(repeat(i::text,10))::tsvector as tsvector "
"from generate_series(0,1000) i")
tblspace1_new_path = self.get_tblspace_path(node, 'tblspace1_new')
tblspace2_new_path = self.get_tblspace_path(node, 'tblspace2_new')
node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored'))
node_restored.cleanup()
try:
self.restore_node(
backup_dir, 'node', node_restored,
options=[
"-j", "4",
"-T", "{0}={1}".format(
tblspace1_old_path, tblspace1_new_path),
"-T", "{0}={1}".format(
tblspace2_old_path, tblspace2_new_path)])
# we should die here because exception is what we expect to happen
self.assertEqual(
1, 0,
"Expecting Error because tablespace mapping is incorrect"
"\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue(
'ERROR: --tablespace-mapping option' in e.message and
'have an entry in tablespace_map file' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd))
node.safe_psql(
"postgres",
"drop table t_heap_lame")
node.safe_psql(
"postgres",
"drop tablespace some_lame_tablespace")
self.backup_node(
backup_dir, 'node', node, backup_type="delta",
options=["-j", "4", "--stream"])
self.restore_node(
backup_dir, 'node', node_restored,
options=[
"-j", "4",
"-T", "{0}={1}".format(
tblspace1_old_path, tblspace1_new_path),
"-T", "{0}={1}".format(
tblspace2_old_path, tblspace2_new_path)])
if self.paranoia:
pgdata = self.pgdata_content(node.data_dir)
if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir)
self.compare_pgdata(pgdata, pgdata_restored)
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_tablespace_handling_1(self):
"""
make node with tablespace A, take full backup, check that restore with
tablespace mapping of tablespace B will end with error
"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={
'max_wal_senders': '2'})
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
node.slow_start()
tblspace1_old_path = self.get_tblspace_path(node, 'tblspace1_old')
tblspace2_old_path = self.get_tblspace_path(node, 'tblspace2_old')
tblspace_new_path = self.get_tblspace_path(node, 'tblspace_new')
self.create_tblspace_in_node(
node, 'tblspace1',
tblspc_path=tblspace1_old_path)
self.backup_node(
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored'))
node_restored.cleanup()
try:
self.restore_node(
backup_dir, 'node', node_restored,
options=[
"-j", "4",
"-T", "{0}={1}".format(
tblspace2_old_path, tblspace_new_path)])
# we should die here because exception is what we expect to happen
self.assertEqual(
1, 0,
"Expecting Error because tablespace mapping is incorrect"
"\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue(
'ERROR: --tablespace-mapping option' in e.message and
'have an entry in tablespace_map file' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd))
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_tablespace_handling_2(self):
"""
make node without tablespaces, take full backup, check that restore with
tablespace mapping will end with error
"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={
'max_wal_senders': '2'})
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
node.slow_start()
tblspace1_old_path = self.get_tblspace_path(node, 'tblspace1_old')
tblspace_new_path = self.get_tblspace_path(node, 'tblspace_new')
self.backup_node(
backup_dir, 'node', node, backup_type="full",
options=["-j", "4", "--stream"])
node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored'))
node_restored.cleanup()
try:
self.restore_node(
backup_dir, 'node', node_restored,
options=[
"-j", "4",
"-T", "{0}={1}".format(
tblspace1_old_path, tblspace_new_path)])
# we should die here because exception is what we expect to happen
self.assertEqual(
1, 0,
"Expecting Error because tablespace mapping is incorrect"
"\n Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertTrue(
'ERROR: --tablespace-mapping option' in e.message and
'have an entry in tablespace_map file' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd))
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_drop_rel_during_backup_delta(self):
""""""
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,
2019-03-01 18:19:56 +02:00
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()
node.safe_psql(
"postgres",
"create table t_heap as select i"
" as id from generate_series(0,100) i")
relative_path = node.safe_psql(
"postgres",
"select pg_relation_filepath('t_heap')").rstrip()
absolute_path = os.path.join(node.data_dir, relative_path)
# FULL backup
self.backup_node(backup_dir, 'node', node, options=['--stream'])
# DELTA backup
gdb = self.backup_node(
backup_dir, 'node', node, backup_type='delta',
gdb=True, options=['--log-level-file=verbose'])
gdb.set_breakpoint('backup_files')
gdb.run_until_break()
# REMOVE file
node.safe_psql(
"postgres",
"DROP TABLE t_heap")
node.safe_psql(
"postgres",
"CHECKPOINT")
# File removed, we can proceed with backup
gdb.continue_execution_until_exit()
pgdata = self.pgdata_content(node.data_dir)
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
log_content = f.read()
self.assertTrue(
'LOG: File "{0}" is not found'.format(absolute_path) in log_content,
'File "{0}" should be deleted but it`s not'.format(absolute_path))
node.cleanup()
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
# Physical comparison
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_drop_rel_during_backup_page(self):
""""""
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,
2019-03-01 18:19:56 +02:00
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()
node.safe_psql(
"postgres",
"create table t_heap as select i"
" as id from generate_series(0,100) i")
relative_path = node.safe_psql(
"postgres",
"select pg_relation_filepath('t_heap')").rstrip()
absolute_path = os.path.join(node.data_dir, relative_path)
# FULL backup
self.backup_node(backup_dir, 'node', node, options=['--stream'])
# PAGE backup
gdb = self.backup_node(
backup_dir, 'node', node, backup_type='page',
gdb=True, options=['--log-level-file=verbose'])
gdb.set_breakpoint('backup_files')
gdb.run_until_break()
# REMOVE file
os.remove(absolute_path)
# File removed, we can proceed with backup
gdb.continue_execution_until_exit()
pgdata = self.pgdata_content(node.data_dir)
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
log_content = f.read()
self.assertTrue(
'LOG: File "{0}" is not found'.format(absolute_path) in log_content,
'File "{0}" should be deleted but it`s not'.format(absolute_path))
node.cleanup()
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
# Physical comparison
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_drop_rel_during_backup_ptrack(self):
""""""
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={
'ptrack_enable': 'on'})
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.slow_start()
node.safe_psql(
"postgres",
"create table t_heap as select i"
" as id from generate_series(0,100) i")
relative_path = node.safe_psql(
"postgres",
"select pg_relation_filepath('t_heap')").rstrip()
absolute_path = os.path.join(node.data_dir, relative_path)
# FULL backup
self.backup_node(backup_dir, 'node', node, options=['--stream'])
# PTRACK backup
gdb = self.backup_node(
backup_dir, 'node', node, backup_type='ptrack',
gdb=True, options=['--log-level-file=verbose'])
gdb.set_breakpoint('backup_files')
gdb.run_until_break()
# REMOVE file
os.remove(absolute_path)
# File removed, we can proceed with backup
gdb.continue_execution_until_exit()
pgdata = self.pgdata_content(node.data_dir)
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
log_content = f.read()
self.assertTrue(
'LOG: File "{0}" is not found'.format(absolute_path) in log_content,
'File "{0}" should be deleted but it`s not'.format(absolute_path))
node.cleanup()
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
# Physical comparison
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_persistent_slot_for_stream_backup(self):
""""""
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={
'max_wal_size': '40MB'})
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.slow_start()
node.safe_psql(
"postgres",
"SELECT pg_create_physical_replication_slot('slot_1')")
# FULL backup
self.backup_node(
backup_dir, 'node', node,
options=['--stream', '--slot=slot_1'])
# FULL backup
self.backup_node(
backup_dir, 'node', node,
options=['--stream', '--slot=slot_1'])
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_temp_slot_for_stream_backup(self):
""""""
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={
'max_wal_size': '40MB'})
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.slow_start()
2019-03-01 18:19:56 +02:00
# FULL backup
self.backup_node(
backup_dir, 'node', node,
options=['--stream', '--temp-slot'])
if self.get_version(node) < self.version_to_num('10.0'):
return unittest.skip('You need PostgreSQL >= 10 for this test')
else:
pg_receivexlog_path = self.get_bin_path('pg_receivewal')
# FULL backup
self.backup_node(
backup_dir, 'node', node,
options=['--stream', '--slot=slot_1', '--temp-slot'])
# Clean after yourself
self.del_test_dir(module_name, fname)