Skip to content

Commit 70b9e15

Browse files
committed
[Issue #205] now fio_dir_list honors the "--backup-pg-log" flag and correctly handles exclusive backups
1 parent 81a13b8 commit 70b9e15

File tree

10 files changed

+53
-49
lines changed

10 files changed

+53
-49
lines changed

src/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ setup_push_filelist(const char *archive_status_dir, const char *first_file,
944944

945945
/* get list of files from archive_status */
946946
status_files = parray_new();
947-
dir_list_file(status_files, archive_status_dir, false, false, false, 0, FIO_DB_HOST);
947+
dir_list_file(status_files, archive_status_dir, false, false, false, false, 0, FIO_DB_HOST);
948948
parray_qsort(status_files, pgFileCompareName);
949949

950950
for (i = 0; i < parray_num(status_files); i++)

src/backup.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void backup_cleanup(bool fatal, void *userdata);
8080

8181
static void *backup_files(void *arg);
8282

83-
static void do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync);
83+
static void do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool backup_logs);
8484

8585
static void pg_start_backup(const char *label, bool smooth, pgBackup *backup,
8686
PGNodeInfo *nodeInfo, PGconn *backup_conn, PGconn *master_conn);
@@ -129,7 +129,7 @@ backup_stopbackup_callback(bool fatal, void *userdata)
129129
* Move files from 'pgdata' to a subdirectory in 'backup_path'.
130130
*/
131131
static void
132-
do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
132+
do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool backup_logs)
133133
{
134134
int i;
135135
char database_path[MAXPGPATH];
@@ -333,10 +333,10 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
333333
/* list files with the logical path. omit $PGDATA */
334334
if (fio_is_remote(FIO_DB_HOST))
335335
fio_list_dir(backup_files_list, instance_config.pgdata,
336-
true, true, false, 0);
336+
true, true, false, backup_logs, 0);
337337
else
338338
dir_list_file(backup_files_list, instance_config.pgdata,
339-
true, true, false, 0, FIO_LOCAL_HOST);
339+
true, true, false, backup_logs, 0, FIO_LOCAL_HOST);
340340

341341
/*
342342
* Get database_map (name to oid) for use in partial restore feature.
@@ -356,10 +356,10 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
356356
* 0 value is not external dir */
357357
if (fio_is_remote(FIO_DB_HOST))
358358
fio_list_dir(backup_files_list, parray_get(external_dirs, i),
359-
false, true, false, i+1);
359+
false, true, false, false, i+1);
360360
else
361361
dir_list_file(backup_files_list, parray_get(external_dirs, i),
362-
false, true, false, i+1, FIO_LOCAL_HOST);
362+
false, true, false, false, i+1, FIO_LOCAL_HOST);
363363
}
364364
}
365365

