Skip to content

Commit 2f8d5ef

Browse files
committed
[PBCKP-259]: Fix test_start_time for checking that backup and restore can be performed with start-time option.
Fix checking that time of new backup later, than latest existing backup
1 parent 907507a commit 2f8d5ef

File tree

3 files changed

+53
-248
lines changed

3 files changed

+53
-248
lines changed

src/pg_probackup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,8 @@ main(int argc, char *argv[])
993993
return do_catchup(catchup_source_pgdata, catchup_destination_pgdata, num_threads, !no_sync,
994994
exclude_absolute_paths_list, exclude_relative_paths_list);
995995
case RESTORE_CMD:
996+
if (start_time != INVALID_BACKUP_ID)
997+
current.backup_id = start_time;
996998
return do_restore_or_validate(instanceState, current.backup_id,
997999
recovery_target_options,
9981000
restore_params, no_sync);

tests/backup.py

Lines changed: 51 additions & 245 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,7 +3402,7 @@ def test_pg_stop_backup_missing_permissions(self):
34023402

34033403
# @unittest.skip("skip")
34043404
def test_start_time(self):
3405-
3405+
"""Test, that option --start-time allows to set backup_id and restore"""
34063406
fname = self.id().split('.')[3]
34073407
node = self.make_simple_node(
34083408
base_dir=os.path.join(module_name, fname, 'node'),
@@ -3417,85 +3417,27 @@ def test_start_time(self):
34173417
node.slow_start()
34183418

34193419
# FULL backup
3420-
startTime = int(time())
3421-
self.backup_node(
3422-
backup_dir, 'node', node, backup_type="full",
3423-
options=['--stream', '--start-time', str(startTime)])
3424-
3425-
# DELTA backup
3426-
startTime = int(time())
3427-
self.backup_node(
3428-
backup_dir, 'node', node, backup_type="delta",
3429-
options=['--stream', '--start-time', str(startTime)])
3430-
3431-
# PAGE backup
3432-
startTime = int(time())
3433-
self.backup_node(
3434-
backup_dir, 'node', node, backup_type="page",
3435-
options=['--stream', '--start-time', str(startTime)])
3436-
3437-
if self.ptrack and node.major_version > 11:
3438-
node.safe_psql(
3439-
"postgres",
3440-
"create extension ptrack")
3441-
3442-
# PTRACK backup
3443-
startTime = int(time())
3444-
self.backup_node(
3445-
backup_dir, 'node', node, backup_type="ptrack",
3446-
options=['--stream', '--start-time', str(startTime)])
3447-
3448-
# Clean after yourself
3449-
self.del_test_dir(module_name, fname)
3450-
3451-
# @unittest.skip("skip")
3452-
def test_start_time_incorrect_time(self):
3453-
3454-
fname = self.id().split('.')[3]
3455-
node = self.make_simple_node(
3456-
base_dir=os.path.join(module_name, fname, 'node'),
3457-
set_replication=True,
3458-
ptrack_enable=self.ptrack,
3459-
initdb_params=['--data-checksums'])
3460-
3461-
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
3462-
self.init_pb(backup_dir)
3463-
self.add_instance(backup_dir, 'node', node)
3464-
self.set_archiving(backup_dir, 'node', node)
3465-
node.slow_start()
3466-
3467-
startTime = int(time())
3468-
#backup with correct start time
3420+
startTime = str(int(time()))
34693421
self.backup_node(
3422+
backup_dir, 'node', node, backup_type='full',
3423+
options=['--stream', '--start-time={0}'.format(startTime)])
3424+
# restore FULL backup by the start-time
3425+
node.cleanup()
3426+
self.restore_node(
34703427
backup_dir, 'node', node,
3471-
options=['--stream', '--start-time', str(startTime)])
3472-
#backups with incorrect start time
3473-
try:
3474-
self.backup_node(
3475-
backup_dir, 'node', node, backup_type="full",
3476-
options=['--stream', '--start-time', str(startTime-10000)])
3477-
# we should die here because exception is what we expect to happen
3478-
self.assertEqual(
3479-
1, 0,
3480-
"Expecting Error because start time for new backup must be newer "
3481-
"\n Output: {0} \n CMD: {1}".format(
3482-
repr(self.output), self.cmd))
3483-
except ProbackupException as e:
3484-
self.assertRegex(
3485-
e.message,
3486-
r"ERROR: Can't assign backup_id from requested start_time \(\w*\), this time must be later that backup \w*\n",
3487-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
3488-
repr(e.message), self.cmd))
3428+
options=['--start-time={0}'.format(startTime)])
34893429

