@@ -42,8 +42,8 @@ static void create_recovery_conf(time_t backup_id,
4242static parray * read_timeline_history (TimeLineID targetTLI );
4343static void * restore_files (void * arg );
4444
45- static parray * get_dbOid_exclude_list (pgBackup * backup ,parray * datname_list ,
46- bool partial_restore_type );
45+ static parray * get_dbOid_exclude_list (pgBackup * backup ,parray * files ,
46+ parray * datname_list , bool partial_restore_type );
4747
4848static int pgCompareOid (const void * f1 ,const void * f2 );
4949
@@ -435,6 +435,15 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
435435dest_backup_path [MAXPGPATH ];
436436int i ;
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 */
446455if (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 ,
448457partial_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 */
11731173parray *
1174- get_dbOid_exclude_list (pgBackup * backup ,parray * datname_list ,bool partial_restore_type )
1174+ get_dbOid_exclude_list (pgBackup * backup ,parray * files ,
1175+ parray * datname_list ,bool partial_restore_type )
11751176{
11761177int i ;
11771178int j ;
11781179parray * database_map = NULL ;
11791180parray * dbOid_exclude_list = NULL ;
1181+ bool found_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 */
11821201database_map = read_database_map (backup );
11831202
11841203/* partial restore requested but database_map is missing */
11851204if (!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.