Skip to content

Commit 612070c

Browse files
committed
Code cleanup. remove unused check option
1 parent 0f59db3 commit 612070c

File tree

7 files changed

+110
-171
lines changed

7 files changed

+110
-171
lines changed

backup.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,11 @@ do_backup(bool smooth_checkpoint)
467467
current.stream = stream_wal;
468468

469469
/* Create backup directory and backup.ini */
470-
if (!check)
471-
{
472-
if (pgBackupCreateDir(&current))
473-
elog(ERROR, "cannot create backup directory");
474-
pgBackupWriteIni(&current);
475-
}
470+
471+
if (pgBackupCreateDir(&current))
472+
elog(ERROR, "cannot create backup directory");
473+
pgBackupWriteIni(&current);
474+
476475
elog(LOG, "backup destination is initialized");
477476

478477
/* get list of backups already taken */
@@ -490,8 +489,7 @@ do_backup(bool smooth_checkpoint)
490489
/* update backup status to DONE */
491490
current.end_time = time(NULL);
492491
current.status = BACKUP_STATUS_DONE;
493-
if (!check)
494-
pgBackupWriteIni(&current);
492+
pgBackupWriteIni(&current);
495493

496494
/* Calculate the total data read */
497495
if (verbose)
@@ -1423,18 +1421,15 @@ create_file_list(parray *files, const char *root, bool is_append)
14231421
FILE *fp;
14241422
char path[MAXPGPATH];
14251423

1426-
if (!check)
1427-
{
1428-
/* output path is '$BACKUP_PATH/file_database.txt' */
1429-
pgBackupGetPath(&current, path, lengthof(path), DATABASE_FILE_LIST);
1424+
/* output path is '$BACKUP_PATH/file_database.txt' */
1425+
pgBackupGetPath(&current, path, lengthof(path), DATABASE_FILE_LIST);
14301426

1431-
fp = fopen(path, is_append ? "at" : "wt");
1432-
if (fp == NULL)
1433-
elog(ERROR, "cannot open file list \"%s\": %s", path,
1434-
strerror(errno));
1435-
print_file_list(fp, files, root);
1436-
fclose(fp);
1437-
}
1427+
fp = fopen(path, is_append ? "at" : "wt");
1428+
if (fp == NULL)
1429+
elog(ERROR, "cannot open file list \"%s\": %s", path,
1430+
strerror(errno));
1431+
print_file_list(fp, files, root);
1432+
fclose(fp);
14381433
}
14391434

14401435
/*

data.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ backup_data_file(const char *from_root, const char *to_root,
223223
nblocks = file->size/BLCKSZ;
224224

225225
/* open backup file for write */
226-
if (check)
227-
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
228-
else
229-
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
226+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
230227
out = fopen(to_path, "w");
231228
if (out == NULL)
232229
{
@@ -264,7 +261,7 @@ backup_data_file(const char *from_root, const char *to_root,
264261
}
265262

266263
/* update file permission */
267-
if (!check && chmod(to_path, FILE_PERMISSION) == -1)
264+
if (chmod(to_path, FILE_PERMISSION) == -1)
268265
{
269266
int errno_tmp = errno;
270267
fclose(in);
@@ -293,10 +290,6 @@ backup_data_file(const char *from_root, const char *to_root,
293290
return false;
294291
}
295292

296-
/* remove $BACKUP_PATH/tmp created during check */
297-
if (check)
298-
remove(to_path);
299-
300293
return true;
301294
}
302295

@@ -589,10 +582,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
589582
}
590583

591584
/* open backup file for write */
592-
if (check)
593-
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
594-
else
595-
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
585+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
596586
out = fopen(to_path, "w");
597587
if (out == NULL)
598588
{
@@ -678,9 +668,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
678668
fclose(in);
679669
fclose(out);
680670

681-
if (check)
682-
remove(to_path);
683-
684671
return true;
685672
}
686673

@@ -718,10 +705,7 @@ copy_file_partly(const char *from_root, const char *to_root,
718705
}
719706

720707
/* open backup file for write */
721-
if (check)
722-
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
723-
else
724-
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
708+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
725709

726710
out = fopen(to_path, "w");
727711
if (out == NULL)
@@ -812,9 +796,6 @@ copy_file_partly(const char *from_root, const char *to_root,
812796
fclose(in);
813797
fclose(out);
814798

815-
if (check)
816-
remove(to_path);
817-
818799
return true;
819800
}
820801