3430+
#FULL backup with incorrect start time
34903431
try:
3432+
startTime = str(int(time()-100000))
34913433
self.backup_node(
3492-
backup_dir, 'node', node, backup_type="delta",
3493-
options=['--stream', '--start-time', str(startTime-10000)])
3434+
backup_dir, 'node', node, backup_type='full',
3435+
options=['--stream', '--start-time={0}'.format(startTime)])
34943436
# we should die here because exception is what we expect to happen
34953437
self.assertEqual(
34963438
1, 0,
3497-
"Expecting Error because start time for new backup must be newer "
3498-
"\n Output: {0} \n CMD: {1}".format(
3439+
'Expecting Error because start time for new backup must be newer '
3440+
'\n Output: {0} \n CMD: {1}'.format(
34993441
repr(self.output), self.cmd))
35003442
except ProbackupException as e:
35013443
self.assertRegex(
@@ -3504,44 +3446,46 @@ def test_start_time_incorrect_time(self):
35043446
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
35053447
repr(e.message), self.cmd))
35063448

3507-
try:
3508-
self.backup_node(
3509-
backup_dir, 'node', node, backup_type="page",
3510-
options=['--stream', '--start-time', str(startTime-10000)])
3511-
# we should die here because exception is what we expect to happen
3512-
self.assertEqual(
3513-
1, 0,
3514-
"Expecting Error because start time for new backup must be newer "
3515-
"\n Output: {0} \n CMD: {1}".format(
3516-
repr(self.output), self.cmd))
3517-
except ProbackupException as e:
3518-
self.assertRegex(
3519-
e.message,
3520-
r"ERROR: Can't assign backup_id from requested start_time \(\w*\), this time must be later that backup \w*\n",
3521-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
3522-
repr(e.message), self.cmd))
3449+
# DELTA backup
3450+
node.slow_start()
3451+
startTime = str(int(time()))
3452+
self.backup_node(
3453+
backup_dir, 'node', node, backup_type='delta',
3454+
options=['--stream', '--start-time={0}'.format(startTime)])
3455+
# restore DELTA backup by the start-time
3456+
node.cleanup()
3457+
self.restore_node(
3458+
backup_dir, 'node', node,
3459+
options=['--start-time={0}'.format(startTime)])
35233460

3524-
if self.ptrack and node.major_version > 11:
3461+
# PAGE backup
3462+
node.slow_start()
3463+
startTime = str(int(time()))
3464+
self.backup_node(
3465+
backup_dir, 'node', node, backup_type='page',
3466+
options=['--stream', '--start-time={0}'.format(startTime)])
3467+
# restore PAGE backup by the start-time
3468+
node.cleanup()
3469+
self.restore_node(
3470+
backup_dir, 'node', node,
3471+
options=['--start-time={0}'.format(startTime)])
3472+
3473+
# PTRACK backup
3474+
if self.ptrack:
3475+
node.slow_start()
35253476
node.safe_psql(
3526-
"postgres",
3527-
"create extension ptrack")
3477+
'postgres',
3478+
'create extension ptrack')
35283479