@@ -615,7 +615,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
615615
/* Scan backup PG_XLOG_DIR */
616616
xlog_files_list = parray_new();
617617
join_path_components(pg_xlog_path, database_path, PG_XLOG_DIR);
618-
dir_list_file(xlog_files_list, pg_xlog_path, false, true, false, 0,
618+
dir_list_file(xlog_files_list, pg_xlog_path, false, true, false, false, 0,
619619
FIO_BACKUP_HOST);
620620

621621
/* TODO: Drop streamed WAL segments greater than stop_lsn */
@@ -801,8 +801,8 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
801801
* Entry point of pg_probackup BACKUP subcommand.
802802
*/
803803
int
804-
do_backup(time_t start_time, bool no_validate,
805-
pgSetBackupParams *set_backup_params, bool no_sync)
804+
do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
805+
bool no_validate, bool no_sync, bool backup_logs)
806806
{
807807
PGconn *backup_conn = NULL;
808808
PGNodeInfo nodeInfo;
@@ -901,7 +901,7 @@ do_backup(time_t start_time, bool no_validate,
901901
add_note(&current, set_backup_params->note);
902902

903903
/* backup data */
904-
do_backup_instance(backup_conn, &nodeInfo, no_sync);
904+
do_backup_instance(backup_conn, &nodeInfo, no_sync, backup_logs);
905905
pgut_atexit_pop(backup_cleanup, NULL);
906906

907907
/* compute size of wal files of this backup stored in the archive */

src/catalog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ catalog_get_timelines(InstanceConfig *instance)
878878

879879
/* read all xlog files that belong to this archive */
880880
sprintf(arclog_path, "%s/%s/%s", backup_path, "wal", instance->name);
881-
dir_list_file(xlog_files_list, arclog_path, false, false, false, 0, FIO_BACKUP_HOST);
881+
dir_list_file(xlog_files_list, arclog_path, false, false, false, false, 0, FIO_BACKUP_HOST);
882882
parray_qsort(xlog_files_list, pgFileCompareName);
883883

884884
timelineinfos = parray_new();

src/checkdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ do_block_validation(char *pgdata, uint32 checksum_version)
207207
files_list = parray_new();
208208

209209
/* list files with the logical path. omit $PGDATA */
210-
dir_list_file(files_list, pgdata,
211-
true, true, false, 0, FIO_DB_HOST);
210+
dir_list_file(files_list, pgdata, true, true,
211+
false, false, 0, FIO_DB_HOST);
212212

213213
/*
214214
* Sort pathname ascending.

src/delete.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ delete_backup_files(pgBackup *backup)
750750

751751
/* list files to be deleted */
752752
files = parray_new();
753-
dir_list_file(files, backup->root_dir, false, true, true, 0, FIO_BACKUP_HOST);
753+
dir_list_file(files, backup->root_dir, false, false, true, false, 0, FIO_LOCAL_HOST);
754754

755755
/* delete leaf node first */
756756
parray_qsort(files, pgFileCompareRelPathWithExternalDesc);
@@ -966,7 +966,6 @@ do_delete_instance(void)
966966
{
967967
parray *backup_list;
968968
int i;
969-
int rc;
970969
char instance_config_path[MAXPGPATH];
971970

972971

src/dir.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ db_map_entry_free(void *entry)
513513
*/
514514
void
515515
dir_list_file(parray *files, const char *root, bool exclude, bool follow_symlink,
516-
bool add_root, int external_dir_num, fio_location location)
516+
bool add_root, bool backup_logs, int external_dir_num, fio_location location)
517517
{
518518
pgFile *file;
519519

@@ -527,6 +527,17 @@ dir_list_file(parray *files, const char *root, bool exclude, bool follow_symlink
527527
return;
528528
}
529529

530+
/* setup exclusion list for file search */
531+
if (!backup_logs)
532+
{
533+
int i;
534+
535+
for (i = 0; pgdata_exclude_dir[i]; i++); /* find first empty slot */
536+
537+
/* Set 'pg_log' in first empty slot */
538+
pgdata_exclude_dir[i] = PG_LOG_DIR;
539+
}
540+
530541
if (!S_ISDIR(file->mode))
531542
{
532543
if (external_dir_num > 0)

src/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ remove_dir_with_files(const char *path)
10551055
int i;
10561056
char full_path[MAXPGPATH];
10571057

1058-
dir_list_file(files, path, true, true, true, 0, FIO_LOCAL_HOST);
1058+
dir_list_file(files, path, false, false, true, false, 0, FIO_LOCAL_HOST);
10591059
parray_qsort(files, pgFileCompareRelPathWithExternalDesc);
10601060
for (i = 0; i < parray_num(files); i++)
10611061
{

src/pg_probackup.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,6 @@ main(int argc, char *argv[])
668668
if (instance_config.conn_opt.pguser != NULL)
669669
dbuser = pstrdup(instance_config.conn_opt.pguser);
670670

671-
/* setup exclusion list for file search */
672-
if (!backup_logs)
673-
{
674-
int i;
675-
676-
for (i = 0; pgdata_exclude_dir[i]; i++); /* find first empty slot */
677-
678-
/* Set 'pg_log' in first empty slot */
679-
pgdata_exclude_dir[i] = PG_LOG_DIR;
680-
}
681-
682671
if (backup_subcmd == VALIDATE_CMD || backup_subcmd == RESTORE_CMD)
683672
{
684673
/*
@@ -802,7 +791,7 @@ main(int argc, char *argv[])
802791
elog(ERROR, "required parameter not specified: BACKUP_MODE "
803792
"(-b, --backup-mode)");
804793

805-
return do_backup(start_time, no_validate, set_backup_params, no_sync);
794+
return do_backup(start_time, set_backup_params, no_validate, no_sync, backup_logs);
806795
}
807796
case RESTORE_CMD:
808797
return do_restore_or_validate(current.backup_id,

src/pg_probackup.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ extern char** commands_args;
694694
extern const char *pgdata_exclude_dir[];
695695

696696
/* in backup.c */
697-
extern int do_backup(time_t start_time, bool no_validate,
698-
pgSetBackupParams *set_backup_params, bool no_sync);
697+
extern int do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
698+
bool no_validate, bool no_sync, bool backup_logs);
699699
extern void do_checkdb(bool need_amcheck, ConnectionOptions conn_opt,
700700
char *pgdata);
701701
extern BackupMode parse_backup_mode(const char *value);
@@ -859,7 +859,7 @@ extern const char* deparse_compress_alg(int alg);
859859

860860
/* in dir.c */
861861
extern void dir_list_file(parray *files, const char *root, bool exclude,
862-
bool follow_symlink, bool add_root,
862+
bool follow_symlink, bool add_root, bool backup_logs,
863863
int external_dir_num, fio_location location);
864864

865865
extern void create_data_directories(parray *dest_files,
@@ -1035,8 +1035,8 @@ extern int fio_send_file_gz(const char *from_fullpath, const char *to_fullpath,
10351035
extern int fio_send_file(const char *from_fullpath, const char *to_fullpath, FILE* out,
10361036
pgFile *file, char **errormsg);
10371037

1038-
extern void fio_list_dir(parray *files, const char *root, bool exclude,
1039-
bool follow_symlink, bool add_root, int external_dir_num);
1038+
extern void fio_list_dir(parray *files, const char *root, bool exclude, bool follow_symlink,
1039+
bool add_root, bool backup_logs, int external_dir_num);
10401040

10411041
/* return codes for fio_send_pages() and fio_send_file() */
10421042
#define SEND_OK (0)

src/utils/file.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,24 @@ typedef struct
4242
bool exclude;
4343
bool follow_symlink;
4444
bool add_root;
45+
bool backup_logs;
46+
bool exclusive_backup;
4547
int external_dir_num;
4648
} fio_list_dir_request;
4749

4850
typedef struct
4951
{
50-
mode_t mode;
51-
size_t size;
52+
mode_t mode;
53+
size_t size;
5254
time_t mtime;
53-
bool is_datafile;
54-
bool is_database;
55-
56-
Oid tblspcOid;
57-
Oid dbOid;
58-
Oid relOid;
55+
bool is_datafile;
56+
bool is_database;
57+
Oid tblspcOid;
58+
Oid dbOid;
59+
Oid relOid;
5960
ForkName forkName;
60-
int segno;
61-
int external_dir_num;
61+
int segno;
62+
int external_dir_num;
6263
int linked_len;
6364
} fio_pgFile;
6465

@@ -2065,7 +2066,7 @@ static void fio_send_file_impl(int out, char const* path)
20652066

20662067
/* Compile the array of files located on remote machine in directory root */
20672068
void fio_list_dir(parray *files, const char *root, bool exclude,
2068-
bool follow_symlink, bool add_root, int external_dir_num)
2069+
bool follow_symlink, bool add_root, bool backup_logs, int external_dir_num)
20692070
{
20702071
fio_header hdr;
20712072
fio_list_dir_request req;
@@ -2076,6 +2077,8 @@ void fio_list_dir(parray *files, const char *root, bool exclude,
20762077
req.exclude = exclude;
20772078
req.follow_symlink = follow_symlink;
20782079
req.add_root = add_root;
2080+
req.backup_logs = backup_logs;
2081+
req.exclusive_backup = exclusive_backup;
20792082
req.external_dir_num = external_dir_num;
20802083

20812084
hdr.cop = FIO_LIST_DIR;
@@ -2162,12 +2165,15 @@ static void fio_list_dir_impl(int out, char* buf)
21622165

21632166
/*
21642167
* Disable logging into console any messages with exception of ERROR messages,
2165-
* to avoid sending messages to main process, because it may screw his FIO message parsing.
2168+
* because currently we have no mechanism to notify the main process
2169+
* about then message been sent.
2170+
* TODO: correctly send elog messages from agent to main process.
21662171
*/
21672172
instance_config.logger.log_level_console = ERROR;
2173+
exclusive_backup = req->exclusive_backup;
21682174

21692175
dir_list_file(file_files, req->path, req->exclude, req->follow_symlink,
2170-
req->add_root, req->external_dir_num, FIO_LOCAL_HOST);
2176+
req->add_root, req->backup_logs, req->external_dir_num, FIO_LOCAL_HOST);
21712177

21722178
/* send information about files to the main process */
21732179
for (i = 0; i < parray_num(file_files); i++)
@@ -2352,7 +2358,6 @@ void fio_communicate(int in, int out)
23522358
SYS_CHECK(ftruncate(fd[hdr.handle], hdr.arg));
23532359
break;
23542360
case FIO_LIST_DIR:
2355-
// buf contain fio_send_request header and bitmap.
23562361
fio_list_dir_impl(out, buf);
23572362
break;
23582363
case FIO_SEND_PAGES:

0 commit comments

Comments
 (0)