@@ -65,7 +65,7 @@ static void pg12_recovery_config(pgBackup *backup, bool add_include);
65
65
66
66
static void restore_chain (pgBackup * dest_backup , parray * parent_chain ,
67
67
parray * dbOid_exclude_list , pgRestoreParams * params ,
68
- const char * pgdata_path );
68
+ const char * pgdata_path , bool no_sync );
69
69
70
70
static void * restore_files_new (void * arg );
71
71
@@ -118,7 +118,7 @@ set_orphan_status(parray *backups, pgBackup *parent_backup)
118
118
*/
119
119
int
120
120
do_restore_or_validate (time_t target_backup_id , pgRecoveryTarget * rt ,
121
- pgRestoreParams * params )
121
+ pgRestoreParams * params , bool no_sync )
122
122
{
123
123
int i = 0 ;
124
124
int j = 0 ;
@@ -490,14 +490,14 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
490
490
dest_backup -> server_version );
491
491
492
492
restore_chain (dest_backup , parent_chain , dbOid_exclude_list ,
493
- params , instance_config .pgdata );
493
+ params , instance_config .pgdata , no_sync );
494
494
495
495
/* Create recovery.conf with given recovery target parameters */
496
496
create_recovery_conf (target_backup_id , rt , dest_backup , params );
497
497
}
498
498
499
499
/* cleanup */
500
- parray_walk (backups , pgBackupFree ); /* free backup->files */
500
+ parray_walk (backups , pgBackupFree ); /* TODO: free backup->files */
501
501
parray_free (backups );
502
502
parray_free (parent_chain );
503
503
@@ -512,7 +512,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
512
512
void
513
513
restore_chain (pgBackup * dest_backup , parray * parent_chain ,
514
514
parray * dbOid_exclude_list , pgRestoreParams * params ,
515
- const char * pgdata_path )
515
+ const char * pgdata_path , bool no_sync )
516
516
{
517
517
int i ;
518
518
char control_file [MAXPGPATH ];
@@ -524,6 +524,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
524
524
restore_files_arg_new * threads_args ;
525
525
bool restore_isok = true;
526
526
527
+ char pretty_time [20 ];
527
528
time_t start_time , end_time ;
528
529
529
530
/* Preparations for actual restoring */
@@ -637,6 +638,8 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
637
638
pg_atomic_clear_flag (& file -> lock );
638
639
}
639
640
641
+ fio_disconnect ();
642
+
640
643
threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
641
644
threads_args = (restore_files_arg_new * ) palloc (sizeof (restore_files_arg_new ) *
642
645
num_threads );
@@ -674,46 +677,56 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
674
677
}
675
678
676
679
time (& end_time );
680
+ pretty_time_interval (difftime (end_time , start_time ),
681
+ pretty_time , lengthof (pretty_time ));
677
682
if (restore_isok )
678
- elog (INFO , "Backup files are restored, time elapsed: %.0f sec" ,
679
- difftime (end_time , start_time ));
683
+ elog (INFO , "Backup files are restored, time elapsed: %s" , pretty_time );
680
684
else
681
- elog (ERROR , "Backup files restoring failed, time elapsed: %.0f sec" ,
682
- difftime (end_time , start_time ));
685
+ elog (ERROR , "Backup files restoring failed, time elapsed: %s" , pretty_time );
683
686
687
+ if (no_sync )
688
+ elog (WARNING , "Restored files are not synced to disk" );
689
+ else
690
+ {
691
+ elog (INFO , "Syncing restored files to disk" );
692
+ time (& start_time );
684
693
685
- elog (INFO , "Sync restored backup files to disk" );
686
- time (& start_time );
694
+ for (i = 0 ; i < parray_num (dest_files ); i ++ )
695
+ {
696
+ char to_fullpath [MAXPGPATH ];
697
+ pgFile * dest_file = (pgFile * ) parray_get (dest_files , i );
687
698
688
- for (i = 0 ; i < parray_num (dest_files ); i ++ )
689
- {
690
- int out ;
691
- char to_fullpath [MAXPGPATH ];
692
- pgFile * dest_file = (pgFile * ) parray_get (dest_files , i );
693
-
694
- if (S_ISDIR (dest_file -> mode ) ||
695
- dest_file -> external_dir_num > 0 ||
696
- (strcmp (PG_TABLESPACE_MAP_FILE , dest_file -> rel_path ) == 0 ) ||
697
- (strcmp (DATABASE_MAP , dest_file -> rel_path ) == 0 ))
698
- continue ;
699
+ if (S_ISDIR (dest_file -> mode ))
700
+ continue ;
699
701
700
- join_path_components (to_fullpath , pgdata_path , dest_file -> rel_path );
702
+ if (params -> skip_external_dirs && dest_file -> external_dir_num > 0 )
703
+ continue ;
701
704
702
- /* open destination file */
703
- out = fio_open (to_fullpath , O_WRONLY | PG_BINARY , FIO_DB_HOST );
704
- if (out < 0 )
705
- elog (ERROR , "Cannot open file \"%s\": %s" ,
706
- to_fullpath , strerror (errno ));
707
-
708
- /* sync file */
709
- if (fio_flush (out ) != 0 || fio_close (out ) != 0 )
710
- elog (ERROR , "Cannot sync file \"%s\": %s" ,
711
- to_fullpath , strerror (errno ));
712
- }
705
+ /* construct fullpath */
706
+ if (dest_file -> external_dir_num == 0 )
707
+ {
708
+ if (strcmp (PG_TABLESPACE_MAP_FILE , dest_file -> rel_path ) == 0 )
709
+ continue ;
710
+ if (strcmp (DATABASE_MAP , dest_file -> rel_path ) == 0 )
711
+ continue ;
712
+ join_path_components (to_fullpath , pgdata_path , dest_file -> rel_path );
713
+ }
714
+ else
715
+ {
716
+ char * external_path = parray_get (external_dirs , dest_file -> external_dir_num - 1 );
717
+ join_path_components (to_fullpath , external_path , dest_file -> rel_path );
718
+ }
713
719
714
- time (& end_time );
715
- elog (INFO , "Restored backup files are synced, time elapsed: %.0f sec" ,
716
- difftime (end_time , start_time ));
720
+ /* TODO: write test for case: file to be synced is missing */
721
+ if (fio_sync (to_fullpath , FIO_DB_HOST ) != 0 )
722
+ elog (ERROR , "Failed to sync file \"%s\": %s" , to_fullpath , strerror (errno ));
723
+ }
724
+
725
+ time (& end_time );
726
+ pretty_time_interval (difftime (end_time , start_time ),
727
+ pretty_time , lengthof (pretty_time ));
728
+ elog (INFO , "Restored backup files are synced, time elapsed: %s" , pretty_time );
729
+ }
717
730
718
731
/* cleanup */
719
732
pfree (threads );
@@ -724,8 +737,6 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
724
737
725
738
parray_walk (dest_files , pgFileFree );
726
739
parray_free (dest_files );
727
-
728
- // elog(LOG, "Restore of backup %s is completed", base36enc(backup->start_time));
729
740
}
730
741
731
742
/*
0 commit comments