@@ -94,7 +94,6 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
94
94
{
95
95
int i ;
96
96
char external_prefix [MAXPGPATH ]; /* Temp value. Used as template */
97
- char dst_backup_path [MAXPGPATH ];
98
97
char label [1024 ];
99
98
XLogRecPtr prev_backup_start_lsn = InvalidXLogRecPtr ;
100
99
@@ -137,7 +136,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
137
136
#if PG_VERSION_NUM >= 90600
138
137
current .tli = get_current_timeline (backup_conn );
139
138
#else
140
- current .tli = get_current_timeline_from_control (false);
139
+ current .tli = get_current_timeline_from_control (instance_config . pgdata , FIO_DB_HOST , false);
141
140
#endif
142
141
143
142
/*
@@ -258,17 +257,19 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
258
257
/* start stream replication */
259
258
if (current .stream )
260
259
{
261
- join_path_components (dst_backup_path , current .database_dir , PG_XLOG_DIR );
262
- fio_mkdir (dst_backup_path , DIR_PERMISSION , FIO_BACKUP_HOST );
260
+ char stream_xlog_path [MAXPGPATH ];
263
261
264
- start_WAL_streaming (backup_conn , dst_backup_path , & instance_config .conn_opt ,
262
+ join_path_components (stream_xlog_path , current .database_dir , PG_XLOG_DIR );
263
+ fio_mkdir (stream_xlog_path , DIR_PERMISSION , FIO_BACKUP_HOST );
264
+
265
+ start_WAL_streaming (backup_conn , stream_xlog_path , & instance_config .conn_opt ,
265
266
current .start_lsn , current .tli );
266
267
267
268
/* Make sure that WAL streaming is working
268
269
* PAGE backup in stream mode is waited twice, first for
269
270
* segment in WAL archive and then for streamed segment
270
271
*/
271
- wait_wal_lsn (dst_backup_path , current .start_lsn , true, current .tli , false, true, ERROR , true);
272
+ wait_wal_lsn (stream_xlog_path , current .start_lsn , true, current .tli , false, true, ERROR , true);
272
273
}
273
274
274
275
/* initialize backup's file list */
@@ -315,23 +316,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
315
316
elog (ERROR , "PGDATA is almost empty. Either it was concurrently deleted or "
316
317
"pg_probackup do not possess sufficient permissions to list PGDATA content" );
317
318
318
- /* Calculate pgdata_bytes */
319
- for (i = 0 ; i < parray_num (backup_files_list ); i ++ )
320
- {
321
- pgFile * file = (pgFile * ) parray_get (backup_files_list , i );
322
-
323
- if (file -> external_dir_num != 0 )
324
- continue ;
325
-
326
- if (S_ISDIR (file -> mode ))
327
- {
328
- current .pgdata_bytes += 4096 ;
329
- continue ;
330
- }
331
-
332
- current .pgdata_bytes += file -> size ;
333
- }
334
-
319
+ current .pgdata_bytes += calculate_datasize_of_filelist (backup_files_list );
335
320
pretty_size (current .pgdata_bytes , pretty_bytes , lengthof (pretty_bytes ));
336
321
elog (INFO , "PGDATA size: %s" , pretty_bytes );
337
322
@@ -697,7 +682,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo)
697
682
698
683
if (nodeInfo -> is_superuser )
699
684
elog (WARNING , "Current PostgreSQL role is superuser. "
700
- "It is not recommended to run backup or checkdb as superuser." );
685
+ "It is not recommended to run pg_probackup under superuser." );
701
686
702
687
strlcpy (current .server_version , nodeInfo -> server_version_str ,
703
688
sizeof (current .server_version ));
@@ -786,7 +771,7 @@ do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
786
771
// elog(WARNING, "ptrack_version_num %d", ptrack_version_num);
787
772
788
773
if (nodeInfo .ptrack_version_num > 0 )
789
- nodeInfo .is_ptrack_enable = pg_ptrack_enable (backup_conn , nodeInfo .ptrack_version_num );
774
+ nodeInfo .is_ptrack_enabled = pg_is_ptrack_enabled (backup_conn , nodeInfo .ptrack_version_num );
790
775
791
776
if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
792
777
{
@@ -795,7 +780,7 @@ do_backup(InstanceState *instanceState, pgSetBackupParams *set_backup_params,
795
780
elog (ERROR , "This PostgreSQL instance does not support ptrack" );
796
781
else
797
782
{
798
- if (!nodeInfo .is_ptrack_enable )
783
+ if (!nodeInfo .is_ptrack_enabled )
799
784
elog (ERROR , "Ptrack is disabled" );
800
785
}
801
786
}
@@ -953,12 +938,12 @@ check_server_version(PGconn *conn, PGNodeInfo *nodeInfo)
953
938
* All system identifiers must be equal.
954
939
*/
955
940
void
956
- check_system_identifiers (PGconn * conn , char * pgdata )
941
+ check_system_identifiers (PGconn * conn , const char * pgdata )
957
942
{
958
943
uint64 system_id_conn ;
959
944
uint64 system_id_pgdata ;
960
945
961
- system_id_pgdata = get_system_identifier (pgdata );
946
+ system_id_pgdata = get_system_identifier (pgdata , FIO_DB_HOST );
962
947
system_id_conn = get_remote_system_identifier (conn );
963
948
964
949
/* for checkdb check only system_id_pgdata and system_id_conn */
@@ -1069,7 +1054,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1069
1054
* Switch to a new WAL segment. It should be called only for master.
1070
1055
* For PG 9.5 it should be called only if pguser is superuser.
1071
1056
*/
1072
- static void
1057
+ void
1073
1058
pg_switch_wal (PGconn * conn )
1074
1059
{
1075
1060
PGresult * res ;
@@ -2282,7 +2267,7 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
2282
2267
2283
2268
}
2284
2269
2285
- static void
2270
+ void
2286
2271
check_external_for_tablespaces (parray * external_list , PGconn * backup_conn )
2287
2272
{
2288
2273
PGresult * res ;
@@ -2346,3 +2331,36 @@ check_external_for_tablespaces(parray *external_list, PGconn *backup_conn)
2346
2331
}
2347
2332
}
2348
2333
}
2334
+
2335
+ /*
2336
+ * Calculate pgdata_bytes
2337
+ * accepts (parray *) of (pgFile *)
2338
+ */
2339
+ int64
2340
+ calculate_datasize_of_filelist (parray * filelist )
2341
+ {
2342
+ int64 bytes = 0 ;
2343
+ int i ;
2344
+
2345
+ /* parray_num don't check for NULL */
2346
+ if (filelist == NULL )
2347
+ return 0 ;
2348
+
2349
+ for (i = 0 ; i < parray_num (filelist ); i ++ )
2350
+ {
2351
+ pgFile * file = (pgFile * ) parray_get (filelist , i );
2352
+
2353
+ if (file -> external_dir_num != 0 )
2354
+ continue ;
2355
+
2356
+ if (S_ISDIR (file -> mode ))
2357
+ {
2358
+ // TODO is a dir always 4K?
2359
+ bytes += 4096 ;
2360
+ continue ;
2361
+ }
2362
+
2363
+ bytes += file -> size ;
2364
+ }
2365
+ return bytes ;
2366
+ }
0 commit comments