Skip to content

Commit 7a20927

Browse files
committed
Merge branch 'issue_205' into issue_201
2 parents ba29f9f + 2f7f677 commit 7a20927

File tree

14 files changed

+651
-322
lines changed

14 files changed

+651
-322
lines changed

src/archive.c

Lines changed: 15 additions & 5 deletions
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++)
@@ -1387,15 +1387,16 @@ get_wal_file(const char *filename, const char *from_fullpath,
13871387
*/
13881388
if (fio_is_remote(FIO_BACKUP_HOST))
13891389
{
1390+
char *errmsg = NULL;
13901391
/* get file via ssh */
13911392
#ifdef HAVE_LIBZ
13921393
/* If requested file is regular WAL segment, then try to open it with '.gz' suffix... */
13931394
if (IsXLogFileName(filename))
1394-
rc = fio_send_file_gz(from_fullpath_gz, to_fullpath, out, thread_num);
1395+
rc = fio_send_file_gz(from_fullpath_gz, to_fullpath, out, NULL, &errmsg);
13951396
if (rc == FILE_MISSING)
13961397
#endif
13971398
/* ... failing that, use uncompressed */
1398-
rc = fio_send_file(from_fullpath, to_fullpath, out, thread_num);
1399+
rc = fio_send_file(from_fullpath, to_fullpath, out, NULL, &errmsg);
13991400

14001401
/* When not in prefetch mode, try to use partial file */
14011402
if (rc == FILE_MISSING && !prefetch_mode && IsXLogFileName(filename))
@@ -1405,18 +1406,27 @@ get_wal_file(const char *filename, const char *from_fullpath,
14051406
#ifdef HAVE_LIBZ
14061407
/* '.gz.partial' goes first ... */
14071408
snprintf(from_partial, sizeof(from_partial), "%s.gz.partial", from_fullpath);
1408-
rc = fio_send_file_gz(from_partial, to_fullpath, out, thread_num);
1409+
rc = fio_send_file_gz(from_partial, to_fullpath, out, NULL, &errmsg);
14091410
if (rc == FILE_MISSING)
14101411
#endif
14111412
{
14121413
/* ... failing that, use '.partial' */
14131414
snprintf(from_partial, sizeof(from_partial), "%s.partial", from_fullpath);
1414-
rc = fio_send_file(from_partial, to_fullpath, out, thread_num);
1415+
rc = fio_send_file(from_partial, to_fullpath, out, NULL, &errmsg);
14151416
}
14161417

14171418
if (rc == SEND_OK)
14181419
src_partial = true;
14191420
}
1421+
1422+
if (rc == WRITE_FAILED)
1423+
elog(WARNING, "Thread [%d]: Cannot write to file '%s': %s",
1424+
thread_num, to_fullpath, strerror(errno));
1425+
1426+
if (errmsg)
1427+
elog(WARNING, "Thread [%d]: %s", thread_num, errmsg);
1428+
1429+
pg_free(errmsg);
14201430
}
14211431
else
14221432
{

src/backup.c

Lines changed: 28 additions & 26 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];
@@ -331,8 +331,12 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
331331
backup_files_list = parray_new();
332332

333333
/* list files with the logical path. omit $PGDATA */
334-
dir_list_file(backup_files_list, instance_config.pgdata,
335-
true, true, false, 0, FIO_DB_HOST);
334+
if (fio_is_remote(FIO_DB_HOST))
335+
fio_list_dir(backup_files_list, instance_config.pgdata,
336+
true, true, false, backup_logs, 0);
337+
else
338+
dir_list_file(backup_files_list, instance_config.pgdata,
339+
true, true, false, backup_logs, 0, FIO_LOCAL_HOST);
336340

337341
/*
338342
* Get database_map (name to oid) for use in partial restore feature.
@@ -345,11 +349,19 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
345349
* from external directory option
346350
*/
347351
if (external_dirs)
352+
{
348353
for (i = 0; i < parray_num(external_dirs); i++)
354+
{
349355
/* External dirs numeration starts with 1.
350356
* 0 value is not external dir */
351-
dir_list_file(backup_files_list, parray_get(external_dirs, i),
352-
false, true, false, i+1, FIO_DB_HOST);
357+
if (fio_is_remote(FIO_DB_HOST))
358+
fio_list_dir(backup_files_list, parray_get(external_dirs, i),
359+
false, true, false, false, i+1);
360+
else
361+
dir_list_file(backup_files_list, parray_get(external_dirs, i),
362+
false, true, false, false, i+1, FIO_LOCAL_HOST);
363+
}
364+
}
353365

354366
/* close ssh session in main thread */
355367
fio_disconnect();
@@ -551,19 +563,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
551563
elog(ERROR, "Data files transferring failed, time elapsed: %s",
552564
pretty_time);
553565

554-
/* Remove disappeared during backup files from backup_list */
555-
for (i = 0; i < parray_num(backup_files_list); i++)
556-
{
557-
pgFile *tmp_file = (pgFile *) parray_get(backup_files_list, i);
558-
559-
if (tmp_file->write_size == FILE_NOT_FOUND)
560-
{
561-
pgFileFree(tmp_file);
562-
parray_remove(backup_files_list, i);
563-
i--;
564-
}
565-
}
566-
567566
/* clean previous backup file list */
568567
if (prev_backup_filelist)
569568
{
@@ -616,7 +615,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
616615
/* Scan backup PG_XLOG_DIR */
617616
xlog_files_list = parray_new();
618617
join_path_components(pg_xlog_path, database_path, PG_XLOG_DIR);
619-
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,
620619
FIO_BACKUP_HOST);
621620

622621
/* TODO: Drop streamed WAL segments greater than stop_lsn */
@@ -802,8 +801,8 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
802801
* Entry point of pg_probackup BACKUP subcommand.
803802
*/
804803
int
805-
do_backup(time_t start_time, bool no_validate,
806-
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)
807806
{
808807
PGconn *backup_conn = NULL;
809808
PGNodeInfo nodeInfo;
@@ -902,7 +901,7 @@ do_backup(time_t start_time, bool no_validate,
902901
add_note(&current, set_backup_params->note);
903902

904903
/* backup data */
905-
do_backup_instance(backup_conn, &nodeInfo, no_sync);
904+
do_backup_instance(backup_conn, &nodeInfo, no_sync, backup_logs);
906905
pgut_atexit_pop(backup_cleanup, NULL);
907906

908907
/* compute size of wal files of this backup stored in the archive */
@@ -2146,6 +2145,12 @@ backup_files(void *arg)
21462145
current.backup_mode, current.parent_backup, true);
21472146
}
21482147

2148+
/* No point in storing empty, missing or not changed files */
2149+
if (file->write_size <= 0)
2150+
unlink(to_fullpath);
2151+
// elog(ERROR, "Cannot remove file \"%s\": %s", to_fullpath,
2152+
// strerror(errno));
2153+
21492154
if (file->write_size == FILE_NOT_FOUND)
21502155
continue;
21512156

@@ -2188,11 +2193,8 @@ parse_filelist_filenames(parray *files, const char *root)
21882193
while (i < parray_num(files))
21892194
{
21902195
pgFile *file = (pgFile *) parray_get(files, i);
2191-
// char *relative;
21922196
int sscanf_result;
21932197

2194-
// relative = GetRelativePath(file->rel_path, root);
2195-
21962198
if (S_ISREG(file->mode) &&
21972199
path_is_prefix_of_path(PG_TBLSPC_DIR, file->rel_path))
21982200
{

src/catalog.c

Lines changed: 6 additions & 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();
@@ -1772,6 +1772,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
17721772

17731773
/*
17741774
* Save the backup content into BACKUP_CONTROL_FILE.
1775+
* TODO: honor the strict flag
17751776
*/
17761777
void
17771778
write_backup(pgBackup *backup, bool strict)
@@ -1856,6 +1857,10 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
18561857
char line[BLCKSZ];
18571858
pgFile *file = (pgFile *) parray_get(files, i);
18581859

1860+
/* Ignore disappeared file */
1861+
if (file->write_size == FILE_NOT_FOUND)
1862+
continue;
1863+
18591864
if (S_ISDIR(file->mode))
18601865
{
18611866
backup_size_on_disk += 4096;

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.

0 commit comments

Comments
 (0)