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

Commitde2a0d1

Browse files
author
Artur Zakirov
committed
Fix for9c471aa.
pgdata_exclude[] doesn't exclude files. Add pgdata_exclude_files[].
1 parent9c471aa commitde2a0d1

File tree

7 files changed

+96
-48
lines changed

7 files changed

+96
-48
lines changed

‎backup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
205205
* mkdirs.sh, then sort them in order of path. Omit $PGDATA.
206206
*/
207207
backup_files_list=parray_new();
208-
dir_list_file(backup_files_list,pgdata,NULL, false, false);
208+
dir_list_file(backup_files_list,pgdata,false, false, false);
209209

210210
if (!check)
211211
{
@@ -396,7 +396,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
396396
/* Scan backup pg_xlog dir */
397397
list_file=parray_new();
398398
join_path_components(pg_xlog_path,path,"pg_xlog");
399-
dir_list_file(list_file,pg_xlog_path,NULL, true, false);
399+
dir_list_file(list_file,pg_xlog_path,false, true, false);
400400

401401
/* Remove file path root prefix and calc meta */
402402
for (i=0;i<parray_num(list_file);i++)
@@ -1233,7 +1233,7 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
12331233
list_file=parray_new();
12341234

12351235
/* list files with the logical path. omit $PGDATA */
1236-
dir_list_file(list_file,root,pgdata_exclude, true,add_root);
1236+
dir_list_file(list_file,root,true, true,add_root);
12371237

12381238
/* mark files that are possible datafile as 'datafile' */
12391239
for (i=0;i< (int)parray_num(list_file);i++)

‎delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pgBackupDeleteFiles(pgBackup *backup)
260260
/* list files to be deleted */
261261
files=parray_new();
262262
pgBackupGetPath(backup,path,lengthof(path),NULL);
263-
dir_list_file(files,path,NULL, true, true);
263+
dir_list_file(files,path,false, true, true);
264264

265265
/* delete leaf node first */
266266
parray_qsort(files,pgFileComparePathDesc);

‎dir.c

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020
#include"datapagemap.h"
2121

2222
/* directory exclusion list for backup mode listing */
23-
constchar*pgdata_exclude[]=
23+
constchar*pgdata_exclude_dir[]=
2424
{
2525
"pg_xlog",
2626
"pg_stat_tmp",
2727
"pgsql_tmp",
28+
NULL,/* arclog_path will be set later */
29+
NULL,/* pg_log will be set later */
30+
NULL
31+
};
32+
33+
staticchar*pgdata_exclude_files[]=
34+
{
2835
"recovery.conf",
2936
"postmaster.pid",
3037
"postmaster.opts",
31-
NULL,/* arclog_path will be set later */
32-
NULL,/* pg_log will be set later */
3338
NULL
3439
};
3540

@@ -249,7 +254,8 @@ BlackListCompare(const void *str1, const void *str2)
249254
* directory llnked to will be listed.
250255
*/
251256
void
252-
dir_list_file(parray*files,constchar*root,constchar*exclude[],boolomit_symlink,booladd_root)
257+
dir_list_file(parray*files,constchar*root,boolexclude,boolomit_symlink,
258+
booladd_root)
253259
{
254260
charpath[MAXPGPATH];
255261
charbuf[MAXPGPATH*2];
@@ -288,8 +294,8 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
288294
}
289295

290296
void
291-
dir_list_file_internal(parray*files,constchar*root,constchar*exclude[],
292-
boolomit_symlink,booladd_root,parray*black_list)
297+
dir_list_file_internal(parray*files,constchar*root,boolexclude,
298+
boolomit_symlink,booladd_root,parray*black_list)
293299
{
294300
pgFile*file;
295301

@@ -305,7 +311,33 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
305311
}
306312

307313
if (add_root)
314+
{
315+
/* Skip files */
316+
if (!S_ISDIR(file->mode)&&exclude)
317+
{
318+
char*file_name;
319+
inti;
320+
321+
/* Extract file name */
322+
file_name=strrchr(file->path,'/');
323+
if (file_name==NULL)
324+
file_name=file->path;
325+
else
326+
file_name++;
327+
328+
/*
329+
* If the item in the exclude list starts with '/', compare to the
330+
* absolute path of the directory. Otherwise compare to the directory
331+
* name portion.
332+
*/
333+
for (i=0;pgdata_exclude_files[i];i++)
334+
if (strcmp(file_name,pgdata_exclude_files[i])==0)
335+
/* Skip */
336+
return;
337+
}
338+
308339
parray_append(files,file);
340+
}
309341

310342
/* chase symbolic link chain and find regular file or directory */
311343
while (S_ISLNK(file->mode))
@@ -351,45 +383,49 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
351383
*/
352384
while (S_ISDIR(file->mode))
353385
{
354-
inti;
355386
boolskip= false;
356387
DIR*dir;
357388
structdirent*dent;
358-
char*dirname;
359389

360-
/* skip entry which matches exclude list */
361-
dirname=strrchr(file->path,'/');
362-
if (dirname==NULL)
363-
dirname=file->path;
364-
else
365-
dirname++;
366-
367-
/*
368-
* If the item in the exclude list starts with '/', compare to the
369-
* absolute path of the directory. Otherwise compare to the directory
370-
* name portion.
371-
*/
372-
for (i=0;exclude&&exclude[i];i++)
390+
if (exclude)
373391
{
374-
if (exclude[i][0]=='/')
392+
inti;
393+
char*dirname;
394+
395+
/* skip entry which matches exclude list */
396+
dirname=strrchr(file->path,'/');
397+
if (dirname==NULL)
398+
dirname=file->path;
399+
else
400+
dirname++;
401+
402+
/*
403+
* If the item in the exclude list starts with '/', compare to the
404+
* absolute path of the directory. Otherwise compare to the directory
405+
* name portion.
406+
*/
407+
for (i=0;exclude&&pgdata_exclude_dir[i];i++)
375408
{
376-
if (strcmp(file->path,exclude[i])==0)
409+
if (pgdata_exclude_dir[i][0]=='/')
377410
{
378-
skip= true;
379-
break;
411+
if (strcmp(file->path,pgdata_exclude_dir[i])==0)
412+
{
413+
skip= true;
414+
break;
415+
}
380416
}
381-
}
382-
else
383-
{
384-
if (strcmp(dirname,exclude[i])==0)
417+
else
385418
{
386-
skip= true;
387-
break;
419+
if (strcmp(dirname,pgdata_exclude_dir[i])==0)
420+
{
421+
skip= true;
422+
break;
423+
}
388424
}
389425
}
426+
if (skip)
427+
break;
390428
}
391-
if (skip)
392-
break;
393429

394430
/* open directory and list contents */
395431
dir=opendir(file->path);
@@ -636,7 +672,7 @@ dir_copy_files(const char *from_root, const char *to_root)
636672
parray*files=parray_new();
637673

638674
/* don't copy root directory */
639-
dir_list_file(files,from_root,NULL, true, false);
675+
dir_list_file(files,from_root,false, true, false);
640676

641677
for (i=0;i<parray_num(files);i++)
642678
{

‎pg_probackup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ main(int argc, char *argv[])
174174
join_path_components(arclog_path,backup_path,"wal");
175175

176176
/* setup exclusion list for file search */
177-
for (i=0;pgdata_exclude[i];i++);/* find first empty slot */
177+
for (i=0;pgdata_exclude_dir[i];i++);/* find first empty slot */
178178

179-
pgdata_exclude[i++]=arclog_path;
179+
pgdata_exclude_dir[i++]=arclog_path;
180180

181181
if(!backup_logs)
182-
pgdata_exclude[i++]="pg_log";
182+
pgdata_exclude_dir[i++]="pg_log";
183183

184184
if (target_time!=NULL&&target_xid!=NULL)
185185
elog(ERROR,"You can't specify recovery-target-time and recovery-target-xid at the same time");

‎pg_probackup.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extern bool check;
192192
externpgBackupcurrent;
193193

194194
/* exclude directory list for $PGDATA file listing */
195-
externconstchar*pgdata_exclude[];
195+
externconstchar*pgdata_exclude_dir[];
196196

197197
/* backup file list from non-snapshot */
198198
externparray*backup_files_list;
@@ -284,9 +284,10 @@ extern int pgBackupCompareId(const void *f1, const void *f2);
284284
externintpgBackupCompareIdDesc(constvoid*f1,constvoid*f2);
285285

286286
/* in dir.c */
287-
externvoiddir_list_file(parray*files,constchar*root,constchar*exclude[],boolomit_symlink,booladd_root);
288-
externvoiddir_list_file_internal(parray*files,constchar*root,constchar*exclude[],
289-
boolomit_symlink,booladd_root,parray*black_list);
287+
externvoiddir_list_file(parray*files,constchar*root,boolexclude,
288+
boolomit_symlink,booladd_root);
289+
externvoiddir_list_file_internal(parray*files,constchar*root,boolexclude,
290+
boolomit_symlink,booladd_root,parray*black_list);
290291
externvoiddir_print_mkdirs_sh(FILE*out,constparray*files,constchar*root);
291292
externvoiddir_print_file_list(FILE*out,constparray*files,constchar*root,constchar*prefix);
292293
externparray*dir_read_file_list(constchar*root,constchar*file_txt);

‎restore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ do_restore(time_t backup_id,
160160
elog(LOG,"clearing restore destination");
161161

162162
files=parray_new();
163-
dir_list_file(files,pgdata,NULL, false, false);
163+
dir_list_file(files,pgdata,false, false, false);
164164
parray_qsort(files,pgFileComparePathDesc);/* delete from leaf */
165165

166166
for (i=0;i<parray_num(files);i++)
@@ -364,7 +364,7 @@ restore_database(pgBackup *backup)
364364

365365
/* get list of files restored to pgdata */
366366
files_now=parray_new();
367-
dir_list_file(files_now,pgdata,pgdata_exclude, true, false);
367+
dir_list_file(files_now,pgdata,true, true, false);
368368
/* to delete from leaf, sort in reversed order */
369369
parray_qsort(files_now,pgFileComparePathDesc);
370370

‎tests/backup_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
importunittest
2-
fromosimportpath
2+
fromosimportpath,listdir
33
importsix
44
from .pb_libimportProbackupTest
55
fromtestgresimportstop_all
@@ -35,6 +35,17 @@ def test_backup_modes_1(self):
3535
self.assertEqual(show_backup.status,six.b("OK"))
3636
self.assertEqual(show_backup.mode,six.b("FULL"))
3737

38+
# postmaster.pid and postmaster.opts shouldn't be copied
39+
excluded=True
40+
backups_dir=path.join(self.backup_dir(node),"backups")
41+
forbackupinlistdir(backups_dir):
42+
db_dir=path.join(backups_dir,backup,"database")
43+
forfinlistdir(db_dir):
44+
ifpath.isfile(path.join(db_dir,f))and \
45+
(f=="postmaster.pid"orf=="postmaster.opts"):
46+
excluded=False
47+
self.assertEqual(excluded,True)
48+
3849
# page backup mode
3950
withopen(path.join(node.logs_dir,"backup_page.log"),"wb")asbackup_log:
4051
backup_log.write(self.backup_pb(node,backup_type="page",options=["--verbose"]))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp