@@ -95,7 +95,6 @@ static void
95
95
do_backup_instance (PGconn * backup_conn , PGNodeInfo * nodeInfo , bool no_sync , bool backup_logs )
96
96
{
97
97
int i ;
98
- char database_path [MAXPGPATH ];
99
98
char external_prefix [MAXPGPATH ]; /* Temp value. Used as template */
100
99
char dst_backup_path [MAXPGPATH ];
101
100
char label [1024 ];
@@ -147,15 +146,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
147
146
current .tli = get_current_timeline_from_control (false);
148
147
#endif
149
148
150
- /* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
151
- if (current .backup_mode == BACKUP_MODE_DIFF_PAGE || !stream_wal )
152
- /*
153
- * Do not wait start_lsn for stream backup.
154
- * Because WAL streaming will start after pg_start_backup() in stream
155
- * mode.
156
- */
157
- wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false);
158
-
159
149
/*
160
150
* In incremental backup mode ensure that already-validated
161
151
* backup on current timeline exists and get its filelist.
@@ -265,31 +255,39 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
265
255
/* Update running backup meta with START LSN */
266
256
write_backup (& current , true);
267
257
268
- pgBackupGetPath (& current , database_path , lengthof (database_path ),
269
- DATABASE_DIR );
270
- pgBackupGetPath (& current , external_prefix , lengthof (external_prefix ),
271
- EXTERNAL_DIR );
258
+ /* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
259
+ if (current .backup_mode == BACKUP_MODE_DIFF_PAGE || !stream_wal )
260
+ {
261
+ /* Check that archive_dir can be reached */
262
+ if (fio_access (arclog_path , F_OK , FIO_BACKUP_HOST ) != 0 )
263
+ elog (ERROR , "WAL archive directory is not accessible \"%s\": %s" ,
264
+ arclog_path , strerror (errno ));
272
265
273
- /* initialize backup's file list */
274
- backup_files_list = parray_new ();
266
+ /*
267
+ * Do not wait start_lsn for stream backup.
268
+ * Because WAL streaming will start after pg_start_backup() in stream
269
+ * mode.
270
+ */
271
+ wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false);
272
+ }
275
273
276
274
/* start stream replication */
277
275
if (stream_wal )
278
276
{
279
- join_path_components (dst_backup_path , database_path , PG_XLOG_DIR );
277
+ join_path_components (dst_backup_path , current . database_dir , PG_XLOG_DIR );
280
278
fio_mkdir (dst_backup_path , DIR_PERMISSION , FIO_BACKUP_HOST );
281
279
282
280
start_WAL_streaming (backup_conn , dst_backup_path , & instance_config .conn_opt ,
283
281
current .start_lsn , current .tli );
284
282
}
285
283
284
+ /* initialize backup's file list */
285
+ backup_files_list = parray_new ();
286
+ join_path_components (external_prefix , current .root_dir , EXTERNAL_DIR );
287
+
286
288
/* list files with the logical path. omit $PGDATA */
287
- if (fio_is_remote (FIO_DB_HOST ))
288
- fio_list_dir (backup_files_list , instance_config .pgdata ,
289
- true, true, false, backup_logs , true, 0 );
290
- else
291
- dir_list_file (backup_files_list , instance_config .pgdata ,
292
- true, true, false, backup_logs , true, 0 , FIO_LOCAL_HOST );
289
+ fio_list_dir (backup_files_list , instance_config .pgdata ,
290
+ true, true, false, backup_logs , true, 0 );
293
291
294
292
/*
295
293
* Get database_map (name to oid) for use in partial restore feature.
@@ -441,7 +439,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
441
439
join_path_components (dirpath , temp , file -> rel_path );
442
440
}
443
441
else
444
- join_path_components (dirpath , database_path , file -> rel_path );
442
+ join_path_components (dirpath , current . database_dir , file -> rel_path );
445
443
446
444
elog (VERBOSE , "Create directory '%s'" , dirpath );
447
445
fio_mkdir (dirpath , DIR_PERMISSION , FIO_BACKUP_HOST );
@@ -475,7 +473,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
475
473
476
474
arg -> nodeInfo = nodeInfo ;
477
475
arg -> from_root = instance_config .pgdata ;
478
- arg -> to_root = database_path ;
476
+ arg -> to_root = current . database_dir ;
479
477
arg -> external_prefix = external_prefix ;
480
478
arg -> external_dirs = external_dirs ;
481
479
arg -> files_list = backup_files_list ;
@@ -552,7 +550,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
552
550
elog (ERROR , "Failed to find file \"%s\" in backup filelist." ,
553
551
XLOG_CONTROL_FILE );
554
552
555
- set_min_recovery_point (pg_control , database_path , current .stop_lsn );
553
+ set_min_recovery_point (pg_control , current . database_dir , current .stop_lsn );
556
554
}
557
555
558
556
/* close and sync page header map */
@@ -609,7 +607,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
609
607
610
608
/* construct fullpath */
611
609
if (file -> external_dir_num == 0 )
612
- join_path_components (to_fullpath , database_path , file -> rel_path );
610
+ join_path_components (to_fullpath , current . database_dir , file -> rel_path );
613
611
else
614
612
{
615
613
char external_dst [MAXPGPATH ];
@@ -726,8 +724,8 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
726
724
* Entry point of pg_probackup BACKUP subcommand.
727
725
*/
728
726
int
729
- do_backup (time_t start_time , pgSetBackupParams * set_backup_params ,
730
- bool no_validate , bool no_sync , bool backup_logs )
727
+ do_backup (pgSetBackupParams * set_backup_params ,
728
+ bool no_validate , bool no_sync , bool backup_logs )
731
729
{
732
730
PGconn * backup_conn = NULL ;
733
731
PGNodeInfo nodeInfo ;
@@ -736,37 +734,37 @@ do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
736
734
/* Initialize PGInfonode */
737
735
pgNodeInit (& nodeInfo );
738
736
737
+ /* Save list of external directories */
738
+ if (instance_config .external_dir_str &&
739
+ (pg_strcasecmp (instance_config .external_dir_str , "none" ) != 0 ))
740
+ current .external_dir_str = instance_config .external_dir_str ;
741
+
742
+ /* Create backup directory and BACKUP_CONTROL_FILE */
743
+ pgBackupCreateDir (& current , backup_instance_path );
744
+
739
745
if (!instance_config .pgdata )
740
746
elog (ERROR , "required parameter not specified: PGDATA "
741
747
"(-D, --pgdata)" );
742
748
743
749
/* Update backup status and other metainfo. */
744
750
current .status = BACKUP_STATUS_RUNNING ;
745
- current .start_time = start_time ;
751
+ current .start_time = current . backup_id ;
746
752
747
753
StrNCpy (current .program_version , PROGRAM_VERSION ,
748
754
sizeof (current .program_version ));
749
755
750
756
current .compress_alg = instance_config .compress_alg ;
751
757
current .compress_level = instance_config .compress_level ;
752
758
753
- /* Save list of external directories */
754
- if (instance_config .external_dir_str &&
755
- (pg_strcasecmp (instance_config .external_dir_str , "none" ) != 0 ))
756
- current .external_dir_str = instance_config .external_dir_str ;
757
-
758
759
elog (INFO , "Backup start, pg_probackup version: %s, instance: %s, backup ID: %s, backup mode: %s, "
759
760
"wal mode: %s, remote: %s, compress-algorithm: %s, compress-level: %i" ,
760
- PROGRAM_VERSION , instance_name , base36enc (start_time ), pgBackupGetBackupMode (& current , false),
761
+ PROGRAM_VERSION , instance_name , base36enc (current . backup_id ), pgBackupGetBackupMode (& current , false),
761
762
current .stream ? "STREAM" : "ARCHIVE" , IsSshProtocol () ? "true" : "false" ,
762
763
deparse_compress_alg (current .compress_alg ), current .compress_level );
763
764
764
- /* Create backup directory and BACKUP_CONTROL_FILE */
765
- if (pgBackupCreateDir (& current ))
766
- elog (ERROR , "Cannot create backup directory" );
767
765
if (!lock_backup (& current , true, true))
768
766
elog (ERROR , "Cannot lock backup %s directory" ,
769
- base36enc (current .start_time ));
767
+ base36enc (current .backup_id ));
770
768
write_backup (& current , true);
771
769
772
770
/* set the error processing function for the backup process */
@@ -781,7 +779,7 @@ do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
781
779
backup_conn = pgdata_basic_setup (instance_config .conn_opt , & nodeInfo );
782
780
783
781
if (current .from_replica )
784
- elog (INFO , "Backup %s is going to be taken from standby" , base36enc (start_time ));
782
+ elog (INFO , "Backup %s is going to be taken from standby" , base36enc (current . backup_id ));
785
783
786
784
/* TODO, print PostgreSQL full version */
787
785
//elog(INFO, "PostgreSQL version: %s", nodeInfo.server_version_str);
0 commit comments