delete.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,8 @@ pgBackupDeleteFiles(pgBackup *backup)
270270
* Update STATUS to BACKUP_STATUS_DELETING in preparation for the case which
271271
* the error occurs before deleting all backup files.
272272
*/
273-
if (!check)
274-
{
275-
backup->status = BACKUP_STATUS_DELETING;
276-
pgBackupWriteIni(backup);
277-
}
273+
backup->status = BACKUP_STATUS_DELETING;
274+
pgBackupWriteIni(backup);
278275

279276
/* list files to be deleted */
280277
files = parray_new();
@@ -291,18 +288,14 @@ pgBackupDeleteFiles(pgBackup *backup)
291288
elog(LOG, "delete file(%zd/%lu) \"%s\"", i + 1,
292289
(unsigned long) parray_num(files), file->path);
293290

294-
/* skip actual deletion in check mode */
295-
if (!check)
291+
if (remove(file->path))
296292
{
297-
if (remove(file->path))
298-
{
299-
elog(WARNING, "can't remove \"%s\": %s", file->path,
300-
strerror(errno));
301-
parray_walk(files, pgFileFree);
302-
parray_free(files);
293+
elog(WARNING, "can't remove \"%s\": %s", file->path,
294+
strerror(errno));
295+
parray_walk(files, pgFileFree);
296+
parray_free(files);
303297

304-
return 1;
305-
}
298+
return 1;
306299
}
307300
}
308301

pg_probackup.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ char *backup_path;
2525
char *pgdata;
2626
char arclog_path[MAXPGPATH];
2727

28-
/* common configuration */
29-
bool check = false;
30-
3128
/* directory configuration */
3229
pgBackup current;
3330

@@ -60,7 +57,6 @@ static pgut_option options[] =
6057
{ 's', 'D', "pgdata", &pgdata, SOURCE_CMDLINE },
6158
{ 's', 'B', "backup-path", &backup_path, SOURCE_CMDLINE },
6259
/* common options */
63-
/* { 'b', 'c', "check", &check },*/
6460
{ 'u', 'j', "threads", &num_threads, SOURCE_CMDLINE },
6561
{ 'b', 8, "stream", &stream_wal, SOURCE_CMDLINE },
6662
{ 'b', 11, "progress", &progress, SOURCE_CMDLINE },

pg_probackup.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ extern char *backup_path;
225225
extern char *pgdata;
226226
extern char arclog_path[MAXPGPATH];
227227

228-
/* common configuration */
229-
extern bool check;
230-
231228
/* current settings */
232229
extern pgBackup current;
233230

restore.c

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,9 @@ do_restore(time_t backup_id,
222222
parray_free(backups);
223223

224224
/* print restore complete message */
225-
if (!check)
226-
{
227-
elog(LOG, "all restore completed");
228-
elog(LOG, "========================================");
229-
}
230-
if (!check)
231-
elog(INFO, "restore complete. Recovery starts automatically when the PostgreSQL server is started.");
225+
elog(LOG, "all restore completed");
226+
elog(LOG, "========================================");
227+
elog(INFO, "restore complete. Recovery starts automatically when the PostgreSQL server is started.");
232228

233229
return 0;
234230
}
@@ -259,11 +255,9 @@ restore_database(pgBackup *backup)
259255
backup->wal_block_size, XLOG_BLCKSZ);
260256

261257
time2iso(timestamp, lengthof(timestamp), backup->start_time);
262-
if (!check)
263-
{
264-
elog(LOG, "----------------------------------------");
265-
elog(LOG, "restoring database from backup %s", timestamp);
266-
}
258+
259+
elog(LOG, "----------------------------------------");
260+
elog(LOG, "restoring database from backup %s", timestamp);
267261

268262
/*
269263
* Validate backup files with its size, because load of CRC calculation is
@@ -321,7 +315,6 @@ restore_database(pgBackup *backup)
321315
}
322316

323317
/* Delete files which are not in file list. */
324-
if (!check)
325318
{
326319
parray *files_now;
327320

@@ -358,8 +351,7 @@ restore_database(pgBackup *backup)
358351
parray_walk(files, pgFileFree);
359352
parray_free(files);
360353

361-
if (!check)
362-
elog(LOG, "restore backup completed");
354+
elog(LOG, "restore backup completed");
363355
}
364356

