Skip to content

Commit d624863

Browse files
committed
[Issue #290] check WAL archive directory presence at the start of backup
1 parent 4edc9d9 commit d624863

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/backup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,19 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
257257

258258
/* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
259259
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE || !stream_wal)
260+
{
261+
/* Check that archive_dir can be reached */
262+
if (fio_access(arclog_path, F_OK, FIO_BACKUP_HOST) != 0)
263+
elog(ERROR, "WAL archive directory is not accessible \"%s\": %s",
264+
arclog_path, strerror(errno));
265+
260266
/*
261267
* Do not wait start_lsn for stream backup.
262268
* Because WAL streaming will start after pg_start_backup() in stream
263269
* mode.
264270
*/
265271
wait_wal_lsn(current.start_lsn, true, current.tli, false, true, ERROR, false);
272+
}
266273

267274
/* start stream replication */
268275
if (stream_wal)

tests/backup.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,10 +2872,6 @@ def test_issue_289(self):
28722872
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
28732873
self.init_pb(backup_dir)
28742874
self.add_instance(backup_dir, 'node', node)
2875-
# self.set_archiving(backup_dir, 'node', node)
2876-
2877-
# os.rmdir(
2878-
# os.path.join(backup_dir, "wal", "node"))
28792875

28802876
node.slow_start()
28812877

@@ -2905,7 +2901,54 @@ def test_issue_289(self):
29052901
self.assertEqual(
29062902
self.show_pb(backup_dir, 'node')[0]['status'], "ERROR")
29072903

2908-
exit(1)
2904+
# Clean after yourself
2905+
self.del_test_dir(module_name, fname)
2906+
2907+
# @unittest.skip("skip")
2908+
def test_issue_290(self):
2909+
"""
2910+
https://github.com/postgrespro/pg_probackup/issues/290
2911+
"""
2912+
fname = self.id().split('.')[3]
2913+
node = self.make_simple_node(
2914+
base_dir=os.path.join(module_name, fname, 'node'),
2915+
initdb_params=['--data-checksums'])
2916+
2917+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2918+
self.init_pb(backup_dir)
2919+
self.add_instance(backup_dir, 'node', node)
2920+
self.set_archiving(backup_dir, 'node', node)
2921+
2922+
os.rmdir(
2923+
os.path.join(backup_dir, "wal", "node"))
2924+
2925+
node.slow_start()
2926+
2927+
try:
2928+
self.backup_node(
2929+
backup_dir, 'node', node,
2930+
options=['--archive-timeout=10s'])
2931+
# we should die here because exception is what we expect to happen
2932+
self.assertEqual(
2933+
1, 0,
2934+
"Expecting Error because full backup is missing"
2935+
"\n Output: {0} \n CMD: {1}".format(
2936+
repr(self.output), self.cmd))
2937+
except ProbackupException as e:
2938+
self.assertNotIn(
2939+
"INFO: Wait for WAL segment",
2940+
e.message,
2941+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
2942+
repr(e.message), self.cmd))
2943+
2944+
self.assertIn(
2945+
"WAL archive directory is not accessible",
2946+
e.message,
2947+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
2948+
repr(e.message), self.cmd))
2949+
2950+
self.assertEqual(
2951+
self.show_pb(backup_dir, 'node')[0]['status'], "ERROR")
29092952

29102953
# Clean after yourself
29112954
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)