3529-
try:
3530-
self.backup_node(
3531-
backup_dir, 'node', node, backup_type='ptrack',
3532-
options=['--stream', '--start-time', str(startTime-10000)])
3533-
# we should die here because exception is what we expect to happen
3534-
self.assertEqual(
3535-
1, 0,
3536-
"Expecting Error because start time for new backup must be newer "
3537-
"\n Output: {0} \n CMD: {1}".format(
3538-
repr(self.output), self.cmd))
3539-
except ProbackupException as e:
3540-
self.assertRegex(
3541-
e.message,
3542-
r"ERROR: Can't assign backup_id from requested start_time \(\w*\), this time must be later that backup \w*\n",
3543-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
3544-
repr(e.message), self.cmd))
3480+
startTime = str(int(time()))
3481+
self.backup_node(
3482+
backup_dir, 'node', node, backup_type='ptrack',
3483+
options=['--stream', '--start-time={0}'.format(startTime)])
3484+
3485+
node.cleanup()
3486+
self.restore_node(
3487+
backup_dir, 'node', node,
3488+
options=['--start-time={0}'.format(startTime)])
35453489

35463490
# Clean after yourself
35473491
self.del_test_dir(module_name, fname)
@@ -3632,141 +3576,3 @@ def test_start_time_few_nodes(self):
36323576
# Clean after yourself
36333577
self.del_test_dir(module_name, fname)
36343578

