@@ -121,6 +121,18 @@ static long long int total_checksum_failures;
121
121
/* Do not verify checksums. */
122
122
static bool noverify_checksums = false;
123
123
124
+ /*
125
+ * Definition of one element part of an exclusion list, used for paths part
126
+ * of checksum validation or base backups. "name" is the name of the file
127
+ * or path to check for exclusion. If "match_prefix" is true, any items
128
+ * matching the name as prefix are excluded.
129
+ */
130
+ struct exclude_list_item
131
+ {
132
+ const char * name ;
133
+ bool match_prefix ;
134
+ };
135
+
124
136
/*
125
137
* The contents of these directories are removed or recreated during server
126
138
* start so they are not included in backups. The directories themselves are
@@ -170,31 +182,34 @@ static const char *const excludeDirContents[] =
170
182
/*
171
183
* List of files excluded from backups.
172
184
*/
173
- static const char * const excludeFiles [] =
185
+ static const struct exclude_list_item excludeFiles [] =
174
186
{
175
187
/* Skip auto conf temporary file. */
176
- PG_AUTOCONF_FILENAME ".tmp" ,
188
+ { PG_AUTOCONF_FILENAME ".tmp" , false} ,
177
189
178
190
/* Skip current log file temporary file */
179
- LOG_METAINFO_DATAFILE_TMP ,
191
+ { LOG_METAINFO_DATAFILE_TMP , false} ,
180
192
181
- /* Skip relation cache because it is rebuilt on startup */
182
- RELCACHE_INIT_FILENAME ,
193
+ /*
194
+ * Skip relation cache because it is rebuilt on startup. This includes
195
+ * temporary files.
196
+ */
197
+ {RELCACHE_INIT_FILENAME , true},
183
198
184
199
/*
185
200
* If there's a backup_label or tablespace_map file, it belongs to a
186
201
* backup started by the user with pg_start_backup(). It is *not* correct
187
202
* for this backup. Our backup_label/tablespace_map is injected into the
188
203
* tar separately.
189
204
*/
190
- BACKUP_LABEL_FILE ,
191
- TABLESPACE_MAP ,
205
+ { BACKUP_LABEL_FILE , false} ,
206
+ { TABLESPACE_MAP , false} ,
192
207
193
- "postmaster.pid" ,
194
- "postmaster.opts" ,
208
+ { "postmaster.pid" , false} ,
209
+ { "postmaster.opts" , false} ,
195
210
196
211
/* end of list */
197
- NULL
212
+ { NULL , false}
198
213
};
199
214
200
215
/*
@@ -203,16 +218,15 @@ static const char *const excludeFiles[] =
203
218
* Note: this list should be kept in sync with what pg_checksums.c
204
219
* includes.
205
220
*/
206
- static const char * const noChecksumFiles [] = {
207
- "pg_control" ,
208
- "pg_filenode.map" ,
209
- "pg_internal.init" ,
210
- "PG_VERSION" ,
221
+ static const struct exclude_list_item noChecksumFiles [] = {
222
+ { "pg_control" , false} ,
223
+ { "pg_filenode.map" , false} ,
224
+ { "pg_internal.init" , true} ,
225
+ { "PG_VERSION" , false} ,
211
226
#ifdef EXEC_BACKEND
212
- "config_exec_params" ,
213
- "config_exec_params.new" ,
227
+ {"config_exec_params" , true},
214
228
#endif
215
- NULL ,
229
+ { NULL , false}
216
230
};
217
231
218
232
/*
@@ -1082,9 +1096,13 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
1082
1096
1083
1097
/* Scan for files that should be excluded */
1084
1098
excludeFound = false;
1085
- for (excludeIdx = 0 ; excludeFiles [excludeIdx ] != NULL ; excludeIdx ++ )
1099
+ for (excludeIdx = 0 ; excludeFiles [excludeIdx ]. name != NULL ; excludeIdx ++ )
1086
1100
{
1087
- if (strcmp (de -> d_name , excludeFiles [excludeIdx ]) == 0 )
1101
+ int cmplen = strlen (excludeFiles [excludeIdx ].name );
1102
+
1103
+ if (!excludeFiles [excludeIdx ].match_prefix )
1104
+ cmplen ++ ;
1105
+ if (strncmp (de -> d_name , excludeFiles [excludeIdx ].name , cmplen ) == 0 )
1088
1106
{
1089
1107
elog (DEBUG1 , "file \"%s\" excluded from backup" , de -> d_name );
1090
1108
excludeFound = true;
@@ -1317,17 +1335,24 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
1317
1335
static bool
1318
1336
is_checksummed_file (const char * fullpath , const char * filename )
1319
1337
{
1320
- const char * const * f ;
1321
-
1322
1338
/* Check that the file is in a tablespace */
1323
1339
if (strncmp (fullpath , "./global/" , 9 ) == 0 ||
1324
1340
strncmp (fullpath , "./base/" , 7 ) == 0 ||
1325
1341
strncmp (fullpath , "/" , 1 ) == 0 )
1326
1342
{
1327
- /* Compare file against noChecksumFiles skiplist */
1328
- for (f = noChecksumFiles ; * f ; f ++ )
1329
- if (strcmp (* f , filename ) == 0 )
1343
+ int excludeIdx ;
1344
+
1345
+ /* Compare file against noChecksumFiles skip list */
1346
+ for (excludeIdx = 0 ; noChecksumFiles [excludeIdx ].name != NULL ; excludeIdx ++ )
1347
+ {
1348
+ int cmplen = strlen (noChecksumFiles [excludeIdx ].name );
1349
+
1350
+ if (!noChecksumFiles [excludeIdx ].match_prefix )
1351
+ cmplen ++ ;
1352
+ if (strncmp (filename , noChecksumFiles [excludeIdx ].name ,
1353
+ cmplen ) == 0 )
1330
1354
return false;
1355
+ }
1331
1356
1332
1357
return true;
1333
1358
}
0 commit comments