@@ -95,7 +95,6 @@ static void
9595do_backup_instance (PGconn * backup_conn , PGNodeInfo * nodeInfo , bool no_sync , bool backup_logs )
9696{
9797 int i ;
98- char database_path [MAXPGPATH ];
9998 char external_prefix [MAXPGPATH ]; /* Temp value. Used as template */
10099 char dst_backup_path [MAXPGPATH ];
101100 char label [1024 ];
@@ -265,18 +264,15 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
265264 /* Update running backup meta with START LSN */
266265 write_backup (& current , true);
267266
268- pgBackupGetPath (& current , database_path , lengthof (database_path ),
269- DATABASE_DIR );
270- pgBackupGetPath (& current , external_prefix , lengthof (external_prefix ),
271- EXTERNAL_DIR );
267+ join_path_components (external_prefix , current .database_dir , EXTERNAL_DIR );
272268
273269 /* initialize backup's file list */
274270 backup_files_list = parray_new ();
275271
276272 /* start stream replication */
277273 if (stream_wal )
278274 {
279- join_path_components (dst_backup_path , database_path , PG_XLOG_DIR );
275+ join_path_components (dst_backup_path , current . database_dir , PG_XLOG_DIR );
280276 fio_mkdir (dst_backup_path , DIR_PERMISSION , FIO_BACKUP_HOST );
281277
282278 start_WAL_streaming (backup_conn , dst_backup_path , & instance_config .conn_opt ,
@@ -441,7 +437,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
441437 join_path_components (dirpath , temp , file -> rel_path );
442438 }
443439 else
444- join_path_components (dirpath , database_path , file -> rel_path );
440+ join_path_components (dirpath , current . database_dir , file -> rel_path );
445441
446442 elog (VERBOSE , "Create directory '%s'" , dirpath );
447443 fio_mkdir (dirpath , DIR_PERMISSION , FIO_BACKUP_HOST );
@@ -475,7 +471,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
475471
476472 arg -> nodeInfo = nodeInfo ;
477473 arg -> from_root = instance_config .pgdata ;
478- arg -> to_root = database_path ;
474+ arg -> to_root = current . database_dir ;
479475 arg -> external_prefix = external_prefix ;
480476 arg -> external_dirs = external_dirs ;
481477 arg -> files_list = backup_files_list ;
@@ -552,7 +548,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
552548 elog (ERROR , "Failed to find file \"%s\" in backup filelist." ,
553549 XLOG_CONTROL_FILE );
554550
555- set_min_recovery_point (pg_control , database_path , current .stop_lsn );
551+ set_min_recovery_point (pg_control , current . database_dir , current .stop_lsn );
556552 }
557553
558554 /* close and sync page header map */
@@ -609,7 +605,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
609605
610606 /* construct fullpath */
611607 if (file -> external_dir_num == 0 )
612- join_path_components (to_fullpath , database_path , file -> rel_path );
608+ join_path_components (to_fullpath , current . database_dir , file -> rel_path );
613609 else
614610 {
615611 char external_dst [MAXPGPATH ];
@@ -726,8 +722,8 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
726722 * Entry point of pg_probackup BACKUP subcommand.
727723 */
728724int
729- do_backup (time_t start_time , pgSetBackupParams * set_backup_params ,
730- bool no_validate , bool no_sync , bool backup_logs )
725+ do_backup (pgSetBackupParams * set_backup_params ,
726+ bool no_validate , bool no_sync , bool backup_logs )
731727{
732728 PGconn * backup_conn = NULL ;
733729 PGNodeInfo nodeInfo ;
@@ -736,13 +732,16 @@ do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
736732 /* Initialize PGInfonode */
737733 pgNodeInit (& nodeInfo );
738734
735+ /* Create backup directory and BACKUP_CONTROL_FILE */
736+ pgBackupCreateDir (& current , backup_instance_path );
737+
739738 if (!instance_config .pgdata )
740739 elog (ERROR , "required parameter not specified: PGDATA "
741740 "(-D, --pgdata)" );
742741
743742 /* Update backup status and other metainfo. */
744743 current .status = BACKUP_STATUS_RUNNING ;
745- current .start_time = start_time ;
744+ current .start_time = current . backup_id ;
746745
747746 StrNCpy (current .program_version , PROGRAM_VERSION ,
748747 sizeof (current .program_version ));
@@ -757,16 +756,13 @@ do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
757756
758757 elog (INFO , "Backup start, pg_probackup version: %s, instance: %s, backup ID: %s, backup mode: %s, "
759758 "wal mode: %s, remote: %s, compress-algorithm: %s, compress-level: %i" ,
760- PROGRAM_VERSION , instance_name , base36enc (start_time ), pgBackupGetBackupMode (& current ),
759+ PROGRAM_VERSION , instance_name , base36enc (current . backup_id ), pgBackupGetBackupMode (& current ),
761760 current .stream ? "STREAM" : "ARCHIVE" , IsSshProtocol () ? "true" : "false" ,
762761 deparse_compress_alg (current .compress_alg ), current .compress_level );
763762
764- /* Create backup directory and BACKUP_CONTROL_FILE */
765- if (pgBackupCreateDir (& current ))
766- elog (ERROR , "Cannot create backup directory" );
767763 if (!lock_backup (& current , true, true))
768764 elog (ERROR , "Cannot lock backup %s directory" ,
769- base36enc (current .start_time ));
765+ base36enc (current .backup_id ));
770766 write_backup (& current , true);
771767
772768 /* set the error processing function for the backup process */
@@ -781,7 +777,7 @@ do_backup(time_t start_time, pgSetBackupParams *set_backup_params,
781777 backup_conn = pgdata_basic_setup (instance_config .conn_opt , & nodeInfo );
782778
783779 if (current .from_replica )
784- elog (INFO , "Backup %s is going to be taken from standby" , base36enc (start_time ));
780+ elog (INFO , "Backup %s is going to be taken from standby" , base36enc (current . backup_id ));
785781
786782 /* TODO, print PostgreSQL full version */
787783 //elog(INFO, "PostgreSQL version: %s", nodeInfo.server_version_str);
0 commit comments