@@ -166,14 +166,16 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
166166 source_id = get_system_identifier (source_pgdata , FIO_DB_HOST , false); /* same as instance_config.system_identifier */
167167
168168 if (source_conn_id != source_id )
169- elog (ERROR , "Database identifiers mismatch: we connected to DB id %lu, but in \"%s\" we found id %lu" ,
169+ elog (ERROR , "Database identifiers mismatch: we %s connected to DB id %lu, but in \"%s\" we found id %lu" ,
170+ dry_run ? "can" :"will" ,
170171 source_conn_id , source_pgdata , source_id );
171172
172173 if (current .backup_mode != BACKUP_MODE_FULL )
173174 {
174175 dest_id = get_system_identifier (dest_pgdata , FIO_LOCAL_HOST , false);
175176 if (source_conn_id != dest_id )
176- elog (ERROR , "Database identifiers mismatch: we connected to DB id %lu, but in \"%s\" we found id %lu" ,
177+ elog (ERROR , "Database identifiers mismatch: we %s connected to DB id %lu, but in \"%s\" we found id %lu" ,
178+ dry_run ? "can" :"will" ,
177179 source_conn_id , dest_pgdata , dest_id );
178180 }
179181 }
@@ -706,9 +708,12 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
706708
707709 /* Start stream replication */
708710 join_path_components (dest_xlog_path , dest_pgdata , PG_XLOG_DIR );
709- fio_mkdir (dest_xlog_path , DIR_PERMISSION , FIO_LOCAL_HOST );
710- start_WAL_streaming (source_conn , dest_xlog_path , & instance_config .conn_opt ,
711- current .start_lsn , current .tli , false);
711+ if (!dry_run )
712+ {
713+ fio_mkdir (dest_xlog_path , DIR_PERMISSION , FIO_LOCAL_HOST );
714+ start_WAL_streaming (source_conn , dest_xlog_path , & instance_config .conn_opt ,
715+ current .start_lsn , current .tli , false);
716+ }
712717
713718 source_filelist = parray_new ();
714719
@@ -820,9 +825,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
820825 char dirpath [MAXPGPATH ];
821826
822827 join_path_components (dirpath , dest_pgdata , file -> rel_path );
823-
824- elog ( VERBOSE , "Create directory '%s'" , dirpath );
825- fio_mkdir (dirpath , DIR_PERMISSION , FIO_LOCAL_HOST );
828+ elog ( VERBOSE , "Directory '%s' %s be created" , dirpath , dry_run ? "can" : "will" );
829+ if (! dry_run )
830+ fio_mkdir (dirpath , DIR_PERMISSION , FIO_LOCAL_HOST );
826831 }
827832 else
828833 {
@@ -850,18 +855,21 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
850855
851856 join_path_components (to_path , dest_pgdata , file -> rel_path );
852857
853- elog (VERBOSE , "Create directory \"%s\" and symbolic link \"%s\"" ,
854- linked_path , to_path );
858+ elog (VERBOSE , "Directory \"%s\" and symbolic link \"%s\" %s be created " ,
859+ linked_path , to_path , dry_run ? "can" : "will" );
855860
856- /* create tablespace directory */
857- if (fio_mkdir (linked_path , file -> mode , FIO_LOCAL_HOST ) != 0 )
858- elog (ERROR , "Could not create tablespace directory \"%s\": %s" ,
859- linked_path , strerror (errno ));
860-
861- /* create link to linked_path */
862- if (fio_symlink (linked_path , to_path , true, FIO_LOCAL_HOST ) < 0 )
863- elog (ERROR , "Could not create symbolic link \"%s\" -> \"%s\": %s" ,
864- linked_path , to_path , strerror (errno ));
861+ if (!dry_run )
862+ {
863+ /* create tablespace directory */
864+ if (fio_mkdir (linked_path , file -> mode , FIO_LOCAL_HOST ) != 0 )
865+ elog (ERROR , "Could not create tablespace directory \"%s\": %s" ,
866+ linked_path , strerror (errno ));
867+
868+ /* create link to linked_path */
869+ if (fio_symlink (linked_path , to_path , true, FIO_LOCAL_HOST ) < 0 )
870+ elog (ERROR , "Could not create symbolic link \"%s\" -> \"%s\": %s" ,
871+ linked_path , to_path , strerror (errno ));
872+ }
865873 }
866874 }
867875
@@ -901,7 +909,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
901909 */
902910 if (current .backup_mode != BACKUP_MODE_FULL )
903911 {
904- elog (INFO , "Removing redundant files in destination directory" );
912+ elog (INFO , "Redundant files %s in destination directory" , dry_run ? "can" : "will " );
905913 parray_qsort (dest_filelist , pgFileCompareRelPathWithExternalDesc );
906914 for (i = 0 ; i < parray_num (dest_filelist ); i ++ )
907915 {
@@ -930,11 +938,15 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
930938 char fullpath [MAXPGPATH ];
931939
932940 join_path_components (fullpath , dest_pgdata , file -> rel_path );
933- fio_delete (file -> mode , fullpath , FIO_LOCAL_HOST );
934- elog (VERBOSE , "Deleted file \"%s\"" , fullpath );
941+ if (!dry_run )
942+ {
943+ fio_delete (file -> mode , fullpath , FIO_LOCAL_HOST );
944+ elog (VERBOSE , "File \"%s\" %s deleted" , fullpath , dry_run ? "can" : "will" );
945+ }
935946
936947 /* shrink dest pgdata list */
937- pgFileFree (file );
948+ if (!dry_run )
949+ pgFileFree (file );
938950 parray_remove (dest_filelist , i );
939951 i -- ;
940952 }
@@ -951,17 +963,20 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
951963 if (dest_filelist )
952964 parray_qsort (dest_filelist , pgFileCompareRelPathWithExternal );
953965
954- /* run copy threads */
955- elog (INFO , "Start transferring data files" );
956- time (& start_time );
957- transfered_datafiles_bytes = catchup_multithreaded_copy (num_threads , & source_node_info ,
958- source_pgdata , dest_pgdata ,
959- source_filelist , dest_filelist ,
960- dest_redo .lsn , current .backup_mode );
961- catchup_isok = transfered_datafiles_bytes != -1 ;
966+ if (!dry_run )
967+ {
968+ /* run copy threads */
969+ elog (INFO , "Start transferring data files" );
970+ time (& start_time );
971+ transfered_datafiles_bytes = catchup_multithreaded_copy (num_threads , & source_node_info ,
972+ source_pgdata , dest_pgdata ,
973+ source_filelist , dest_filelist ,
974+ dest_redo .lsn , current .backup_mode );
975+ catchup_isok = transfered_datafiles_bytes != -1 ;
976+ }
962977
963978 /* at last copy control file */
964- if (catchup_isok )
979+ if (catchup_isok && ! dry_run )
965980 {
966981 char from_fullpath [MAXPGPATH ];
967982 char to_fullpath [MAXPGPATH ];
@@ -972,7 +987,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
972987 transfered_datafiles_bytes += source_pg_control_file -> size ;
973988 }
974989
975- if (!catchup_isok )
990+ if (!catchup_isok && ! dry_run )
976991 {
977992 char pretty_time [20 ];
978993 char pretty_transfered_data_bytes [20 ];
@@ -1010,15 +1025,19 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10101025 pg_free (stop_backup_query_text );
10111026 }
10121027
1013- wait_wal_and_calculate_stop_lsn (dest_xlog_path , stop_backup_result .lsn , & current );
1028+ if (!dry_run )
1029+ wait_wal_and_calculate_stop_lsn (dest_xlog_path , stop_backup_result .lsn , & current );
10141030
10151031#if PG_VERSION_NUM >= 90600
10161032 /* Write backup_label */
10171033 Assert (stop_backup_result .backup_label_content != NULL );
1018- pg_stop_backup_write_file_helper (dest_pgdata , PG_BACKUP_LABEL_FILE , "backup label" ,
1019- stop_backup_result .backup_label_content , stop_backup_result .backup_label_content_len ,
1020- NULL );
1021- free (stop_backup_result .backup_label_content );
1034+ if (!dry_run )
1035+ {
1036+ pg_stop_backup_write_file_helper (dest_pgdata , PG_BACKUP_LABEL_FILE , "backup label" ,
1037+ stop_backup_result .backup_label_content , stop_backup_result .backup_label_content_len ,
1038+ NULL );
1039+ free (stop_backup_result .backup_label_content );
1040+ }
10221041 stop_backup_result .backup_label_content = NULL ;
10231042 stop_backup_result .backup_label_content_len = 0 ;
10241043
@@ -1040,6 +1059,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10401059#endif
10411060
10421061 /* wait for end of wal streaming and calculate wal size transfered */
1062+ if (!dry_run )
10431063 {
10441064 parray * wal_files_list = NULL ;
10451065 wal_files_list = parray_new ();
@@ -1081,7 +1101,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10811101 pretty_size (transfered_datafiles_bytes , pretty_transfered_data_bytes , lengthof (pretty_transfered_data_bytes ));
10821102 pretty_size (transfered_walfiles_bytes , pretty_transfered_wal_bytes , lengthof (pretty_transfered_wal_bytes ));
10831103
1084- elog (INFO , "Databases synchronized. Transfered datafiles size: %s, transfered wal size: %s, time elapsed: %s" ,
1104+ elog (INFO , "Databases %s synchronized. Transfered datafiles size: %s, transfered wal size: %s, time elapsed: %s" ,
1105+ dry_run ? "can be" : "was" ,
10851106 pretty_transfered_data_bytes , pretty_transfered_wal_bytes , pretty_time );
10861107
10871108 if (current .backup_mode != BACKUP_MODE_FULL )
@@ -1091,13 +1112,17 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
10911112 }
10921113
10931114 /* Sync all copied files unless '--no-sync' flag is used */
1094- if (sync_dest_files )
1095- catchup_sync_destination_files (dest_pgdata , FIO_LOCAL_HOST , source_filelist , source_pg_control_file );
1096- else
1097- elog (WARNING , "Files are not synced to disk" );
1115+ if (!dry_run )
1116+ {
1117+ /* Sync all copied files unless '--no-sync' flag is used */
1118+ if (sync_dest_files )
1119+ catchup_sync_destination_files (dest_pgdata , FIO_LOCAL_HOST , source_filelist , source_pg_control_file );
1120+ else
1121+ elog (WARNING , "Files are not synced to disk" );
1122+ }
10981123
10991124 /* Cleanup */
1100- if (dest_filelist )
1125+ if (dest_filelist && ! dry_run )
11011126 {
11021127 parray_walk (dest_filelist , pgFileFree );
11031128 parray_free (dest_filelist );
0 commit comments