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

541 lines
18 KiB
Python
Raw Normal View History

import os
2017-06-27 11:43:45 +02:00
import unittest
2018-01-28 03:36:27 +02:00
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
2017-07-12 16:28:28 +02:00
module_name = 'show'
2017-07-12 16:28:28 +02:00
class OptionTest(ProbackupTest, unittest.TestCase):
2017-05-03 13:14:48 +02:00
# @unittest.skip("skip")
# @unittest.expectedFailure
2017-06-20 12:57:23 +02:00
def test_show_1(self):
2017-05-03 13:14:48 +02:00
"""Status DONE and OK"""
fname = self.id().split('.')[3]
2017-07-12 16:28:28 +02:00
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2018-01-28 03:36:27 +02:00
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'])
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
self.assertEqual(
2018-01-28 03:36:27 +02:00
self.backup_node(
backup_dir, 'node', node,
2018-09-06 19:46:32 +02:00
options=["--log-level-console=off"]),
2017-05-03 13:14:48 +02:00
None
)
2017-06-27 07:42:52 +02:00
self.assertIn("OK", self.show_pb(backup_dir, 'node', as_text=True))
# 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
2018-06-02 19:35:37 +02:00
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_show_json(self):
"""Status DONE and OK"""
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'),
2019-04-22 19:52:00 +02:00
initdb_params=['--data-checksums'])
2018-06-02 19:35:37 +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()
2018-06-02 19:35:37 +02:00
self.assertEqual(
self.backup_node(
backup_dir, 'node', node,
2018-09-06 19:46:32 +02:00
options=["--log-level-console=off"]),
2018-06-02 19:35:37 +02:00
None
)
self.backup_node(backup_dir, 'node', node)
self.assertIn("OK", self.show_pb(backup_dir, 'node', as_text=True))
# Clean after yourself
self.del_test_dir(module_name, fname)
2017-06-20 12:57:23 +02:00
# @unittest.skip("skip")
2017-05-03 13:14:48 +02:00
def test_corrupt_2(self):
"""Status CORRUPT"""
fname = self.id().split('.')[3]
2017-07-12 16:28:28 +02:00
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2018-01-28 03:36:27 +02:00
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'])
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)
# delete file which belong to backup
2018-01-28 03:36:27 +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
2018-01-28 03:36:27 +02:00
try:
self.validate_pb(backup_dir, 'node', backup_id)
# we should die here because exception is what we expect to happen
self.assertEqual(
1, 0,
2019-05-01 01:32:16 +02:00
"Expecting Error because backup corrupted."
2018-01-28 03:36:27 +02:00
" Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd
)
)
except ProbackupException as e:
self.assertIn(
2019-05-01 01:32:16 +02:00
'data files are corrupted',
2018-01-28 03:36:27 +02:00
e.message,
'\n Unexpected Error Message: {0}\n'
' CMD: {1}'.format(repr(e.message), self.cmd)
)
2017-06-27 07:42:52 +02:00
self.assertIn("CORRUPT", self.show_pb(backup_dir, as_text=True))
# Clean after yourself
2017-07-12 16:28:28 +02:00
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_no_control_file(self):
"""backup.control doesn't exist"""
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'),
2019-04-22 19:52:00 +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)
2018-12-25 16:48:49 +02:00
node.slow_start()
backup_id = self.backup_node(backup_dir, 'node', node)
# delete backup.control file
file = os.path.join(
backup_dir, "backups", "node",
backup_id, "backup.control")
os.remove(file)
2019-05-01 01:32:16 +02:00
output = self.show_pb(backup_dir, 'node', as_text=True, as_json=False)
self.assertIn(
'Control file',
output)
self.assertIn(
2019-05-01 01:32:16 +02:00
'doesn\'t exist',
output)
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_empty_control_file(self):
"""backup.control is empty"""
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'),
2019-04-22 19:52:00 +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)
2018-12-25 16:48:49 +02:00
node.slow_start()
backup_id = self.backup_node(backup_dir, 'node', node)
# truncate backup.control file
file = os.path.join(
backup_dir, "backups", "node",
backup_id, "backup.control")
fd = open(file, 'w')
fd.close()
2019-05-01 01:32:16 +02:00
output = self.show_pb(backup_dir, 'node', as_text=True, as_json=False)
self.assertIn(
'Control file',
output)
self.assertIn(
2019-05-01 01:32:16 +02:00
'is empty',
output)
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_corrupt_control_file(self):
"""backup.control contains invalid option"""
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'),
2019-04-22 19:52:00 +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)
2018-12-25 16:48:49 +02:00
node.slow_start()
backup_id = self.backup_node(backup_dir, 'node', node)
# corrupt backup.control file
file = os.path.join(
backup_dir, "backups", "node",
backup_id, "backup.control")
fd = open(file, 'a')
fd.write("statuss = OK")
fd.close()
2018-11-28 20:19:10 +02:00
self.assertIn(
2019-05-01 01:32:16 +02:00
'WARNING: Invalid option "statuss" in file',
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")
# @unittest.expectedFailure
def test_corrupt_correctness(self):
"""backup.control contains invalid option"""
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'),
initdb_params=['--data-checksums'],
pg_options={'autovacuum': 'off'})
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=1)
# FULL
backup_local_id = self.backup_node(
2019-10-09 12:23:14 +02:00
backup_dir, 'node', node, no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(backup_dir, 'node', node)
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node,
options=['--remote-proto=ssh', '--remote-host=localhost'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# DELTA
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
backup_type='delta', no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
self.delete_pb(backup_dir, 'node', backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='delta')
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='delta',
options=['--remote-proto=ssh', '--remote-host=localhost'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
self.delete_pb(backup_dir, 'node', backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# PAGE
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
backup_type='page', no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
self.delete_pb(backup_dir, 'node', backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='page')
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='page',
options=['--remote-proto=ssh', '--remote-host=localhost'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
self.delete_pb(backup_dir, 'node', backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_corrupt_correctness_1(self):
"""backup.control contains invalid option"""
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'),
initdb_params=['--data-checksums'],
pg_options={'autovacuum': 'off'})
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=1)
# FULL
backup_local_id = self.backup_node(
2019-10-09 12:23:14 +02:00
backup_dir, 'node', node, no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(backup_dir, 'node', node)
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node,
options=['--remote-proto=ssh', '--remote-host=localhost'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# change data
pgbench = node.pgbench(options=['-T', '10', '--no-vacuum'])
pgbench.wait()
# DELTA
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
backup_type='delta', no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
self.delete_pb(backup_dir, 'node', backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='delta')
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='delta',
options=['--remote-proto=ssh', '--remote-host=localhost'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
self.delete_pb(backup_dir, 'node', backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# PAGE
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
backup_type='page', no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
self.delete_pb(backup_dir, 'node', backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='page')
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='page',
options=['--remote-proto=ssh', '--remote-host=localhost'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
self.delete_pb(backup_dir, 'node', backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_corrupt_correctness_2(self):
"""backup.control contains invalid option"""
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'),
initdb_params=['--data-checksums'],
pg_options={'autovacuum': 'off'})
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=1)
# FULL
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
options=['--compress'], no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, options=['--compress'])
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node,
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# change data
pgbench = node.pgbench(options=['-T', '10', '--no-vacuum'])
pgbench.wait()
# DELTA
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
backup_type='delta', options=['--compress'], no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
self.delete_pb(backup_dir, 'node', backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='delta', options=['--compress'])
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='delta',
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
self.delete_pb(backup_dir, 'node', backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# PAGE
backup_local_id = self.backup_node(
backup_dir, 'node', node,
2019-10-09 12:23:14 +02:00
backup_type='page', options=['--compress'], no_remote=True)
output_local = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
self.delete_pb(backup_dir, 'node', backup_local_id)
2019-10-09 12:23:14 +02:00
if self.remote:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='page', options=['--compress'])
else:
backup_remote_id = self.backup_node(
backup_dir, 'node', node, backup_type='page',
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
output_remote = self.show_pb(
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
self.delete_pb(backup_dir, 'node', backup_remote_id)
# check correctness
self.assertEqual(
output_local['data-bytes'],
output_remote['data-bytes'])
self.assertEqual(
output_local['uncompressed-bytes'],
output_remote['uncompressed-bytes'])
# Clean after yourself
self.del_test_dir(module_name, fname)