Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06805ea

Browse files
committed
[Issue 79] be more paranoid about missing or mangled database_map
1 parentcb37bf8 commit06805ea

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

‎src/backup.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ pg_ptrack_support(PGconn *backup_conn)
10721072

10731073
/*
10741074
* Create 'datname to Oid' map
1075+
* Return NULL if failed to construct database_map
10751076
*/
10761077
parray*
10771078
get_database_map(PGconn*conn)
@@ -1080,10 +1081,10 @@ get_database_map(PGconn *conn)
10801081
parray*database_map=NULL;
10811082
inti;
10821083

1083-
res=pgut_execute(conn,
1084+
res=pgut_execute_extended(conn,
10841085
"SELECT oid, datname FROM pg_catalog.pg_database "
10851086
"WHERE datname NOT IN ('template1', 'template0')",
1086-
0,NULL);
1087+
0,NULL, true, true);
10871088

10881089
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
10891090
{
@@ -1114,6 +1115,14 @@ get_database_map(PGconn *conn)
11141115
parray_append(database_map,db_entry);
11151116
}
11161117

1118+
/* extra paranoia */
1119+
if (database_map&& (parray_num(database_map)==0))
1120+
{
1121+
parray_free(database_map);
1122+
elog(WARNING,"Failed to get database map");
1123+
returnNULL;
1124+
}
1125+
11171126
returndatabase_map;
11181127
}
11191128

‎src/dir.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,18 +1779,11 @@ read_database_map(pgBackup *backup)
17791779
fp=fio_open_stream(database_map_path,FIO_BACKUP_HOST);
17801780
if (fp==NULL)
17811781
{
1782-
/* It is NOT ok for database_map to be missing at this point
1783-
* But at this point we are sure that partial restore is requested,
1784-
* so we error here if database_map is missing.
1782+
/* It is NOT ok for database_map to be missing at this point, so
1783+
* we should error here.
17851784
* It`s a job of the caller to error if database_map is not empty.
17861785
*/
1787-
if (errno==ENOENT)
1788-
{
1789-
elog(ERROR,"Backup %s has missing database_map: \"%s\"",
1790-
base36enc(backup->start_time),database_map_path);
1791-
}
1792-
else
1793-
elog(ERROR,"Cannot open \"%s\": %s",database_map_path,strerror(errno));
1786+
elog(ERROR,"Cannot open \"%s\": %s",database_map_path,strerror(errno));
17941787
}
17951788

17961789
database_map=parray_new();

‎src/restore.c‎

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static void create_recovery_conf(time_t backup_id,
4242
staticparray*read_timeline_history(TimeLineIDtargetTLI);
4343
staticvoid*restore_files(void*arg);
4444

45-
staticparray*get_dbOid_exclude_list(pgBackup*backup,parray*datname_list,
46-
boolpartial_restore_type);
45+
staticparray*get_dbOid_exclude_list(pgBackup*backup,parray*files,
46+
parray*datname_list,boolpartial_restore_type);
4747

4848
staticintpgCompareOid(constvoid*f1,constvoid*f2);
4949

@@ -435,6 +435,15 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
435435
dest_backup_path[MAXPGPATH];
436436
inti;
437437

438+
/*
439+
* Preparations for actual restoring.
440+
*/
441+
pgBackupGetPath(dest_backup,control_file,lengthof(control_file),
442+
DATABASE_FILE_LIST);
443+
dest_files=dir_read_file_list(NULL,NULL,control_file,
444+
FIO_BACKUP_HOST);
445+
parray_qsort(dest_files,pgFileCompareRelPathWithExternal);
446+
438447
/*
439448
* Get a list of dbOids to skip if user requested the partial restore.
440449
* It is important that we do this after(!) validation so
@@ -444,18 +453,9 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
444453
* partial restore, it`s OK
445454
*/
446455
if (datname_list)
447-
dbOid_exclude_list=get_dbOid_exclude_list(dest_backup,datname_list,
456+
dbOid_exclude_list=get_dbOid_exclude_list(dest_backup,dest_files,datname_list,
448457
partial_restore_type);
449458

450-
/*
451-
* Preparations for actual restoring.
452-
*/
453-
pgBackupGetPath(dest_backup,control_file,lengthof(control_file),
454-
DATABASE_FILE_LIST);
455-
dest_files=dir_read_file_list(NULL,NULL,control_file,
456-
FIO_BACKUP_HOST);
457-
parray_qsort(dest_files,pgFileCompareRelPathWithExternal);
458-
459459
/*
460460
* Restore dest_backup internal directories.
461461
*/
@@ -1171,19 +1171,39 @@ parseRecoveryTargetOptions(const char *target_time,
11711171
* we always convert it into exclude_list.
11721172
*/
11731173
parray*
1174-
get_dbOid_exclude_list(pgBackup*backup,parray*datname_list,boolpartial_restore_type)
1174+
get_dbOid_exclude_list(pgBackup*backup,parray*files,
1175+
parray*datname_list,boolpartial_restore_type)
11751176
{
11761177
inti;
11771178
intj;
11781179
parray*database_map=NULL;
11791180
parray*dbOid_exclude_list=NULL;
1181+
boolfound_database_map= false;
1182+
1183+
/* make sure that database_map is in backup_content.control */
1184+
for (i=0;i<parray_num(files);i++)
1185+
{
1186+
pgFile*file= (pgFile*)parray_get(files,i);
1187+
1188+
if ((file->external_dir_num==0)&&
1189+
strcmp(DATABASE_MAP,file->rel_path)==0)
1190+
{
1191+
found_database_map= true;
1192+
break;
1193+
}
1194+
}
1195+
1196+
if (!found_database_map)
1197+
elog(ERROR,"Backup %s has missing database_map, partial restore is impossible.",
1198+
base36enc(backup->start_time));
11801199

11811200
/* get database_map from file */
11821201
database_map=read_database_map(backup);
11831202

11841203
/* partial restore requested but database_map is missing */
11851204
if (!database_map)
1186-
elog(ERROR,"Backup %s has empty or mangled database_map",base36enc(backup->start_time));
1205+
elog(ERROR,"Backup %s has empty or mangled database_map, partial restore is impossible.",
1206+
base36enc(backup->start_time));
11871207

11881208
/* So we have list of datnames and database_map for it.
11891209
* We must construct a list of dbOids to exclude.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp