@@ -436,7 +436,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
436436int i ;
437437
438438/*
439- * Get a list ofdbOid`s to skip if user requested the partial restore.
439+ * Get a list ofdbOids to skip if user requested the partial restore.
440440 * It is important that we do this after(!) validation so
441441 * database_map can be trusted.
442442 * NOTE: database_map could be missing for legal reasons, e.g. missing
@@ -692,11 +692,32 @@ restore_files(void *arg)
692692if (interrupted || thread_interrupted )
693693elog (ERROR ,"Interrupted during restore database" );
694694
695+ /* Directories were created before */
696+ if (S_ISDIR (file -> mode ))
697+ continue ;
698+
695699if (progress )
696700elog (INFO ,"Progress: (%d/%lu). Process file %s " ,
697701i + 1 , (unsigned long )parray_num (arguments -> files ),
698702file -> rel_path );
699703
704+ /* only files from pgdata can be skipped by partial restore */
705+ if (arguments -> dbOid_exclude_list &&
706+ file -> external_dir_num == 0 )
707+ {
708+ /* exclude map is not empty */
709+ if (parray_bsearch (arguments -> dbOid_exclude_list ,
710+ & file -> dbOid ,pgCompareOid ))
711+ {
712+ /* got a match, destination file will truncated */
713+ create_empty_file (FIO_BACKUP_HOST ,
714+ instance_config .pgdata ,FIO_DB_HOST ,file );
715+
716+ elog (VERBOSE ,"Exclude file due to partial restore: \"%s\"" ,file -> rel_path );
717+ continue ;
718+ }
719+ }
720+
700721/*
701722 * For PAGE and PTRACK backups skip datafiles which haven't changed
702723 * since previous backup and thus were not backed up.
@@ -717,10 +738,6 @@ restore_files(void *arg)
717738}
718739}
719740
720- /* Directories were created before */
721- if (S_ISDIR (file -> mode ))
722- continue ;
723-
724741/* Do not restore tablespace_map file */
725742if (path_is_prefix_of_path (PG_TABLESPACE_MAP_FILE ,file -> rel_path ))
726743{
@@ -729,7 +746,8 @@ restore_files(void *arg)
729746}
730747
731748/* Do not restore database_map file */
732- if (path_is_prefix_of_path (DATABASE_MAP ,file -> rel_path ))
749+ if ((file -> external_dir_num == 0 )&&
750+ strcmp (DATABASE_MAP ,file -> rel_path )== 0 )
733751{
734752elog (VERBOSE ,"Skip database_map" );
735753continue ;
@@ -744,22 +762,6 @@ restore_files(void *arg)
744762pgFileCompareRelPathWithExternal )== NULL )
745763continue ;
746764
747- /* only files from pgdata can be skipped by partial restore */
748- if (arguments -> dbOid_exclude_list && !file -> external_dir_num )
749- {
750- /* exclude map is not empty */
751- if (parray_bsearch (arguments -> dbOid_exclude_list ,
752- & file -> dbOid ,pgCompareOid ))
753- {
754- /* got a match, destination file will truncated */
755- create_empty_file (FIO_BACKUP_HOST ,
756- instance_config .pgdata ,FIO_DB_HOST ,file );
757-
758- elog (VERBOSE ,"Exclude file due to partial restore: \"%s\"" ,file -> rel_path );
759- continue ;
760- }
761- }
762-
763765/*
764766 * restore the file.
765767 * We treat datafiles separately, cause they were backed up block by
@@ -1164,27 +1166,27 @@ parseRecoveryTargetOptions(const char *target_time,
11641166return rt ;
11651167}
11661168
1167- /* ReturndbOid array of databases that should not be restored
1168- * Regardless of whatoptions user used, db-include or db-exclude,
1169- * we convert it into exclude_list.
1169+ /* Return array of dbOids of databases that should not be restored
1170+ * Regardless of whatoption user used, db-include or db-exclude,
1171+ * wealways convert it into exclude_list.
11701172 */
11711173parray *
11721174get_dbOid_exclude_list (pgBackup * backup ,parray * datname_list ,bool partial_restore_type )
11731175{
11741176int i ;
11751177int j ;
11761178parray * database_map = NULL ;
1177- parray * dbOid_exclude_list = NULL ;
1179+ parray * dbOid_exclude_list = NULL ;
11781180
11791181/* get database_map from file */
11801182database_map = read_database_map (backup );
11811183
11821184/* partial restore requested but database_map is missing */
11831185if (!database_map )
1184- elog (ERROR ,"Backup %s has empty database_map" ,base36enc (backup -> start_time ));
1186+ elog (ERROR ,"Backup %s has emptyor mangled database_map" ,base36enc (backup -> start_time ));
11851187
1186- /* So we havedb-include listand database list for it.
1187- * We mustform up a list ofdatabases to exclude
1188+ /* So we have listof datnames and database_map for it.
1189+ * We mustconstruct a list ofdbOids to exclude.
11881190 */
11891191if (partial_restore_type )
11901192{
@@ -1263,7 +1265,7 @@ get_dbOid_exclude_list(pgBackup *backup, parray *datname_list, bool partial_rest
12631265return dbOid_exclude_list ;
12641266}
12651267
1266- /* Compare twoOid */
1268+ /* Compare twoOids */
12671269int
12681270pgCompareOid (const void * f1 ,const void * f2 )
12691271{