Skip to content

Commit 080988b

Browse files
committed
Merge branch 'master' into issue_90
2 parents 6a3581c + 57da2e5 commit 080988b

17 files changed

+1248
-555
lines changed

Documentation.md

Lines changed: 742 additions & 454 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ gen_probackup_project.pl C:\path_to_postgresql_source_tree
110110

111111
## Documentation
112112

113-
Currently the latest documentation can be found at [Postgres Pro Enterprise documentation](https://postgrespro.com/docs/postgrespro/current/app-pgprobackup).
113+
Currently the latest documentation can be found at [github](https://github.com/postgrespro/pg_probackup/blob/master/Documentation.md) and [Postgres Pro Enterprise documentation](https://postgrespro.com/docs/postgrespro/current/app-pgprobackup).
114114

115115
## Licence
116116

src/backup.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ do_backup_instance(PGconn *backup_conn)
344344
dir_list_file(backup_files_list, parray_get(external_dirs, i),
345345
false, true, false, i+1, FIO_DB_HOST);
346346

347+
/* close ssh session in main thread */
348+
fio_disconnect();
349+
347350
/* Sanity check for backup_files_list, thank you, Windows:
348351
* https://github.com/postgrespro/pg_probackup/issues/48
349352
*/
@@ -512,6 +515,9 @@ do_backup_instance(PGconn *backup_conn)
512515
parray_free(prev_backup_filelist);
513516
}
514517

518+
/* Notify end of backup */
519+
pg_stop_backup(&current, pg_startbackup_conn);
520+
515521
/* In case of backup from replica >= 9.6 we must fix minRecPoint,
516522
* First we must find pg_control in backup_files_list.
517523
*/
@@ -532,13 +538,16 @@ do_backup_instance(PGconn *backup_conn)
532538
break;
533539
}
534540
}
535-
}
536541

537-
/* Notify end of backup */
538-
pg_stop_backup(&current, pg_startbackup_conn);
542+
if (!pg_control)
543+
elog(ERROR, "Failed to find file \"%s\" in backup filelist.",
544+
pg_control_path);
539545

540-
if (current.from_replica && !exclusive_backup)
541546
set_min_recovery_point(pg_control, database_path, current.stop_lsn);
547+
}
548+
549+
/* close ssh session in main thread */
550+
fio_disconnect();
542551

543552
/* Add archived xlog files into the list of files of this backup */
544553
if (stream_wal)
@@ -2143,6 +2152,9 @@ backup_files(void *arg)
21432152
elog(WARNING, "unexpected file type %d", buf.st_mode);
21442153
}
21452154

2155+
/* ssh connection to longer needed */
2156+
fio_disconnect();
2157+
21462158
/* Close connection */
21472159
if (arguments->conn_arg.conn)
21482160
pgut_disconnect(arguments->conn_arg.conn);

src/data.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ prepare_page(ConnectionArgs *arguments,
356356
((strict && !is_ptrack_support) || !strict))
357357
{
358358
/* show this message for checkdb or backup without ptrack support */
359-
elog(WARNING, "CORRUPTION in file %s, block %u",
359+
elog(WARNING, "Corruption detected in file \"%s\", block %u",
360360
file->path, blknum);
361361
}
362362

@@ -585,10 +585,7 @@ backup_data_file(backup_files_arg* arguments,
585585
}
586586

587587
if (file->size % BLCKSZ != 0)
588-
{
589-
fio_fclose(in);
590-
elog(WARNING, "File: %s, invalid file size %zu", file->path, file->size);
591-
}
588+
elog(WARNING, "File: \"%s\", invalid file size %zu", file->path, file->size);
592589

593590
/*
594591
* Compute expected number of blocks in the file.
@@ -625,7 +622,7 @@ backup_data_file(backup_files_arg* arguments,
625622
if (rc == PAGE_CHECKSUM_MISMATCH && is_ptrack_support)
626623
goto RetryUsingPtrack;
627624
if (rc < 0)
628-
elog(ERROR, "Failed to read file %s: %s",
625+
elog(ERROR, "Failed to read file \"%s\": %s",
629626
file->path, rc == PAGE_CHECKSUM_MISMATCH ? "data file checksum mismatch" : strerror(-rc));
630627
n_blocks_read = rc;
631628
}
@@ -1212,10 +1209,7 @@ check_data_file(ConnectionArgs *arguments,
12121209
}
12131210

12141211
if (file->size % BLCKSZ != 0)
1215-
{
1216-
fclose(in);
1217-
elog(WARNING, "File: %s, invalid file size %zu", file->path, file->size);
1218-
}
1212+
elog(WARNING, "File: \"%s\", invalid file size %zu", file->path, file->size);
12191213

12201214
/*
12211215
* Compute expected number of blocks in the file.

src/delete.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
209209
time_t days_threshold = 0;
210210

211211
/* For fancy reporting */
212-
float actual_window = 0;
212+
uint32 actual_window = 0;
213213

214214
/* Get current time */
215215
current_time = time(NULL);
@@ -252,7 +252,9 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
252252
cur_full_backup_num++;
253253
}
254254

