1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-16 15:18:40 +02:00

Code cleanup. remove unused check option

This commit is contained in:
Anastasia 2017-04-12 17:39:20 +03:00
parent 0f59db3399
commit 612070c48d
7 changed files with 112 additions and 173 deletions

View File

@ -467,12 +467,11 @@ do_backup(bool smooth_checkpoint)
current.stream = stream_wal;
/* Create backup directory and backup.ini */
if (!check)
{
if (pgBackupCreateDir(&current))
elog(ERROR, "cannot create backup directory");
pgBackupWriteIni(&current);
}
if (pgBackupCreateDir(&current))
elog(ERROR, "cannot create backup directory");
pgBackupWriteIni(&current);
elog(LOG, "backup destination is initialized");
/* get list of backups already taken */
@ -490,8 +489,7 @@ do_backup(bool smooth_checkpoint)
/* update backup status to DONE */
current.end_time = time(NULL);
current.status = BACKUP_STATUS_DONE;
if (!check)
pgBackupWriteIni(&current);
pgBackupWriteIni(&current);
/* Calculate the total data read */
if (verbose)
@ -1423,18 +1421,15 @@ create_file_list(parray *files, const char *root, bool is_append)
FILE *fp;
char path[MAXPGPATH];
if (!check)
{
/* output path is '$BACKUP_PATH/file_database.txt' */
pgBackupGetPath(&current, path, lengthof(path), DATABASE_FILE_LIST);
/* output path is '$BACKUP_PATH/file_database.txt' */
pgBackupGetPath(&current, path, lengthof(path), DATABASE_FILE_LIST);
fp = fopen(path, is_append ? "at" : "wt");
if (fp == NULL)
elog(ERROR, "cannot open file list \"%s\": %s", path,
strerror(errno));
print_file_list(fp, files, root);
fclose(fp);
}
fp = fopen(path, is_append ? "at" : "wt");
if (fp == NULL)
elog(ERROR, "cannot open file list \"%s\": %s", path,
strerror(errno));
print_file_list(fp, files, root);
fclose(fp);
}
/*

27
data.c
View File

@ -223,10 +223,7 @@ backup_data_file(const char *from_root, const char *to_root,
nblocks = file->size/BLCKSZ;
/* open backup file for write */
if (check)
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
else
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
out = fopen(to_path, "w");
if (out == NULL)
{
@ -264,7 +261,7 @@ backup_data_file(const char *from_root, const char *to_root,
}
/* update file permission */
if (!check && chmod(to_path, FILE_PERMISSION) == -1)
if (chmod(to_path, FILE_PERMISSION) == -1)
{
int errno_tmp = errno;
fclose(in);
@ -293,10 +290,6 @@ backup_data_file(const char *from_root, const char *to_root,
return false;
}
/* remove $BACKUP_PATH/tmp created during check */
if (check)
remove(to_path);
return true;
}
@ -589,10 +582,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
}
/* open backup file for write */
if (check)
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
else
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
out = fopen(to_path, "w");
if (out == NULL)
{
@ -678,9 +668,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
fclose(in);
fclose(out);
if (check)
remove(to_path);
return true;
}
@ -718,10 +705,7 @@ copy_file_partly(const char *from_root, const char *to_root,
}
/* open backup file for write */
if (check)
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
else
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
out = fopen(to_path, "w");
if (out == NULL)
@ -812,9 +796,6 @@ copy_file_partly(const char *from_root, const char *to_root,
fclose(in);
fclose(out);
if (check)
remove(to_path);
return true;
}

View File

@ -270,11 +270,8 @@ pgBackupDeleteFiles(pgBackup *backup)
* Update STATUS to BACKUP_STATUS_DELETING in preparation for the case which
* the error occurs before deleting all backup files.
*/
if (!check)
{
backup->status = BACKUP_STATUS_DELETING;
pgBackupWriteIni(backup);
}
backup->status = BACKUP_STATUS_DELETING;
pgBackupWriteIni(backup);
/* list files to be deleted */
files = parray_new();
@ -291,18 +288,14 @@ pgBackupDeleteFiles(pgBackup *backup)
elog(LOG, "delete file(%zd/%lu) \"%s\"", i + 1,
(unsigned long) parray_num(files), file->path);
/* skip actual deletion in check mode */
if (!check)
if (remove(file->path))
{
if (remove(file->path))
{
elog(WARNING, "can't remove \"%s\": %s", file->path,
strerror(errno));
parray_walk(files, pgFileFree);
parray_free(files);
elog(WARNING, "can't remove \"%s\": %s", file->path,
strerror(errno));
parray_walk(files, pgFileFree);
parray_free(files);
return 1;
}
return 1;
}
}

View File

