@@ -67,6 +67,7 @@ static void show_archive_plain(const char *instance_name, uint32 xlog_seg_size,
67
67
parray * timelines_list , bool show_name );
68
68
static void show_archive_json (const char * instance_name , uint32 xlog_seg_size ,
69
69
parray * tli_list );
70
+ static bool backup_has_tablespace_map (pgBackup * backup );
70
71
71
72
static PQExpBufferData show_buf ;
72
73
static bool first_instance = true;
@@ -479,6 +480,32 @@ print_backup_json_object(PQExpBuffer buf, pgBackup *backup)
479
480
appendPQExpBuffer (buf , "%u" , backup -> content_crc );
480
481
}
481
482
483
+ /* print tablespaces list */
484
+ if (backup_has_tablespace_map (backup ))
485
+ {
486
+ parray * links = parray_new ();
487
+
488
+ json_add_key (buf , "tablespace_map" , json_level );
489
+ json_add (buf , JT_BEGIN_ARRAY , & json_level );
490
+
491
+ read_tablespace_map (links , backup -> root_dir );
492
+ parray_qsort (links , pgFileCompareLinked );
493
+
494
+ for (size_t i = 0 ; i < parray_num (links ); i ++ ){
495
+ pgFile * link = (pgFile * ) parray_get (links , i );
496
+ if (i )
497
+ appendPQExpBufferChar (buf , ',' );
498
+ json_add (buf , JT_BEGIN_OBJECT , & json_level );
499
+ json_add_value (buf , "oid" , link -> name , json_level , true);
500
+ json_add_value (buf , "path" , link -> linked , json_level , true);
501
+ json_add (buf , JT_END_OBJECT , & json_level );
502
+ }
503
+ /* End of tablespaces */
504
+ json_add (buf , JT_END_ARRAY , & json_level );
505
+ parray_walk (links , pgFileFree );
506
+ parray_free (links );
507
+ }
508
+
482
509
json_add (buf , JT_END_OBJECT , & json_level );
483
510
}
484
511
@@ -521,7 +548,27 @@ show_backup(InstanceState *instanceState, time_t requested_backup_id)
521
548
}
522
549
523
550
if (show_format == SHOW_PLAIN )
551
+ {
524
552
pgBackupWriteControl (stdout , backup , false);
553
+
554
+ /* print tablespaces list */
555
+ if (backup_has_tablespace_map (backup ))
556
+ {
557
+ parray * links = parray_new ();
558
+
559
+ fio_fprintf (stdout , "\ntablespace_map = '" );
560
+
561
+ read_tablespace_map (links , backup -> root_dir );
562
+ parray_qsort (links , pgFileCompareLinked );
563
+
564
+ for (size_t i = 0 ; i < parray_num (links ); i ++ ){
565
+ pgFile * link = (pgFile * ) parray_get (links , i );
566
+ fio_fprintf (stdout , "%s %s%s" , link -> name , link -> linked , (i < parray_num (links ) - 1 ) ? "; " : "'\n" );
567
+ }
568
+ parray_walk (links , pgFileFree );
569
+ parray_free (links );
570
+ }
571
+ }
525
572
else
526
573
elog (ERROR , "Invalid show format %d" , (int ) show_format );
527
574
@@ -1174,3 +1221,10 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
1174
1221
1175
1222
first_instance = false;
1176
1223
}
1224
+
1225
+ static bool backup_has_tablespace_map (pgBackup * backup )
1226
+ {
1227
+ char map_path [MAXPGPATH ];
1228
+ join_path_components (map_path , backup -> database_dir , PG_TABLESPACE_MAP_FILE );
1229
+ return fileExists (map_path , FIO_BACKUP_HOST );
1230
+ }
0 commit comments