255-
/* Check if backup in needed by retention policy */
255+
/* Check if backup in needed by retention policy
256+
* TODO: consider that ERROR backup most likely to have recovery_time == 0
257+
*/
256258
if ((days_threshold == 0 || (days_threshold > backup->recovery_time)) &&
257259
(instance_config.retention_redundancy <= (n_full_backups - cur_full_backup_num)))
258260
{
@@ -324,7 +326,7 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
324326
}
325327

326328
/* Message about retention state of backups
327-
* TODO: Float is ugly, rewrite somehow.
329+
* TODO: message is ugly, rewrite it to something like show table in stdout.
328330
*/
329331

330332
cur_full_backup_num = 1;
@@ -340,9 +342,9 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
340342
if (backup->recovery_time == 0)
341343
actual_window = 0;
342344
else
343-
actual_window = ((float)current_time - (float)backup->recovery_time)/(60 * 60 * 24);
345+
actual_window = (current_time - backup->recovery_time)/(60 * 60 * 24);
344346

345-
elog(INFO, "Backup %s, mode: %s, status: %s. Redundancy: %i/%i, Time Window: %.2fd/%ud. %s",
347+
elog(INFO, "Backup %s, mode: %s, status: %s. Redundancy: %i/%i, Time Window: %ud/%ud. %s",
346348
base36enc(backup->start_time),
347349
pgBackupGetBackupMode(backup),
348350
status2str(backup->status),
@@ -801,10 +803,13 @@ delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli,
801803
int
802804
do_delete_instance(void)
803805
{
804-
parray *backup_list;
805-
int i;
806+
parray *backup_list;
807+
parray *xlog_files_list;
808+
int i;
809+
int rc;
806810
char instance_config_path[MAXPGPATH];
807811

812+
808813
/* Delete all backups. */
809814
backup_list = catalog_get_backup_list(INVALID_BACKUP_ID);
810815

@@ -821,23 +826,40 @@ do_delete_instance(void)
821826
parray_free(backup_list);
822827

823828
/* Delete all wal files. */
824-
delete_walfiles(InvalidXLogRecPtr, 0, instance_config.xlog_seg_size);
829+
xlog_files_list = parray_new();
830+
dir_list_file(xlog_files_list, arclog_path, false, false, false, 0, FIO_BACKUP_HOST);
831+
832+
for (i = 0; i < parray_num(xlog_files_list); i++)
833+
{
834+
pgFile *wal_file = (pgFile *) parray_get(xlog_files_list, i);
835+
if (S_ISREG(wal_file->mode))
836+
{
837+
rc = unlink(wal_file->path);
838+
if (rc != 0)
839+
elog(WARNING, "Failed to remove file \"%s\": %s",
840+
wal_file->path, strerror(errno));
841+
}
842+
}
843+
844+
/* Cleanup */
845+
parray_walk(xlog_files_list, pgFileFree);
846+
parray_free(xlog_files_list);
825847

826848
/* Delete backup instance config file */
827849
join_path_components(instance_config_path, backup_instance_path, BACKUP_CATALOG_CONF_FILE);
828850
if (remove(instance_config_path))
829851
{
830-
elog(ERROR, "can't remove \"%s\": %s", instance_config_path,
852+
elog(ERROR, "Can't remove \"%s\": %s", instance_config_path,
831853
strerror(errno));
832854
}
833855

834856
/* Delete instance root directories */
835857
if (rmdir(backup_instance_path) != 0)
836-
elog(ERROR, "can't remove \"%s\": %s", backup_instance_path,
858+
elog(ERROR, "Can't remove \"%s\": %s", backup_instance_path,
837859
strerror(errno));
838860

839861
if (rmdir(arclog_path) != 0)
840-
elog(ERROR, "can't remove \"%s\": %s", arclog_path,
862+
elog(ERROR, "Can't remove \"%s\": %s", arclog_path,
841863
strerror(errno));
842864

843865
elog(INFO, "Instance '%s' successfully deleted", instance_name);

src/dir.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int BlackListCompare(const void *str1, const void *str2);
122122

123123
static char dir_check_file(pgFile *file);
124124
static void dir_list_file_internal(parray *files, pgFile *parent, bool exclude,
125-
bool omit_symlink, parray *black_list,
125+
bool follow_symlink, parray *black_list,
126126
int external_dir_num, fio_location location);
127127
static void opt_path_map(ConfigOption *opt, const char *arg,
128128
TablespaceList *list, const char *type);
@@ -159,14 +159,14 @@ dir_create_dir(const char *dir, mode_t mode)
159159
}
160160

161161
pgFile *
162-
pgFileNew(const char *path, const char *rel_path, bool omit_symlink,
162+
pgFileNew(const char *path, const char *rel_path, bool follow_symlink,
163163
int external_dir_num, fio_location location)
164164
{
165165
struct stat st;
166166
pgFile *file;
167167

168168
/* stat the file */
169-
if (fio_stat(path, &st, omit_symlink, location) < 0)
169+
if (fio_stat(path, &st, follow_symlink, location) < 0)
170170
{
171171
/* file not found is not an error case */
172172
if (errno == ENOENT)
@@ -445,11 +445,11 @@ BlackListCompare(const void *str1, const void *str2)
445445
* List files, symbolic links and directories in the directory "root" and add
446446
* pgFile objects to "files". We add "root" to "files" if add_root is true.
447447
*
448-
* When omit_symlink is true, symbolic link is ignored and only file or
448+
* When follow_symlink is true, symbolic link is ignored and only file or
449449
* directory linked to will be listed.
450450
*/
451451
void
452-
dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
452+
dir_list_file(parray *files, const char *root, bool exclude, bool follow_symlink,
453453
bool add_root, int external_dir_num, fio_location location)
454454
{
455455
pgFile *file;
@@ -490,7 +490,7 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
490490
parray_qsort(black_list, BlackListCompare);
491491
}
492492

493-
file = pgFileNew(root, "", omit_symlink, external_dir_num, location);
493+
file = pgFileNew(root, "", follow_symlink, external_dir_num, location);
494494
if (file == NULL)
495495
{
496496
/* For external directory this is not ok */
@@ -512,7 +512,7 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
512512
if (add_root)
513513
parray_append(files, file);
514514

515-
dir_list_file_internal(files, file, exclude, omit_symlink, black_list,
515+
dir_list_file_internal(files, file, exclude, follow_symlink, black_list,
516516
external_dir_num, location);
517517

518518
if (!add_root)
@@ -731,7 +731,7 @@ dir_check_file(pgFile *file)
731731
*/
732732
static void
733733
dir_list_file_internal(parray *files, pgFile *parent, bool exclude,
734-
bool omit_symlink, parray *black_list,
734+
bool follow_symlink, parray *black_list,
735735
int external_dir_num, fio_location location)
736736
{
737737
DIR *dir;
@@ -764,7 +764,7 @@ dir_list_file_internal(parray *files, pgFile *parent, bool exclude,
764764
join_path_components(child, parent->path, dent->d_name);
765765
join_path_components(rel_child, parent->rel_path, dent->d_name);
766766

767-
file = pgFileNew(child, rel_child, omit_symlink, external_dir_num,
767+
file = pgFileNew(child, rel_child, follow_symlink, external_dir_num,
768768
location);
769769
if (file == NULL)
770770
continue;
@@ -821,7 +821,7 @@ dir_list_file_internal(parray *files, pgFile *parent, bool exclude,
821821
* recursively.
822822
*/
823823
if (S_ISDIR(file->mode))
824-
dir_list_file_internal(files, file, exclude, omit_symlink,
824+
dir_list_file_internal(files, file, exclude, follow_symlink,
825825
black_list, external_dir_num, location);
826826
}
827827

src/help.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ help_pg_probackup(void)
9797
printf(_(" [--remote-proto] [--remote-host]\n"));
9898
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
9999
printf(_(" [--ssh-options]\n"));
100+
printf(_(" [--help]\n"));
100101

101102
printf(_("\n %s show-config -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
102103
printf(_(" [--format=format]\n"));
104+
printf(_(" [--help]\n"));
103105

104106
printf(_("\n %s backup -B backup-path -b backup-mode --instance=instance_name\n"), PROGRAM_NAME);
105107
printf(_(" [-D pgdata-path] [-C]\n"));
@@ -126,6 +128,7 @@ help_pg_probackup(void)
126128
printf(_(" [--remote-proto] [--remote-host]\n"));
127129
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
128130
printf(_(" [--ssh-options]\n"));
131+
printf(_(" [--help]\n"));
129132

130133
printf(_("\n %s restore -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
131134
printf(_(" [-D pgdata-path] [-i backup-id] [-j num-threads]\n"));
@@ -143,6 +146,7 @@ help_pg_probackup(void)
143146
printf(_(" [--remote-proto] [--remote-host]\n"));
144147
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
145148
printf(_(" [--ssh-options]\n"));
149+
printf(_(" [--help]\n"));
146150

147151
printf(_("\n %s validate -B backup-path [--instance=instance_name]\n"), PROGRAM_NAME);
148152
printf(_(" [-i backup-id] [--progress] [-j num-threads]\n"));
@@ -151,32 +155,39 @@ help_pg_probackup(void)
151155
printf(_(" [--recovery-target-timeline=timeline]\n"));
152156
printf(_(" [--recovery-target-name=target-name]\n"));
153157
printf(_(" [--skip-block-validation]\n"));
158+
printf(_(" [--help]\n"));
154159

155160
printf(_("\n %s checkdb [-B backup-path] [--instance=instance_name]\n"), PROGRAM_NAME);
156161
printf(_(" [-D pgdata-path] [--progress] [-j num-threads]\n"));
157162
printf(_(" [--amcheck] [--skip-block-validation]\n"));
158163
printf(_(" [--heapallindexed]\n"));
164+
printf(_(" [--help]\n"));
159165

160166
printf(_("\n %s show -B backup-path\n"), PROGRAM_NAME);
161167
printf(_(" [--instance=instance_name [-i backup-id]]\n"));
162168
printf(_(" [--format=format]\n"));
169+
printf(_(" [--help]\n"));
163170

164171
printf(_("\n %s delete -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
165172
printf(_(" [--wal] [-i backup-id | --expired | --merge-expired]\n"));
166173
printf(_(" [--dry-run]\n"));
174+
printf(_(" [--help]\n"));
167175

168176
printf(_("\n %s merge -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
169177
printf(_(" -i backup-id [--progress] [-j num-threads]\n"));
178+
printf(_(" [--help]\n"));
170179

171180
printf(_("\n %s add-instance -B backup-path -D pgdata-path\n"), PROGRAM_NAME);
172181
printf(_(" --instance=instance_name\n"));
173182
printf(_(" [--external-dirs=external-directories-paths]\n"));
174183
printf(_(" [--remote-proto] [--remote-host]\n"));
175184
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
176185
printf(_(" [--ssh-options]\n"));
186+
printf(_(" [--help]\n"));
177187

178188
printf(_("\n %s del-instance -B backup-path\n"), PROGRAM_NAME);
179189
printf(_(" --instance=instance_name\n"));
190+
printf(_(" [--help]\n"));
180191

181192
printf(_("\n %s archive-push -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
182193
printf(_(" --wal-file-path=wal-file-path\n"));
@@ -188,13 +199,15 @@ help_pg_probackup(void)
188199
printf(_(" [--remote-proto] [--remote-host]\n"));
189200
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
190201
printf(_(" [--ssh-options]\n"));
202+
printf(_(" [--help]\n"));
191203

192204
printf(_("\n %s archive-get -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
193205
printf(_(" --wal-file-path=wal-file-path\n"));
194206
printf(_(" --wal-file-name=wal-file-name\n"));
195207
printf(_(" [--remote-proto] [--remote-host]\n"));
196208
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
197209
printf(_(" [--ssh-options]\n"));
210+
printf(_(" [--help]\n"));
198211

199212
if ((PROGRAM_URL || PROGRAM_EMAIL))
200213
{

src/pg_probackup.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ extern bool in_backup_list(parray *backup_list, pgBackup *target_backup);
577577
extern int get_backup_index_number(parray *backup_list, pgBackup *backup);
578578
extern bool launch_agent(void);
579579
extern void launch_ssh(char* argv[]);
580+
extern void wait_ssh(void);
580581

581582
#define COMPRESS_ALG_DEFAULT NOT_DEFINED_COMPRESS
582583
#define COMPRESS_LEVEL_DEFAULT 1
@@ -586,7 +587,7 @@ extern const char* deparse_compress_alg(int alg);
586587

587588
/* in dir.c */
588589
extern void dir_list_file(parray *files, const char *root, bool exclude,
589-
bool omit_symlink, bool add_root, int external_dir_num, fio_location location);
590+
bool follow_symlink, bool add_root, int external_dir_num, fio_location location);
590591

591592
extern void create_data_directories(parray *dest_files,
592593
const char *data_dir,
@@ -619,7 +620,7 @@ extern bool fileExists(const char *path, fio_location location);
619620
extern size_t pgFileSize(const char *path);
620621

621622
extern pgFile *pgFileNew(const char *path, const char *rel_path,
622-
bool omit_symlink, int external_dir_num,
623+
bool follow_symlink, int external_dir_num,
623624
fio_location location);
624625
extern pgFile *pgFileInit(const char *path, const char *rel_path);
625626
extern void pgFileDelete(pgFile *file);

0 commit comments

Comments
 (0)