@ -25,9 +25,6 @@ char *backup_path;
char *pgdata;
char arclog_path[MAXPGPATH];
/* common configuration */
bool check = false;
/* directory configuration */
pgBackup current;
@ -60,7 +57,6 @@ static pgut_option options[] =
{ 's', 'D', "pgdata", &pgdata, SOURCE_CMDLINE },
{ 's', 'B', "backup-path", &backup_path, SOURCE_CMDLINE },
/* common options */
/* { 'b', 'c', "check", &check },*/
{ 'u', 'j', "threads", &num_threads, SOURCE_CMDLINE },
{ 'b', 8, "stream", &stream_wal, SOURCE_CMDLINE },
{ 'b', 11, "progress", &progress, SOURCE_CMDLINE },

View File

@ -225,9 +225,6 @@ extern char *backup_path;
extern char *pgdata;
extern char arclog_path[MAXPGPATH];
/* common configuration */
extern bool check;
/* current settings */
extern pgBackup current;

View File

@ -222,13 +222,9 @@ base_backup_found:
parray_free(backups);
/* print restore complete message */
if (!check)
{
elog(LOG, "all restore completed");
elog(LOG, "========================================");
}
if (!check)
elog(INFO, "restore complete. Recovery starts automatically when the PostgreSQL server is started.");
elog(LOG, "all restore completed");
elog(LOG, "========================================");
elog(INFO, "restore complete. Recovery starts automatically when the PostgreSQL server is started.");
return 0;
}
@ -259,11 +255,9 @@ restore_database(pgBackup *backup)
backup->wal_block_size, XLOG_BLCKSZ);
time2iso(timestamp, lengthof(timestamp), backup->start_time);
if (!check)
{
elog(LOG, "----------------------------------------");
elog(LOG, "restoring database from backup %s", timestamp);
}
elog(LOG, "----------------------------------------");
elog(LOG, "restoring database from backup %s", timestamp);
/*
* Validate backup files with its size, because load of CRC calculation is
@ -321,7 +315,6 @@ restore_database(pgBackup *backup)
}
/* Delete files which are not in file list. */
if (!check)
{
parray *files_now;
@ -358,8 +351,7 @@ restore_database(pgBackup *backup)
parray_walk(files, pgFileFree);
parray_free(files);
if (!check)
elog(LOG, "restore backup completed");
elog(LOG, "restore backup completed");
}
/*
@ -597,41 +589,35 @@ restore_files(void *arg)
rel_path = file->path + strlen(from_root) + 1;
/* print progress */
if (!check)
elog(LOG, "(%d/%lu) %s ", i + 1, (unsigned long) parray_num(arguments->files),
elog(LOG, "(%d/%lu) %s ", i + 1, (unsigned long) parray_num(arguments->files),
rel_path);
/* Directories are created before */
if (S_ISDIR(file->mode))
{
if (!check)
elog(LOG, "directory, skip");
elog(LOG, "directory, skip");
continue;
}
/* not backed up */
if (file->write_size == BYTES_INVALID)
{
if (!check)
elog(LOG, "not backed up, skip");
elog(LOG, "not backed up, skip");
continue;
}
/* Do not restore tablespace_map file */
if (path_is_prefix_of_path("tablespace_map", rel_path))
{
if (!check)
elog(LOG, "skip tablespace_map");
elog(LOG, "skip tablespace_map");
continue;
}
/* restore file */
if (!check)
restore_data_file(from_root, pgdata, file, arguments->backup);
restore_data_file(from_root, pgdata, file, arguments->backup);
/* print size of restored file */
if (!check)
elog(LOG, "restored %lu\n", (unsigned long) file->write_size);
elog(LOG, "restored %lu\n", (unsigned long) file->write_size);
}
}
@ -645,42 +631,36 @@ create_recovery_conf(time_t backup_id,
char path[MAXPGPATH];
FILE *fp;
if (!check)
elog(LOG, "----------------------------------------");
elog(LOG, "creating recovery.conf");
snprintf(path, lengthof(path), "%s/recovery.conf", pgdata);
fp = fopen(path, "wt");
if (fp == NULL)
elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
strerror(errno));
fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
PROGRAM_VERSION);
fprintf(fp, "restore_command = 'cp %s/%%f %%p'\n", arclog_path);
if (target_time)
fprintf(fp, "recovery_target_time = '%s'\n", target_time);
else if (target_xid)
fprintf(fp, "recovery_target_xid = '%s'\n", target_xid);
else if (backup_id != 0)
{
elog(LOG, "----------------------------------------");
elog(LOG, "creating recovery.conf");
fprintf(fp, "recovery_target = 'immediate'\n");
fprintf(fp, "recovery_target_action = 'promote'\n");
}
if (!check)
{
snprintf(path, lengthof(path), "%s/recovery.conf", pgdata);
fp = fopen(path, "wt");
if (fp == NULL)
elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
strerror(errno));
if (target_inclusive)
fprintf(fp, "recovery_target_inclusive = '%s'\n", target_inclusive);
fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
PROGRAM_VERSION);
fprintf(fp, "restore_command = 'cp %s/%%f %%p'\n", arclog_path);
if (target_tli)
fprintf(fp, "recovery_target_timeline = '%u'\n", target_tli);
if (target_time)
fprintf(fp, "recovery_target_time = '%s'\n", target_time);
else if (target_xid)
fprintf(fp, "recovery_target_xid = '%s'\n", target_xid);
else if (backup_id != 0)
{
fprintf(fp, "recovery_target = 'immediate'\n");
fprintf(fp, "recovery_target_action = 'promote'\n");
}
if (target_inclusive)
fprintf(fp, "recovery_target_inclusive = '%s'\n", target_inclusive);
if (target_tli)
fprintf(fp, "recovery_target_timeline = '%u'\n", target_tli);
fclose(fp);
}
fclose(fp);
}
/*

View File

@ -182,64 +182,61 @@ pgBackupValidate(pgBackup *backup,
backup_id_string, (size_only ? "SIZE" : "CRC"));
}
if (!check)
if (backup->backup_mode == BACKUP_MODE_FULL ||
backup->backup_mode == BACKUP_MODE_DIFF_PAGE ||
backup->backup_mode == BACKUP_MODE_DIFF_PTRACK)
{
if (backup->backup_mode == BACKUP_MODE_FULL ||
backup->backup_mode == BACKUP_MODE_DIFF_PAGE ||
backup->backup_mode == BACKUP_MODE_DIFF_PTRACK)
int i;
elog(LOG, "database files...");
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
pgBackupGetPath(backup, path, lengthof(path),
DATABASE_FILE_LIST);
files = dir_read_file_list(base_path, path);
/* setup threads */
for (i = 0; i < parray_num(files); i++)
{
int i;
elog(LOG, "database files...");
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
pgBackupGetPath(backup, path, lengthof(path),
DATABASE_FILE_LIST);
files = dir_read_file_list(base_path, path);
/* setup threads */
for (i = 0; i < parray_num(files); i++)
{
pgFile *file = (pgFile *) parray_get(files, i);
__sync_lock_release(&file->lock);
}
/* restore files into $PGDATA */
for (i = 0; i < num_threads; i++)
{
validate_files_args *arg = pg_malloc(sizeof(validate_files_args));
arg->files = files;
arg->root = base_path;
arg->size_only = size_only;
arg->corrupted = false;
validate_threads_args[i] = arg;
pthread_create(&validate_threads[i], NULL, (void *(*)(void *)) pgBackupValidateFiles, arg);
}
/* Wait theads */
for (i = 0; i < num_threads; i++)
{
pthread_join(validate_threads[i], NULL);
if (validate_threads_args[i]->corrupted)
corrupted = true;
pg_free(validate_threads_args[i]);
}
parray_walk(files, pgFileFree);
parray_free(files);
pgFile *file = (pgFile *) parray_get(files, i);
__sync_lock_release(&file->lock);
}
/* update status to OK */
if (corrupted)
backup->status = BACKUP_STATUS_CORRUPT;
else
backup->status = BACKUP_STATUS_OK;
pgBackupWriteIni(backup);
/* restore files into $PGDATA */
for (i = 0; i < num_threads; i++)
{
validate_files_args *arg = pg_malloc(sizeof(validate_files_args));
arg->files = files;
arg->root = base_path;
arg->size_only = size_only;
arg->corrupted = false;
if (corrupted)
elog(WARNING, "backup %s is corrupted", backup_id_string);
else
elog(LOG, "backup %s is valid", backup_id_string);
validate_threads_args[i] = arg;
pthread_create(&validate_threads[i], NULL, (void *(*)(void *)) pgBackupValidateFiles, arg);
}
/* Wait theads */
for (i = 0; i < num_threads; i++)
{
pthread_join(validate_threads[i], NULL);
if (validate_threads_args[i]->corrupted)
corrupted = true;
pg_free(validate_threads_args[i]);
}
parray_walk(files, pgFileFree);
parray_free(files);
}
/* update status to OK */
if (corrupted)
backup->status = BACKUP_STATUS_CORRUPT;
else
backup->status = BACKUP_STATUS_OK;
pgBackupWriteIni(backup);
if (corrupted)
elog(WARNING, "backup %s is corrupted", backup_id_string);
else
elog(LOG, "backup %s is valid", backup_id_string);
return !corrupted;
}