3635-
# @unittest.skip("skip")
3636-
def test_start_time_few_nodes_incorrect_time(self):
3637-
3638-
fname = self.id().split('.')[3]
3639-
node1 = self.make_simple_node(
3640-
base_dir=os.path.join(module_name, fname, 'node1'),
3641-
set_replication=True,
3642-
ptrack_enable=self.ptrack,
3643-
initdb_params=['--data-checksums'])
3644-
3645-
backup_dir1 = os.path.join(self.tmp_path, module_name, fname, 'backup1')
3646-
self.init_pb(backup_dir1)
3647-
self.add_instance(backup_dir1, 'node1', node1)
3648-
self.set_archiving(backup_dir1, 'node1', node1)
3649-
node1.slow_start()
3650-
3651-
node2 = self.make_simple_node(
3652-
base_dir=os.path.join(module_name, fname, 'node2'),
3653-
ptrack_enable=self.ptrack,
3654-
initdb_params=['--data-checksums'])
3655-
3656-
backup_dir2 = os.path.join(self.tmp_path, module_name, fname, 'backup2')
3657-
self.init_pb(backup_dir2)
3658-
self.add_instance(backup_dir2, 'node2', node2)
3659-
self.set_archiving(backup_dir2, 'node2', node2)
3660-
node2.slow_start()
3661-
3662-
# FULL backup
3663-
startTime = int(time())
3664-
self.backup_node(
3665-
backup_dir1, 'node1', node1, backup_type="full",
3666-
options=['--stream', '--start-time', str(startTime)])
3667-
self.backup_node(
3668-
backup_dir2, 'node2', node2, backup_type="full",
3669-
options=['--stream', '--start-time', str(startTime-10000)])
3670-
3671-
show_backup1 = self.show_pb(backup_dir1, 'node1')[0]
3672-
show_backup2 = self.show_pb(backup_dir2, 'node2')[0]
3673-
self.assertGreater(show_backup1['id'], show_backup2['id'])
3674-
3675-
# DELTA backup
3676-
startTime = int(time())
3677-
self.backup_node(
3678-
backup_dir1, 'node1', node1, backup_type="delta",
3679-
options=['--stream', '--start-time', str(startTime)])
3680-
# make backup with start time definitelly earlier, than existing
3681-
try:
3682-
self.backup_node(
3683-
backup_dir2, 'node2', node2, backup_type="delta",
3684-
options=['--stream', '--start-time', str(10000)])
3685-
self.assertEqual(
3686-
1, 0,
3687-
"Expecting Error because start time for new backup must be newer "
3688-
"\n Output: {0} \n CMD: {1}".format(
3689-
repr(self.output), self.cmd))
3690-
except ProbackupException as e:
3691-
self.assertIn(
3692-
"ERROR: Can't assign backup_id from requested start_time (7PS), this time must be later that backup",
3693-
e.message,
3694-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
3695-
repr(e.message), self.cmd))
3696-
3697-
show_backup1 = self.show_pb(backup_dir1, 'node1')[1]
3698-
show_backup2 = self.show_pb(backup_dir2, 'node2')[0]
3699-
self.assertGreater(show_backup1['id'], show_backup2['id'])
3700-
3701-
# PAGE backup
3702-
startTime = int(time())
3703-
self.backup_node(
3704-
backup_dir1, 'node1', node1, backup_type="page",
3705-
options=['--stream', '--start-time', str(startTime)])
3706-
# make backup with start time definitelly earlier, than existing
3707-
try:
3708-
self.backup_node(
3709-
backup_dir2, 'node2', node2, backup_type="page",
3710-
options=['--stream', '--start-time', str(10000)])
3711-
self.assertEqual(
3712-
1, 0,
3713-
"Expecting Error because start time for new backup must be newer "
3714-
"\n Output: {0} \n CMD: {1}".format(
3715-
repr(self.output), self.cmd))
3716-
except ProbackupException as e:
3717-
self.assertIn(
3718-
"ERROR: Can't assign backup_id from requested start_time (7PS), this time must be later that backup",
3719-
e.message,
3720-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
3721-
repr(e.message), self.cmd))
3722-
3723-
show_backup1 = self.show_pb(backup_dir1, 'node1')[2]
3724-
show_backup2 = self.show_pb(backup_dir2, 'node2')[0]
3725-
self.assertGreater(show_backup1['id'], show_backup2['id'])
3726-
3727-
# PTRACK backup
3728-
startTime = int(time())
3729-
if self.ptrack:
3730-
node1.safe_psql(
3731-
"postgres",
3732-
"create extension ptrack")
3733-
self.backup_node(
3734-
backup_dir1, 'node1', node1, backup_type="ptrack",
3735-
options=['--stream', '--start-time', str(startTime)])
3736-
3737-
node2.safe_psql(
3738-
"postgres",
3739-
"create extension ptrack")
3740-
# make backup with start time definitelly earlier, than existing
3741-
try:
3742-
self.backup_node(
3743-
backup_dir2, 'node2', node2, backup_type="ptrack",
3744-
options=['--stream', '--start-time', str(10000)])
3745-
self.assertEqual(
3746-
1, 0,
3747-
"Expecting Error because start time for new backup must be newer "
3748-
"\n Output: {0} \n CMD: {1}".format(
3749-
repr(self.output), self.cmd))
3750-
except ProbackupException as e:
3751-
self.assertIn(
3752-
"ERROR: Can't assign backup_id from requested start_time (7PS), this time must be later that backup",
3753-
e.message,
3754-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
3755-
repr(e.message), self.cmd))
3756-
3757-
# FULL backup
3758-
startTime = int(time())
3759-
self.backup_node(
3760-
backup_dir1, 'node1', node1, backup_type="full",
3761-
options=['--stream', '--start-time', str(startTime)])
3762-
self.backup_node(
3763-
backup_dir2, 'node2', node2, backup_type="full",
3764-
options=['--stream', '--start-time', str(startTime)])
3765-
3766-
show_backups_node1 = self.show_pb(backup_dir1, 'node1')
3767-
show_backup1 = show_backups_node1[len(show_backups_node1) - 1]
3768-
show_backup2 = self.show_pb(backup_dir2, 'node2')[1]
3769-
self.assertEqual(show_backup1['id'], show_backup2['id'])
3770-
3771-
# Clean after yourself
3772-
self.del_test_dir(module_name, fname)

tests/helpers/ptrack_helpers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,6 @@ def backup_node(
980980
if not old_binary:
981981
cmd_list += ['--no-sync']
982982

983-
if startTime:
984-
cmd_list += ['--start-time', startTime]
985-
986983
return self.run_pb(cmd_list + options, asynchronous, gdb, old_binary, return_id, env=env)
987984

988985
def checkdb_node(

0 commit comments

Comments
 (0)