Skip to content

Commit 0ccc9ee

Browse files
committed
Clear PGDATA only if we find dst backup. Also show status if
dst backup is not OK.
1 parent d9c11e4 commit 0ccc9ee

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

restore.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,6 @@ do_restore(time_t backup_id,
112112
elog(LOG, "latest full backup timeline ID = %u", backup_tli);
113113
elog(LOG, "target timeline ID = %u", target_tli);
114114

115-
/*
116-
* Clear restore destination, but don't remove $PGDATA.
117-
* To remove symbolic link, get file list with "omit_symlink = false".
118-
*/
119-
if (!check)
120-
{
121-
elog(LOG, "----------------------------------------");
122-
elog(LOG, "clearing restore destination");
123-
124-
files = parray_new();
125-
dir_list_file(files, pgdata, NULL, false, false);
126-
parray_qsort(files, pgFileComparePathDesc); /* delete from leaf */
127-
128-
for (i = 0; i < parray_num(files); i++)
129-
{
130-
pgFile *file = (pgFile *) parray_get(files, i);
131-
pgFileDelete(file);
132-
}
133-
parray_walk(files, pgFileFree);
134-
parray_free(files);
135-
}
136115

137116
/* Read timeline history files from archives */
138117
timelines = readTimeLineHistory(target_tli);
@@ -151,6 +130,11 @@ do_restore(time_t backup_id,
151130
)
152131
backup_id_found = true;
153132

133+
if (backup_id == base_backup->start_time &&
134+
base_backup->status != BACKUP_STATUS_OK
135+
)
136+
elog(ERROR, "given backup %s is %s", base36enc(backup_id), status2str(base_backup->status));
137+
154138
if (base_backup->backup_mode < BACKUP_MODE_FULL ||
155139
base_backup->status != BACKUP_STATUS_OK)
156140
continue;
@@ -166,6 +150,28 @@ do_restore(time_t backup_id,
166150
base_backup_found:
167151
base_index = i;
168152

153+
/*
154+
* Clear restore destination, but don't remove $PGDATA.
155+
* To remove symbolic link, get file list with "omit_symlink = false".
156+
*/
157+
if (!check)
158+
{
159+
elog(LOG, "----------------------------------------");
160+
elog(LOG, "clearing restore destination");
161+
162+
files = parray_new();
163+
dir_list_file(files, pgdata, NULL, false, false);
164+
parray_qsort(files, pgFileComparePathDesc); /* delete from leaf */
165+
166+
for (i = 0; i < parray_num(files); i++)
167+
{
168+
pgFile *file = (pgFile *) parray_get(files, i);
169+
pgFileDelete(file);
170+
}
171+
parray_walk(files, pgFileFree);
172+
parray_free(files);
173+
}
174+
169175
print_backup_lsn(base_backup);
170176

171177
if (backup_id != 0)

0 commit comments

Comments
 (0)