@@ -149,7 +149,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
149
149
parray * external_dirs = NULL ;
150
150
parray * database_map = NULL ;
151
151
152
- pgFile * pg_control = NULL ;
153
152
PGconn * master_conn = NULL ;
154
153
PGconn * pg_startbackup_conn = NULL ;
155
154
@@ -394,7 +393,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
394
393
* Sorted array is used at least in parse_filelist_filenames(),
395
394
* extractPageMap(), make_pagemap_from_ptrack().
396
395
*/
397
- parray_qsort (backup_files_list , pgFileComparePath );
396
+ parray_qsort (backup_files_list , pgFileCompareRelPathWithExternal );
398
397
399
398
/* Extract information about files in backup_list parsing their names:*/
400
399
parse_filelist_filenames (backup_files_list , instance_config .pgdata );
@@ -468,26 +467,18 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
468
467
if (S_ISDIR (file -> mode ))
469
468
{
470
469
char dirpath [MAXPGPATH ];
471
- char * dir_name ;
472
-
473
- if (file -> external_dir_num )
474
- dir_name = GetRelativePath (file -> path ,
475
- parray_get (external_dirs ,
476
- file -> external_dir_num - 1 ));
477
- else
478
- dir_name = GetRelativePath (file -> path , instance_config .pgdata );
479
-
480
- elog (VERBOSE , "Create directory \"%s\"" , dir_name );
481
470
482
471
if (file -> external_dir_num )
483
472
{
484
473
char temp [MAXPGPATH ];
485
474
snprintf (temp , MAXPGPATH , "%s%d" , external_prefix ,
486
475
file -> external_dir_num );
487
- join_path_components (dirpath , temp , dir_name );
476
+ join_path_components (dirpath , temp , file -> rel_path );
488
477
}
489
478
else
490
- join_path_components (dirpath , database_path , dir_name );
479
+ join_path_components (dirpath , database_path , file -> rel_path );
480
+
481
+ elog (VERBOSE , "Create directory '%s'" , dirpath );
491
482
fio_mkdir (dirpath , DIR_PERMISSION , FIO_BACKUP_HOST );
492
483
}
493
484
@@ -590,16 +581,14 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
590
581
*/
591
582
if (current .from_replica && !exclusive_backup )
592
583
{
593
- char pg_control_path [MAXPGPATH ];
594
-
595
- snprintf (pg_control_path , sizeof (pg_control_path ), "%s/%s" ,
596
- instance_config .pgdata , XLOG_CONTROL_FILE );
584
+ pgFile * pg_control = NULL ;
597
585
598
586
for (i = 0 ; i < parray_num (backup_files_list ); i ++ )
599
587
{
600
588
pgFile * tmp_file = (pgFile * ) parray_get (backup_files_list , i );
601
589
602
- if (strcmp (tmp_file -> path , pg_control_path ) == 0 )
590
+ if (tmp_file -> external_dir_num == 0 &&
591
+ (strcmp (tmp_file -> rel_path , XLOG_CONTROL_FILE ) == 0 ))
603
592
{
604
593
pg_control = tmp_file ;
605
594
break ;
@@ -608,7 +597,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
608
597
609
598
if (!pg_control )
610
599
elog (ERROR , "Failed to find file \"%s\" in backup filelist." ,
611
- pg_control_path );
600
+ XLOG_CONTROL_FILE );
612
601
613
602
set_min_recovery_point (pg_control , database_path , current .stop_lsn );
614
603
}
@@ -636,21 +625,23 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
636
625
637
626
join_path_components (wal_full_path , pg_xlog_path , file -> rel_path );
638
627
639
- if (S_ISREG (file -> mode ))
640
- {
641
- file -> crc = pgFileGetCRC (wal_full_path , true, false);
642
- file -> write_size = file -> size ;
643
- }
644
- /* Remove file path root prefix*/
645
- if (strstr (file -> path , database_path ) == file -> path )
646
- {
647
- char * ptr = file -> path ;
628
+ if (!S_ISREG (file -> mode ))
629
+ continue ;
648
630
649
- file -> path = pgut_strdup (GetRelativePath (ptr , database_path ));
650
- file -> rel_path = pgut_strdup (file -> path );
651
- free (ptr );
652
- }
631
+ file -> crc = pgFileGetCRC (wal_full_path , true, false);
632
+ file -> write_size = file -> size ;
633
+
634
+ /* overwrite rel_path, because now it is relative to
635
+ * /backup_dir/backups/instance_name/backup_id/database/pg_xlog/
636
+ */
637
+ pg_free (file -> rel_path );
638
+
639
+ file -> rel_path = pgut_strdup (GetRelativePath (wal_full_path , database_path ));
640
+ file -> name = last_dir_separator (file -> rel_path );
641
+
642
+ /* Now it is relative to /backup_dir/backups/instance_name/backup_id/database/ */
653
643
}
644
+
654
645
/* Add xlog files into the list of backed up files */
655
646
parray_concat (backup_files_list , xlog_files_list );
656
647
parray_free (xlog_files_list );
@@ -1884,8 +1875,6 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
1884
1875
1885
1876
file -> write_size = file -> size ;
1886
1877
file -> uncompressed_size = file -> size ;
1887
- free (file -> path );
1888
- file -> path = strdup (PG_BACKUP_LABEL_FILE );
1889
1878
parray_append (backup_files_list , file );
1890
1879
}
1891
1880
}
@@ -1932,8 +1921,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
1932
1921
file -> crc = pgFileGetCRC (tablespace_map , true, false);
1933
1922
file -> write_size = file -> size ;
1934
1923
}
1935
- free (file -> path );
1936
- file -> path = strdup (PG_TABLESPACE_MAP_FILE );
1924
+
1937
1925
parray_append (backup_files_list , file );
1938
1926
}
1939
1927
}
@@ -2204,13 +2192,13 @@ parse_filelist_filenames(parray *files, const char *root)
2204
2192
while (i < parray_num (files ))
2205
2193
{
2206
2194
pgFile * file = (pgFile * ) parray_get (files , i );
2207
- char * relative ;
2195
+ // char *relative;
2208
2196
int sscanf_result ;
2209
2197
2210
- relative = GetRelativePath (file -> path , root );
2198
+ // relative = GetRelativePath(file->rel_path , root);
2211
2199
2212
2200
if (S_ISREG (file -> mode ) &&
2213
- path_is_prefix_of_path (PG_TBLSPC_DIR , relative ))
2201
+ path_is_prefix_of_path (PG_TBLSPC_DIR , file -> rel_path ))
2214
2202
{
2215
2203
/*
2216
2204
* Found file in pg_tblspc/tblsOid/TABLESPACE_VERSION_DIRECTORY
@@ -2225,21 +2213,21 @@ parse_filelist_filenames(parray *files, const char *root)
2225
2213
* Check that the file is located under
2226
2214
* TABLESPACE_VERSION_DIRECTORY
2227
2215
*/
2228
- sscanf_result = sscanf (relative , PG_TBLSPC_DIR "/%u/%s/%u" ,
2216
+ sscanf_result = sscanf (file -> rel_path , PG_TBLSPC_DIR "/%u/%s/%u" ,
2229
2217
& tblspcOid , tmp_rel_path , & dbOid );
2230
2218
2231
2219
/* Yes, it is */
2232
2220
if (sscanf_result == 2 &&
2233
2221
strncmp (tmp_rel_path , TABLESPACE_VERSION_DIRECTORY ,
2234
2222
strlen (TABLESPACE_VERSION_DIRECTORY )) == 0 )
2235
- set_cfs_datafiles (files , root , relative , i );
2223
+ set_cfs_datafiles (files , root , file -> rel_path , i );
2236
2224
}
2237
2225
}
2238
2226
2239
2227
if (S_ISREG (file -> mode ) && file -> tblspcOid != 0 &&
2240
2228
file -> name && file -> name [0 ])
2241
2229
{
2242
- if (strcmp ( file -> forkName , "init" ) == 0 )
2230
+ if (file -> forkName == INIT )
2243
2231
{
2244
2232
/*
2245
2233
* Do not backup files of unlogged relations.
@@ -2290,7 +2278,6 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
2290
2278
int p ;
2291
2279
pgFile * prev_file ;
2292
2280
char * cfs_tblspc_path ;
2293
- char * relative_prev_file ;
2294
2281
2295
2282
cfs_tblspc_path = strdup (relative );
2296
2283
if (!cfs_tblspc_path )
@@ -2302,22 +2289,21 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
2302
2289
for (p = (int ) i ; p >= 0 ; p -- )
2303
2290
{
2304
2291
prev_file = (pgFile * ) parray_get (files , (size_t ) p );
2305
- relative_prev_file = GetRelativePath (prev_file -> path , root );
2306
2292
2307
- elog (VERBOSE , "Checking file in cfs tablespace %s" , relative_prev_file );
2293
+ elog (VERBOSE , "Checking file in cfs tablespace %s" , prev_file -> rel_path );
2308
2294
2309
- if (strstr (relative_prev_file , cfs_tblspc_path ) != NULL )
2295
+ if (strstr (prev_file -> rel_path , cfs_tblspc_path ) != NULL )
2310
2296
{
2311
2297
if (S_ISREG (prev_file -> mode ) && prev_file -> is_datafile )
2312
2298
{
2313
2299
elog (VERBOSE , "Setting 'is_cfs' on file %s, name %s" ,
2314
- relative_prev_file , prev_file -> name );
2300
+ prev_file -> rel_path , prev_file -> name );
2315
2301
prev_file -> is_cfs = true;
2316
2302
}
2317
2303
}
2318
2304
else
2319
2305
{
2320
- elog (VERBOSE , "Breaking on %s" , relative_prev_file );
2306
+ elog (VERBOSE , "Breaking on %s" , prev_file -> rel_path );
2321
2307
break ;
2322
2308
}
2323
2309
}
@@ -2331,7 +2317,7 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
2331
2317
void
2332
2318
process_block_change (ForkNumber forknum , RelFileNode rnode , BlockNumber blkno )
2333
2319
{
2334
- char * path ;
2320
+ // char *path;
2335
2321
char * rel_path ;
2336
2322
BlockNumber blkno_inseg ;
2337
2323
int segno ;
@@ -2343,16 +2329,15 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
2343
2329
2344
2330
rel_path = relpathperm (rnode , forknum );
2345
2331
if (segno > 0 )
2346
- path = psprintf ("%s/%s .%u" , instance_config . pgdata , rel_path , segno );
2332
+ f . rel_path = psprintf ("%s.%u" , rel_path , segno );
2347
2333
else
2348
- path = psprintf ( "%s/%s" , instance_config . pgdata , rel_path ) ;
2334
+ f . rel_path = rel_path ;
2349
2335
2350
- pg_free ( rel_path ) ;
2336
+ f . external_dir_num = 0 ;
2351
2337
2352
- f .path = path ;
2353
2338
/* backup_files_list should be sorted before */
2354
2339
file_item = (pgFile * * ) parray_bsearch (backup_files_list , & f ,
2355
- pgFileComparePath );
2340
+ pgFileCompareRelPathWithExternal );
2356
2341
2357
2342
/*
2358
2343
* If we don't have any record of this file in the file map, it means
@@ -2372,7 +2357,7 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
2372
2357
pthread_mutex_unlock (& backup_pagemap_mutex );
2373
2358
}
2374
2359
2375
- pg_free (path );
2360
+ pg_free (rel_path );
2376
2361
}
2377
2362
2378
2363
/*
0 commit comments