@@ -497,7 +497,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
497497 }
498498
499499 /* cleanup */
500- parray_walk (backups , pgBackupFree ); /* TODO: free backup->files */
500+ parray_walk (backups , pgBackupFree );
501501 parray_free (backups );
502502 parray_free (parent_chain );
503503
@@ -529,29 +529,19 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
529529
530530 /* Preparations for actual restoring */
531531 time2iso (timestamp , lengthof (timestamp ), dest_backup -> start_time );
532- elog (LOG , "Restoring database from backup at %s" , timestamp );
532+ elog (INFO , "Restoring the database from backup at %s" , timestamp );
533533
534534 join_path_components (control_file , dest_backup -> root_dir , DATABASE_FILE_LIST );
535535 dest_files = dir_read_file_list (NULL , NULL , control_file , FIO_BACKUP_HOST );
536536
537- // TODO lock entire chain
538- // for (i = parray_num(parent_chain) - 1; i >= 0; i--)
539- // {
540- // pgBackup *backup = (pgBackup *) parray_get(parent_chain, i);
541- //
542- // /*
543- // * Backup was locked during validation if no-validate wasn't
544- // * specified.
545- // */
546- // if (params->no_validate && !lock_backup(backup))
547- // elog(ERROR, "Cannot lock backup directory");
548- //
549- // restore_backup(backup, dest_external_dirs, dest_files, dbOid_exclude_list, params);
550- // }
537+ /* Lock backup chain and make sanity checks */
551538 for (i = parray_num (parent_chain ) - 1 ; i >= 0 ; i -- )
552539 {
553540 pgBackup * backup = (pgBackup * ) parray_get (parent_chain , i );
554541
542+ if (!lock_backup (backup ))
543+ elog (ERROR , "Cannot lock backup %s" , base36enc (backup -> start_time ));
544+
555545 if (backup -> status != BACKUP_STATUS_OK &&
556546 backup -> status != BACKUP_STATUS_DONE )
557547 {
@@ -638,6 +628,10 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
638628 pg_atomic_clear_flag (& file -> lock );
639629 }
640630
631+ /*
632+ * Close ssh connection belonging to the main thread
633+ * to avoid the possibility of been killed for idleness
634+ */
641635 fio_disconnect ();
642636
643637 threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
@@ -735,8 +729,13 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
735729 if (external_dirs != NULL )
736730 free_dir_list (external_dirs );
737731
738- parray_walk (dest_files , pgFileFree );
739- parray_free (dest_files );
732+ for (i = parray_num (parent_chain ) - 1 ; i >= 0 ; i -- )
733+ {
734+ pgBackup * backup = (pgBackup * ) parray_get (parent_chain , i );
735+
736+ parray_walk (backup -> files , pgFileFree );
737+ parray_free (backup -> files );
738+ }
740739}
741740
742741/*
0 commit comments