@@ -67,6 +67,7 @@ static void show_archive_plain(const char *instance_name, uint32 xlog_seg_size,
6767 parray * timelines_list , bool show_name );
6868static void show_archive_json (const char * instance_name , uint32 xlog_seg_size ,
6969 parray * tli_list );
70+ static bool backup_has_tablespace_map (pgBackup * backup );
7071
7172static PQExpBufferData show_buf ;
7273static bool first_instance = true;
@@ -479,6 +480,32 @@ print_backup_json_object(PQExpBuffer buf, pgBackup *backup)
479480 appendPQExpBuffer (buf , "%u" , backup -> content_crc );
480481 }
481482
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+
482509 json_add (buf , JT_END_OBJECT , & json_level );
483510}
484511
@@ -521,7 +548,27 @@ show_backup(InstanceState *instanceState, time_t requested_backup_id)
521548 }
522549
523550 if (show_format == SHOW_PLAIN )
551+ {
524552 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+ }
525572 else
526573 elog (ERROR , "Invalid show format %d" , (int ) show_format );
527574
@@ -1174,3 +1221,10 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
11741221
11751222 first_instance = false;
11761223}
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