365357
/*
@@ -597,41 +589,35 @@ restore_files(void *arg)
597589
rel_path = file->path + strlen(from_root) + 1;
598590

599591
/* print progress */
600-
if (!check)
601-
elog(LOG, "(%d/%lu) %s ", i + 1, (unsigned long) parray_num(arguments->files),
592+
elog(LOG, "(%d/%lu) %s ", i + 1, (unsigned long) parray_num(arguments->files),
602593
rel_path);
603594

604595
/* Directories are created before */
605596
if (S_ISDIR(file->mode))
606597
{
607-
if (!check)
608-
elog(LOG, "directory, skip");
598+
elog(LOG, "directory, skip");
609599
continue;
610600
}
611601

612602
/* not backed up */
613603
if (file->write_size == BYTES_INVALID)
614604
{
615-
if (!check)
616-
elog(LOG, "not backed up, skip");
605+
elog(LOG, "not backed up, skip");
617606
continue;
618607
}
619608

620609
/* Do not restore tablespace_map file */
621610
if (path_is_prefix_of_path("tablespace_map", rel_path))
622611
{
623-
if (!check)
624-
elog(LOG, "skip tablespace_map");
612+
elog(LOG, "skip tablespace_map");
625613
continue;
626614
}
627615

628616
/* restore file */
629-
if (!check)
630-
restore_data_file(from_root, pgdata, file, arguments->backup);
617+
restore_data_file(from_root, pgdata, file, arguments->backup);
631618

632619
/* print size of restored file */
633-
if (!check)
634-
elog(LOG, "restored %lu\n", (unsigned long) file->write_size);
620+
elog(LOG, "restored %lu\n", (unsigned long) file->write_size);
635621
}
636622
}
637623

@@ -645,42 +631,36 @@ create_recovery_conf(time_t backup_id,
645631
char path[MAXPGPATH];
646632
FILE *fp;
647633

648-
if (!check)
649-
{
650-
elog(LOG, "----------------------------------------");
651-
elog(LOG, "creating recovery.conf");
652-
}
634+
elog(LOG, "----------------------------------------");
635+
elog(LOG, "creating recovery.conf");
653636

654-
if (!check)
655-
{
656-
snprintf(path, lengthof(path), "%s/recovery.conf", pgdata);
657-
fp = fopen(path, "wt");
658-
if (fp == NULL)
659-
elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
660-
strerror(errno));
637+
snprintf(path, lengthof(path), "%s/recovery.conf", pgdata);
638+
fp = fopen(path, "wt");
639+
if (fp == NULL)
640+
elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
641+
strerror(errno));
661642

662-
fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
663-
PROGRAM_VERSION);
664-
fprintf(fp, "restore_command = 'cp %s/%%f %%p'\n", arclog_path);
643+
fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
644+
PROGRAM_VERSION);
645+
fprintf(fp, "restore_command = 'cp %s/%%f %%p'\n", arclog_path);
665646

666-
if (target_time)
667-
fprintf(fp, "recovery_target_time = '%s'\n", target_time);
668-
else if (target_xid)
669-
fprintf(fp, "recovery_target_xid = '%s'\n", target_xid);
670-
else if (backup_id != 0)
671-
{
672-
fprintf(fp, "recovery_target = 'immediate'\n");
673-
fprintf(fp, "recovery_target_action = 'promote'\n");
674-
}
647+
if (target_time)
648+
fprintf(fp, "recovery_target_time = '%s'\n", target_time);
649+
else if (target_xid)
650+
fprintf(fp, "recovery_target_xid = '%s'\n", target_xid);
651+
else if (backup_id != 0)
652+
{
653+
fprintf(fp, "recovery_target = 'immediate'\n");
654+
fprintf(fp, "recovery_target_action = 'promote'\n");
655+
}
675656

676-
if (target_inclusive)
677-
fprintf(fp, "recovery_target_inclusive = '%s'\n", target_inclusive);
657+
if (target_inclusive)
658+
fprintf(fp, "recovery_target_inclusive = '%s'\n", target_inclusive);
678659

679-
if (target_tli)
680-
fprintf(fp, "recovery_target_timeline = '%u'\n", target_tli);
660+
if (target_tli)
661+
fprintf(fp, "recovery_target_timeline = '%u'\n", target_tli);
681662

682-
fclose(fp);
683-
}
663+
fclose(fp);
684664
}
685665

686666
/*

0 commit comments

Comments
 (0)