@@ -166,14 +166,16 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
166
166
source_id = get_system_identifier (source_pgdata , FIO_DB_HOST , false); /* same as instance_config.system_identifier */
167
167
168
168
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" ,
170
171
source_conn_id , source_pgdata , source_id );
171
172
172
173
if (current .backup_mode != BACKUP_MODE_FULL )
173
174
{
174
175
dest_id = get_system_identifier (dest_pgdata , FIO_LOCAL_HOST , false);
175
176
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" ,
177
179
source_conn_id , dest_pgdata , dest_id );
178
180
}
179
181
}
@@ -706,9 +708,12 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
706
708
707
709
/* Start stream replication */
708
710
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
+ }
712
717
713
718
source_filelist = parray_new ();
714
719
@@ -820,9 +825,9 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
820
825
char dirpath [MAXPGPATH ];
821
826
822
827
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 );
826
831
}
827
832
else
828
833
{
@@ -850,18 +855,21 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
850
855
851
856
join_path_components (to_path , dest_pgdata , file -> rel_path );
852
857
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" );
855
860
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
+ }
865
873
}
866
874
}
867
875
@@ -901,7 +909,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
901
909
*/
902
910
if (current .backup_mode != BACKUP_MODE_FULL )
903
911
{
904
- elog (INFO , "Removing redundant files in destination directory" );
912
+ elog (INFO , "Redundant files %s in destination directory" , dry_run ? "can" : "will " );
905
913
parray_qsort (dest_filelist , pgFileCompareRelPathWithExternalDesc );
906
914
for (i = 0 ; i < parray_num (dest_filelist ); i ++ )
907
915
{
@@ -930,11 +938,15 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
930
938
char fullpath [MAXPGPATH ];
931
939
932
940
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
+ }
935
946
936
947
/* shrink dest pgdata list */
937
- pgFileFree (file );
948
+ if (!dry_run )
949
+ pgFileFree (file );
938
950
parray_remove (dest_filelist , i );
939
951
i -- ;
940
952
}
@@ -951,17 +963,20 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
951
963
if (dest_filelist )
952
964
parray_qsort (dest_filelist , pgFileCompareRelPathWithExternal );
953
965
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
+ }
962
977
963
978
/* at last copy control file */
964
- if (catchup_isok )
979
+ if (catchup_isok && ! dry_run )
965
980
{
966
981
char from_fullpath [MAXPGPATH ];
967
982
char to_fullpath [MAXPGPATH ];
@@ -972,7 +987,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
972
987
transfered_datafiles_bytes += source_pg_control_file -> size ;
973
988
}
974
989
975
- if (!catchup_isok )
990
+ if (!catchup_isok && ! dry_run )
976
991
{
977
992
char pretty_time [20 ];
978
993
char pretty_transfered_data_bytes [20 ];
@@ -1010,15 +1025,19 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
1010
1025
pg_free (stop_backup_query_text );
1011
1026
}
1012
1027
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 );
1014
1030
1015
1031
#if PG_VERSION_NUM >= 90600
1016
1032
/* Write backup_label */
1017
1033
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
+ }
1022
1041
stop_backup_result .backup_label_content = NULL ;
1023
1042
stop_backup_result .backup_label_content_len = 0 ;
1024
1043
@@ -1040,6 +1059,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
1040
1059
#endif
1041
1060
1042
1061
/* wait for end of wal streaming and calculate wal size transfered */
1062
+ if (!dry_run )
1043
1063
{
1044
1064
parray * wal_files_list = NULL ;
1045
1065
wal_files_list = parray_new ();
@@ -1081,7 +1101,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
1081
1101
pretty_size (transfered_datafiles_bytes , pretty_transfered_data_bytes , lengthof (pretty_transfered_data_bytes ));
1082
1102
pretty_size (transfered_walfiles_bytes , pretty_transfered_wal_bytes , lengthof (pretty_transfered_wal_bytes ));
1083
1103
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" ,
1085
1106
pretty_transfered_data_bytes , pretty_transfered_wal_bytes , pretty_time );
1086
1107
1087
1108
if (current .backup_mode != BACKUP_MODE_FULL )
@@ -1091,13 +1112,17 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
1091
1112
}
1092
1113
1093
1114
/* 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
+ }
1098
1123
1099
1124
/* Cleanup */
1100
- if (dest_filelist )
1125
+ if (dest_filelist && ! dry_run )
1101
1126
{
1102
1127
parray_walk (dest_filelist , pgFileFree );
1103
1128
parray_free (dest_filelist );
0 commit comments