@@ -50,12 +50,12 @@ static void *backup_files(void *arg);
5050static void do_backup_pg (InstanceState * instanceState , PGconn * backup_conn ,
5151 PGNodeInfo * nodeInfo , bool no_sync , bool backup_logs );
5252
53- static void pg_start_backup (const char * label , bool smooth , pgBackup * backup ,
53+ static void pg_start_backup (InstanceState * instanceState , const char * label , bool smooth , pgBackup * backup ,
5454 PGNodeInfo * nodeInfo , PGconn * conn );
5555static void pg_switch_wal (PGconn * conn );
56- static void pg_stop_backup (pgBackup * backup , PGconn * pg_startbackup_conn , PGNodeInfo * nodeInfo );
56+ static void pg_stop_backup (InstanceState * instanceState , pgBackup * backup , PGconn * pg_startbackup_conn , PGNodeInfo * nodeInfo );
5757
58- static XLogRecPtr wait_wal_lsn (XLogRecPtr lsn , bool is_start_lsn , TimeLineID tli ,
58+ static XLogRecPtr wait_wal_lsn (InstanceState * instanceState , XLogRecPtr lsn , bool is_start_lsn , TimeLineID tli ,
5959 bool in_prev_segment , bool segment_only ,
6060 int timeout_elevel , bool in_stream_dir );
6161
@@ -77,14 +77,15 @@ static void set_cfs_datafiles(parray *files, const char *root, char *relative, s
7777static void
7878backup_stopbackup_callback (bool fatal , void * userdata )
7979{
80- PGconn * pg_startbackup_conn = (PGconn * ) userdata ;
80+ InstanceState * instanceState = (InstanceState * ) userdata ;
81+ PGconn * pg_startbackup_conn = instanceState -> conn ;
8182 /*
8283 * If backup is in progress, notify stop of backup to PostgreSQL
8384 */
8485 if (backup_in_progress )
8586 {
8687 elog (WARNING , "backup in progress, stop backup" );
87- pg_stop_backup (NULL , pg_startbackup_conn , NULL ); /* don't care about stop_lsn in case of error */
88+ pg_stop_backup (instanceState , NULL , pg_startbackup_conn , NULL ); /* don't care about stop_lsn in case of error */
8889 }
8990}
9091
@@ -139,7 +140,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
139140 strlen (" with pg_probackup" ));
140141
141142 /* Call pg_start_backup function in PostgreSQL connect */
142- pg_start_backup (label , smooth_checkpoint , & current , nodeInfo , backup_conn );
143+ pg_start_backup (instanceState , label , smooth_checkpoint , & current , nodeInfo , backup_conn );
143144
144145 /* Obtain current timeline */
145146#if PG_VERSION_NUM >= 90600
@@ -270,7 +271,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
270271 * Because WAL streaming will start after pg_start_backup() in stream
271272 * mode.
272273 */
273- wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false);
274+ wait_wal_lsn (instanceState , current .start_lsn , true, current .tli , false, true, ERROR , false);
274275 }
275276
276277 /* start stream replication */
@@ -527,7 +528,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
527528 }
528529
529530 /* Notify end of backup */
530- pg_stop_backup (& current , backup_conn , nodeInfo );
531+ pg_stop_backup (instanceState , & current , backup_conn , nodeInfo );
531532
532533 /* In case of backup from replica >= 9.6 we must fix minRecPoint,
533534 * First we must find pg_control in backup_files_list.
@@ -1028,7 +1029,7 @@ confirm_block_size(PGconn *conn, const char *name, int blcksz)
10281029 * Notify start of backup to PostgreSQL server.
10291030 */
10301031static void
1031- pg_start_backup (const char * label , bool smooth , pgBackup * backup ,
1032+ pg_start_backup (InstanceState * instanceState , const char * label , bool smooth , pgBackup * backup ,
10321033 PGNodeInfo * nodeInfo , PGconn * conn )
10331034{
10341035 PGresult * res ;
@@ -1056,7 +1057,8 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
10561057 * is necessary to call pg_stop_backup() in backup_cleanup().
10571058 */
10581059 backup_in_progress = true;
1059- pgut_atexit_push (backup_stopbackup_callback , conn );
1060+ instanceState -> conn = conn ;
1061+ pgut_atexit_push (backup_stopbackup_callback , instanceState );
10601062
10611063 /* Extract timeline and LSN from results of pg_start_backup() */
10621064 XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
@@ -1262,7 +1264,7 @@ pg_is_superuser(PGconn *conn)
12621264 * Returns InvalidXLogRecPtr if 'segment_only' flag is used.
12631265 */
12641266static XLogRecPtr
1265- wait_wal_lsn (XLogRecPtr target_lsn , bool is_start_lsn , TimeLineID tli ,
1267+ wait_wal_lsn (InstanceState * instanceState , XLogRecPtr target_lsn , bool is_start_lsn , TimeLineID tli ,
12661268 bool in_prev_segment , bool segment_only ,
12671269 int timeout_elevel , bool in_stream_dir )
12681270{
@@ -1296,8 +1298,9 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
12961298 */
12971299 if (in_stream_dir )
12981300 {
1299- pgBackupGetPath2 (& current , pg_wal_dir , lengthof (pg_wal_dir ),
1300- DATABASE_DIR , PG_XLOG_DIR );
1301+ snprintf (pg_wal_dir , lengthof (pg_wal_dir ), "%s/%s/%s/%s" ,
1302+ instanceState -> instance_backup_subdir_path , base36enc (current .start_time ),
1303+ DATABASE_DIR , PG_XLOG_DIR );
13011304 join_path_components (wal_segment_path , pg_wal_dir , wal_segment );
13021305 wal_segment_dir = pg_wal_dir ;
13031306 }
@@ -1438,7 +1441,7 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
14381441 * Notify end of backup to PostgreSQL server.
14391442 */
14401443static void
1441- pg_stop_backup (pgBackup * backup , PGconn * pg_startbackup_conn ,
1444+ pg_stop_backup (InstanceState * instanceState , pgBackup * backup , PGconn * pg_startbackup_conn ,
14421445 PGNodeInfo * nodeInfo )
14431446{
14441447 PGconn * conn ;
@@ -1566,7 +1569,8 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
15661569 }
15671570
15681571 /* After we have sent pg_stop_backup, we don't need this callback anymore */
1569- pgut_atexit_pop (backup_stopbackup_callback , pg_startbackup_conn );
1572+ instanceState -> conn = pg_startbackup_conn ;
1573+ pgut_atexit_pop (backup_stopbackup_callback , instanceState );
15701574
15711575 /*
15721576 * Wait for the result of pg_stop_backup(), but no longer than
@@ -1671,9 +1675,10 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
16711675
16721676 if (stream_wal )
16731677 {
1674- pgBackupGetPath2 (backup , stream_xlog_path ,
1675- lengthof (stream_xlog_path ),
1676- DATABASE_DIR , PG_XLOG_DIR );
1678+ snprintf (stream_xlog_path , lengthof (stream_xlog_path ),
1679+ "%s/%s/%s/%s" , instanceState -> instance_backup_subdir_path ,
1680+ base36enc (backup -> start_time ),
1681+ DATABASE_DIR , PG_XLOG_DIR );
16771682 xlog_path = stream_xlog_path ;
16781683 }
16791684 else
@@ -1702,7 +1707,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17021707 if (stop_backup_lsn_tmp % instance_config .xlog_seg_size == 0 )
17031708 {
17041709 /* Wait for segment with current stop_lsn, it is ok for it to never arrive */
1705- wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1710+ wait_wal_lsn (instanceState , stop_backup_lsn_tmp , false, backup -> tli ,
17061711 false, true, WARNING , stream_wal );
17071712
17081713 /* Get the first record in segment with current stop_lsn */
@@ -1730,7 +1735,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17301735 /* Despite looking for previous record there is not guarantee of success
17311736 * because previous record can be the contrecord.
17321737 */
1733- lsn_tmp = wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1738+ lsn_tmp = wait_wal_lsn (instanceState , stop_backup_lsn_tmp , false, backup -> tli ,
17341739 true, false, ERROR , stream_wal );
17351740
17361741 /* sanity */
@@ -1744,7 +1749,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17441749 else if (stop_backup_lsn_tmp % XLOG_BLCKSZ == 0 )
17451750 {
17461751 /* Wait for segment with current stop_lsn */
1747- wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1752+ wait_wal_lsn (instanceState , stop_backup_lsn_tmp , false, backup -> tli ,
17481753 false, true, ERROR , stream_wal );
17491754
17501755 /* Get the next closest record in segment with current stop_lsn */
@@ -1776,7 +1781,8 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17761781 if (!exclusive_backup )
17771782 {
17781783 Assert (PQnfields (res ) >= 4 );
1779- pgBackupGetPath2 (backup , path , lengthof (path ), DATABASE_DIR , NULL );
1784+ snprintf (path , lengthof (path ), "%s/%s/%s" , instanceState -> instance_backup_subdir_path ,
1785+ base36enc (backup -> start_time ), DATABASE_DIR );
17801786
17811787 /* Write backup_label */
17821788 join_path_components (backup_label , path , PG_BACKUP_LABEL_FILE );
@@ -1873,7 +1879,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18731879 * look for previous record with endpoint >= STOP_LSN.
18741880 */
18751881 if (!stop_lsn_exists )
1876- stop_backup_lsn = wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1882+ stop_backup_lsn = wait_wal_lsn (instanceState , stop_backup_lsn_tmp , false, backup -> tli ,
18771883 false, false, ERROR , stream_wal );
18781884
18791885 if (stream_wal )
@@ -1883,9 +1889,10 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18831889 if (wait_WAL_streaming_end (backup_files_list ))
18841890 elog (ERROR , "WAL streaming failed" );
18851891
1886- pgBackupGetPath2 (backup , stream_xlog_path ,
1887- lengthof (stream_xlog_path ),
1888- DATABASE_DIR , PG_XLOG_DIR );
1892+ snprintf (stream_xlog_path , lengthof (stream_xlog_path ), "%s/%s/%s/%s" ,
1893+ instanceState -> instance_backup_subdir_path , base36enc (backup -> start_time ),
1894+ DATABASE_DIR , PG_XLOG_DIR );
1895+
18891896 xlog_path = stream_xlog_path ;
18901897 }
18911898 else
0 commit comments