1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2026-06-21 01:34:15 +02:00

Sanitize error checks

All the ERROR_* fields are removed in favor of a more simple layer
made of ERROR, FATAL, PANIC. The two last ones are not actually used
yet, thought there should be some code paths that would need more
polishing on this matter.

The error message emitted before leaving should be fine to let the
user know what is happening.
This commit is contained in:
Michael Paquier
2016-01-19 12:41:30 +09:00
parent 3a9cc02d71
commit 5c37daca69
20 changed files with 164 additions and 196 deletions
+23 -23
View File
@@ -75,7 +75,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
/* Block backup operations on a standby */ /* Block backup operations on a standby */
if (pg_is_standby()) if (pg_is_standby())
elog(ERROR_SYSTEM, "Backup cannot run on a standby."); elog(ERROR, "Backup cannot run on a standby.");
elog(INFO, "database backup start"); elog(INFO, "database backup start");
@@ -102,7 +102,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
prev_backup = catalog_get_last_data_backup(backup_list, current.tli); prev_backup = catalog_get_last_data_backup(backup_list, current.tli);
if (prev_backup == NULL) if (prev_backup == NULL)
elog(ERROR_SYSTEM, "Valid full backup not found for " elog(ERROR, "Valid full backup not found for "
"differential backup. Either create a full backup " "differential backup. Either create a full backup "
"or validate existing one."); "or validate existing one.");
} }
@@ -123,7 +123,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
{ {
elog(LOG, "backup_label does not exist, stopping backup"); elog(LOG, "backup_label does not exist, stopping backup");
pg_stop_backup(NULL); pg_stop_backup(NULL);
elog(ERROR_SYSTEM, "backup_label does not exist in PGDATA."); elog(ERROR, "backup_label does not exist in PGDATA.");
} }
/* /*
@@ -138,12 +138,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
pgBackupGetPath(&current, path, lengthof(path), MKDIRS_SH_FILE); pgBackupGetPath(&current, path, lengthof(path), MKDIRS_SH_FILE);
fp = fopen(path, "wt"); fp = fopen(path, "wt");
if (fp == NULL) if (fp == NULL)
elog(ERROR_SYSTEM, "can't open make directory script \"%s\": %s", elog(ERROR, "can't open make directory script \"%s\": %s",
path, strerror(errno)); path, strerror(errno));
dir_print_mkdirs_sh(fp, backup_files_list, pgdata); dir_print_mkdirs_sh(fp, backup_files_list, pgdata);
fclose(fp); fclose(fp);
if (chmod(path, DIR_PERMISSION) == -1) if (chmod(path, DIR_PERMISSION) == -1)
elog(ERROR_SYSTEM, "can't change mode of \"%s\": %s", path, elog(ERROR, "can't change mode of \"%s\": %s", path,
strerror(errno)); strerror(errno));
} }
@@ -255,12 +255,12 @@ do_backup(pgBackupOption bkupopt)
/* PGDATA and BACKUP_MODE are always required */ /* PGDATA and BACKUP_MODE are always required */
if (pgdata == NULL) if (pgdata == NULL)
elog(ERROR_ARGS, "Required parameter not specified: PGDATA " elog(ERROR, "Required parameter not specified: PGDATA "
"(-D, --pgdata)"); "(-D, --pgdata)");
/* A backup mode is needed */ /* A backup mode is needed */
if (current.backup_mode == BACKUP_MODE_INVALID) if (current.backup_mode == BACKUP_MODE_INVALID)
elog(ERROR_ARGS, "Required parameter not specified: BACKUP_MODE " elog(ERROR, "Required parameter not specified: BACKUP_MODE "
"(-b, --backup-mode)"); "(-b, --backup-mode)");
/* Confirm data block size and xlog block size are compatible */ /* Confirm data block size and xlog block size are compatible */
@@ -280,9 +280,9 @@ do_backup(pgBackupOption bkupopt)
/* get exclusive lock of backup catalog */ /* get exclusive lock of backup catalog */
ret = catalog_lock(); ret = catalog_lock();
if (ret == -1) if (ret == -1)
elog(ERROR_SYSTEM, "cannot lock backup catalog"); elog(ERROR, "cannot lock backup catalog");
else if (ret == 1) else if (ret == 1)
elog(ERROR_ALREADY_RUNNING, elog(ERROR,
"another pg_arman is running, skipping this backup"); "another pg_arman is running, skipping this backup");
/* initialize backup result */ /* initialize backup result */
@@ -302,7 +302,7 @@ do_backup(pgBackupOption bkupopt)
if (!check) if (!check)
{ {
if (pgBackupCreateDir(&current)) if (pgBackupCreateDir(&current))
elog(ERROR_SYSTEM, "cannot create backup directory"); elog(ERROR, "cannot create backup directory");
pgBackupWriteIni(&current); pgBackupWriteIni(&current);
} }
elog(LOG, "backup destination is initialized"); elog(LOG, "backup destination is initialized");
@@ -310,7 +310,7 @@ do_backup(pgBackupOption bkupopt)
/* get list of backups already taken */ /* get list of backups already taken */
backup_list = catalog_get_backup_list(NULL); backup_list = catalog_get_backup_list(NULL);
if (!backup_list) if (!backup_list)
elog(ERROR_SYSTEM, "cannot process any more"); elog(ERROR, "cannot process any more");
/* set the error processing function for the backup process */ /* set the error processing function for the backup process */
pgut_atexit_push(backup_cleanup, NULL); pgut_atexit_push(backup_cleanup, NULL);
@@ -379,7 +379,7 @@ check_server_version(void)
/* confirm server version */ /* confirm server version */
server_version = PQserverVersion(connection); server_version = PQserverVersion(connection);
if (server_version != PG_VERSION_NUM) if (server_version != PG_VERSION_NUM)
elog(ERROR_PG_INCOMPATIBLE, elog(ERROR,
"server version is %d.%d.%d, must be %s or higher.", "server version is %d.%d.%d, must be %s or higher.",
server_version / 10000, server_version / 10000,
(server_version / 100) % 100, (server_version / 100) % 100,
@@ -402,12 +402,12 @@ confirm_block_size(const char *name, int blcksz)
res = execute("SELECT current_setting($1)", 1, &name); res = execute("SELECT current_setting($1)", 1, &name);
if (PQntuples(res) != 1 || PQnfields(res) != 1) if (PQntuples(res) != 1 || PQnfields(res) != 1)
elog(ERROR_PG_COMMAND, "cannot get %s: %s", elog(ERROR, "cannot get %s: %s",
name, PQerrorMessage(connection)); name, PQerrorMessage(connection));
block_size = strtol(PQgetvalue(res, 0, 0), &endp, 10); block_size = strtol(PQgetvalue(res, 0, 0), &endp, 10);
PQclear(res); PQclear(res);
if ((endp && *endp) || block_size != blcksz) if ((endp && *endp) || block_size != blcksz)
elog(ERROR_PG_INCOMPATIBLE, elog(ERROR,
"%s(%d) is not compatible(%d expected)", "%s(%d) is not compatible(%d expected)",
name, block_size, blcksz); name, block_size, blcksz);
} }
@@ -494,11 +494,11 @@ wait_for_archive(pgBackup *backup, const char *sql)
{ {
sleep(1); sleep(1);
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, elog(ERROR,
"interrupted during waiting for WAL archiving"); "interrupted during waiting for WAL archiving");
try_count++; try_count++;
if (try_count > TIMEOUT_ARCHIVE) if (try_count > TIMEOUT_ARCHIVE)
elog(ERROR_ARCHIVE_FAILED, elog(ERROR,
"switched WAL could not be archived in %d seconds", "switched WAL could not be archived in %d seconds",
TIMEOUT_ARCHIVE); TIMEOUT_ARCHIVE);
} }
@@ -539,7 +539,7 @@ get_lsn(PGresult *res, XLogRecPtr *lsn)
uint32 xrecoff; uint32 xrecoff;
if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 1) if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 1)
elog(ERROR_PG_COMMAND, elog(ERROR,
"result of backup command is invalid: %s", "result of backup command is invalid: %s",
PQerrorMessage(connection)); PQerrorMessage(connection));
@@ -560,13 +560,13 @@ static void
get_xid(PGresult *res, uint32 *xid) get_xid(PGresult *res, uint32 *xid)
{ {
if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 1) if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 1)
elog(ERROR_PG_COMMAND, elog(ERROR,
"result of txid_current() is invalid: %s", "result of txid_current() is invalid: %s",
PQerrorMessage(connection)); PQerrorMessage(connection));
if (sscanf(PQgetvalue(res, 0, 0), "%u", xid) != 1) if (sscanf(PQgetvalue(res, 0, 0), "%u", xid) != 1)
{ {
elog(ERROR_PG_COMMAND, elog(ERROR,
"result of txid_current() is invalid: %s", "result of txid_current() is invalid: %s",
PQerrorMessage(connection)); PQerrorMessage(connection));
} }
@@ -653,12 +653,12 @@ backup_files(const char *from_root,
/* If current time is rewinded, abort this backup. */ /* If current time is rewinded, abort this backup. */
if (tv.tv_sec < file->mtime) if (tv.tv_sec < file->mtime)
elog(ERROR_SYSTEM, elog(ERROR,
"current time may be rewound. Please retry with full backup mode."); "current time may be rewound. Please retry with full backup mode.");
/* check for interrupt */ /* check for interrupt */
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, "interrupted during backup"); elog(ERROR, "interrupted during backup");
/* print progress in verbose mode */ /* print progress in verbose mode */
if (verbose) if (verbose)
@@ -688,7 +688,7 @@ backup_files(const char *from_root,
} }
else else
{ {
elog(ERROR_SYSTEM, elog(ERROR,
"can't stat backup mode. \"%s\": %s", "can't stat backup mode. \"%s\": %s",
file->path, strerror(errno)); file->path, strerror(errno));
} }
@@ -852,7 +852,7 @@ create_file_list(parray *files,
pgBackupGetPath(&current, path, lengthof(path), subdir); pgBackupGetPath(&current, path, lengthof(path), subdir);
fp = fopen(path, is_append ? "at" : "wt"); fp = fopen(path, is_append ? "at" : "wt");
if (fp == NULL) if (fp == NULL)
elog(ERROR_SYSTEM, "can't open file list \"%s\": %s", path, elog(ERROR, "can't open file list \"%s\": %s", path,
strerror(errno)); strerror(errno));
dir_print_file_list(fp, files, root, prefix); dir_print_file_list(fp, files, root, prefix);
fclose(fp); fclose(fp);
+5 -5
View File
@@ -40,7 +40,7 @@ catalog_lock(void)
join_path_components(id_path, backup_path, PG_RMAN_INI_FILE); join_path_components(id_path, backup_path, PG_RMAN_INI_FILE);
lock_fd = open(id_path, O_RDWR); lock_fd = open(id_path, O_RDWR);
if (lock_fd == -1) if (lock_fd == -1)
elog(errno == ENOENT ? ERROR_CORRUPTED : ERROR_SYSTEM, elog(errno == ENOENT ? ERROR : ERROR,
"cannot open file \"%s\": %s", id_path, strerror(errno)); "cannot open file \"%s\": %s", id_path, strerror(errno));
ret = flock(lock_fd, LOCK_EX | LOCK_NB); /* non-blocking */ ret = flock(lock_fd, LOCK_EX | LOCK_NB); /* non-blocking */
@@ -55,7 +55,7 @@ catalog_lock(void)
{ {
int errno_tmp = errno; int errno_tmp = errno;
close(lock_fd); close(lock_fd);
elog(ERROR_SYSTEM, "cannot lock file \"%s\": %s", id_path, elog(ERROR, "cannot lock file \"%s\": %s", id_path,
strerror(errno_tmp)); strerror(errno_tmp));
} }
} }
@@ -351,7 +351,7 @@ pgBackupWriteIni(pgBackup *backup)
pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_INI_FILE); pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
fp = fopen(ini_path, "wt"); fp = fopen(ini_path, "wt");
if (fp == NULL) if (fp == NULL)
elog(ERROR_SYSTEM, "cannot open INI file \"%s\": %s", ini_path, elog(ERROR, "cannot open INI file \"%s\": %s", ini_path,
strerror(errno)); strerror(errno));
/* configuration section */ /* configuration section */
@@ -416,7 +416,7 @@ catalog_read_ini(const char *path)
options[i++].var = &status; options[i++].var = &status;
Assert(i == lengthof(options) - 1); Assert(i == lengthof(options) - 1);
pgut_readopt(path, options, ERROR_CORRUPTED); pgut_readopt(path, options, ERROR);
if (backup_mode) if (backup_mode)
{ {
@@ -489,7 +489,7 @@ parse_backup_mode(const char *value)
return BACKUP_MODE_DIFF_PAGE; return BACKUP_MODE_DIFF_PAGE;
/* Backup mode is invalid, so leave with an error */ /* Backup mode is invalid, so leave with an error */
elog(ERROR_ARGS, "invalid backup-mode \"%s\"", value); elog(ERROR, "invalid backup-mode \"%s\"", value);
return BACKUP_MODE_INVALID; return BACKUP_MODE_INVALID;
} }
+23 -23
View File
@@ -96,7 +96,7 @@ backup_data_file(const char *from_root, const char *to_root,
if (errno == ENOENT) if (errno == ENOENT)
return false; return false;
elog(ERROR_SYSTEM, "cannot open backup mode file \"%s\": %s", elog(ERROR, "cannot open backup mode file \"%s\": %s",
file->path, strerror(errno)); file->path, strerror(errno));
} }
@@ -110,7 +110,7 @@ backup_data_file(const char *from_root, const char *to_root,
{ {
int errno_tmp = errno; int errno_tmp = errno;
fclose(in); fclose(in);
elog(ERROR_SYSTEM, "cannot open backup file \"%s\": %s", elog(ERROR, "cannot open backup file \"%s\": %s",
to_path, strerror(errno_tmp)); to_path, strerror(errno_tmp));
} }
@@ -169,7 +169,7 @@ backup_data_file(const char *from_root, const char *to_root,
/* oops */ /* oops */
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot write at block %u of \"%s\": %s", elog(ERROR, "cannot write at block %u of \"%s\": %s",
blknum, to_path, strerror(errno_tmp)); blknum, to_path, strerror(errno_tmp));
} }
@@ -198,7 +198,7 @@ backup_data_file(const char *from_root, const char *to_root,
{ {
ret = fseek(in, offset, SEEK_SET); ret = fseek(in, offset, SEEK_SET);
if (ret != 0) if (ret != 0)
elog(ERROR_PG_INCOMPATIBLE, elog(ERROR,
"Can't seek in file offset: %llu ret:%i\n", "Can't seek in file offset: %llu ret:%i\n",
(long long unsigned int) offset, ret); (long long unsigned int) offset, ret);
} }
@@ -238,7 +238,7 @@ backup_data_file(const char *from_root, const char *to_root,
/* oops */ /* oops */
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot write at block %u of \"%s\": %s", elog(ERROR, "cannot write at block %u of \"%s\": %s",
blknum, to_path, strerror(errno_tmp)); blknum, to_path, strerror(errno_tmp));
} }
@@ -261,7 +261,7 @@ backup_data_file(const char *from_root, const char *to_root,
int errno_tmp = errno; int errno_tmp = errno;
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot change mode of \"%s\": %s", file->path, elog(ERROR, "cannot change mode of \"%s\": %s", file->path,
strerror(errno_tmp)); strerror(errno_tmp));
} }
@@ -280,7 +280,7 @@ backup_data_file(const char *from_root, const char *to_root,
if (file->write_size == 0 && file->read_size > 0) if (file->write_size == 0 && file->read_size > 0)
{ {
if (remove(to_path) == -1) if (remove(to_path) == -1)
elog(ERROR_SYSTEM, "cannot remove file \"%s\": %s", to_path, elog(ERROR, "cannot remove file \"%s\": %s", to_path,
strerror(errno)); strerror(errno));
return false; return false;
} }
@@ -318,7 +318,7 @@ restore_data_file(const char *from_root,
in = fopen(file->path, "r"); in = fopen(file->path, "r");
if (in == NULL) if (in == NULL)
{ {
elog(ERROR_SYSTEM, "cannot open backup file \"%s\": %s", file->path, elog(ERROR, "cannot open backup file \"%s\": %s", file->path,
strerror(errno)); strerror(errno));
} }
@@ -335,7 +335,7 @@ restore_data_file(const char *from_root,
{ {
int errno_tmp = errno; int errno_tmp = errno;
fclose(in); fclose(in);
elog(ERROR_SYSTEM, "cannot open restore target file \"%s\": %s", elog(ERROR, "cannot open restore target file \"%s\": %s",
to_path, strerror(errno_tmp)); to_path, strerror(errno_tmp));
} }
@@ -355,13 +355,13 @@ restore_data_file(const char *from_root,
break; /* EOF found */ break; /* EOF found */
else if (read_len != 0 && feof(in)) else if (read_len != 0 && feof(in))
{ {
elog(ERROR_CORRUPTED, elog(ERROR,
"odd size page found at block %u of \"%s\"", "odd size page found at block %u of \"%s\"",
blknum, file->path); blknum, file->path);
} }
else else
{ {
elog(ERROR_SYSTEM, "cannot read block %u of \"%s\": %s", elog(ERROR, "cannot read block %u of \"%s\": %s",
blknum, file->path, strerror(errno_tmp)); blknum, file->path, strerror(errno_tmp));
} }
} }
@@ -374,7 +374,7 @@ restore_data_file(const char *from_root,
if (header.block < blknum || header.hole_offset > BLCKSZ || if (header.block < blknum || header.hole_offset > BLCKSZ ||
(int) header.hole_offset + (int) header.hole_length > BLCKSZ) (int) header.hole_offset + (int) header.hole_length > BLCKSZ)
{ {
elog(ERROR_CORRUPTED, "backup is broken at block %u", elog(ERROR, "backup is broken at block %u",
blknum); blknum);
} }
@@ -387,7 +387,7 @@ restore_data_file(const char *from_root,
if (fread(page.data, 1, header.hole_offset, in) != header.hole_offset || if (fread(page.data, 1, header.hole_offset, in) != header.hole_offset ||
fread(page.data + upper_offset, 1, upper_length, in) != upper_length) fread(page.data + upper_offset, 1, upper_length, in) != upper_length)
{ {
elog(ERROR_SYSTEM, "cannot read block %u of \"%s\": %s", elog(ERROR, "cannot read block %u of \"%s\": %s",
blknum, file->path, strerror(errno)); blknum, file->path, strerror(errno));
} }
@@ -397,10 +397,10 @@ restore_data_file(const char *from_root,
*/ */
blknum = header.block; blknum = header.block;
if (fseek(out, blknum * BLCKSZ, SEEK_SET) < 0) if (fseek(out, blknum * BLCKSZ, SEEK_SET) < 0)
elog(ERROR_SYSTEM, "cannot seek block %u of \"%s\": %s", elog(ERROR, "cannot seek block %u of \"%s\": %s",
blknum, to_path, strerror(errno)); blknum, to_path, strerror(errno));
if (fwrite(page.data, 1, sizeof(page), out) != sizeof(page)) if (fwrite(page.data, 1, sizeof(page), out) != sizeof(page))
elog(ERROR_SYSTEM, "cannot write block %u of \"%s\": %s", elog(ERROR, "cannot write block %u of \"%s\": %s",
blknum, file->path, strerror(errno)); blknum, file->path, strerror(errno));
} }
@@ -411,7 +411,7 @@ restore_data_file(const char *from_root,
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot change mode of \"%s\": %s", to_path, elog(ERROR, "cannot change mode of \"%s\": %s", to_path,
strerror(errno_tmp)); strerror(errno_tmp));
} }
@@ -448,7 +448,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
if (errno == ENOENT) if (errno == ENOENT)
return false; return false;
elog(ERROR_SYSTEM, "cannot open source file \"%s\": %s", file->path, elog(ERROR, "cannot open source file \"%s\": %s", file->path,
strerror(errno)); strerror(errno));
} }
@@ -462,7 +462,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
{ {
int errno_tmp = errno; int errno_tmp = errno;
fclose(in); fclose(in);
elog(ERROR_SYSTEM, "cannot open destination file \"%s\": %s", elog(ERROR, "cannot open destination file \"%s\": %s",
to_path, strerror(errno_tmp)); to_path, strerror(errno_tmp));
} }
@@ -471,7 +471,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
{ {
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot stat \"%s\": %s", file->path, elog(ERROR, "cannot stat \"%s\": %s", file->path,
strerror(errno)); strerror(errno));
} }
@@ -487,7 +487,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
/* oops */ /* oops */
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot write to \"%s\": %s", to_path, elog(ERROR, "cannot write to \"%s\": %s", to_path,
strerror(errno_tmp)); strerror(errno_tmp));
} }
/* update CRC */ /* update CRC */
@@ -502,7 +502,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
{ {
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot read backup mode file \"%s\": %s", elog(ERROR, "cannot read backup mode file \"%s\": %s",
file->path, strerror(errno_tmp)); file->path, strerror(errno_tmp));
} }
@@ -515,7 +515,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
/* oops */ /* oops */
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot write to \"%s\": %s", to_path, elog(ERROR, "cannot write to \"%s\": %s", to_path,
strerror(errno_tmp)); strerror(errno_tmp));
} }
/* update CRC */ /* update CRC */
@@ -535,7 +535,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
errno_tmp = errno; errno_tmp = errno;
fclose(in); fclose(in);
fclose(out); fclose(out);
elog(ERROR_SYSTEM, "cannot change mode of \"%s\": %s", to_path, elog(ERROR, "cannot change mode of \"%s\": %s", to_path,
strerror(errno_tmp)); strerror(errno_tmp));
} }
+5 -5
View File
@@ -26,20 +26,20 @@ do_delete(pgBackupRange *range)
/* DATE are always required */ /* DATE are always required */
if (!pgBackupRangeIsValid(range)) if (!pgBackupRangeIsValid(range))
elog(ERROR_ARGS, "required delete range option not specified: delete DATE"); elog(ERROR, "required delete range option not specified: delete DATE");
/* Lock backup catalog */ /* Lock backup catalog */
ret = catalog_lock(); ret = catalog_lock();
if (ret == -1) if (ret == -1)
elog(ERROR_SYSTEM, "can't lock backup catalog."); elog(ERROR, "can't lock backup catalog.");
else if (ret == 1) else if (ret == 1)
elog(ERROR_ALREADY_RUNNING, elog(ERROR,
"another pg_arman is running, stop delete."); "another pg_arman is running, stop delete.");
/* Get complete list of backups */ /* Get complete list of backups */
backup_list = catalog_get_backup_list(NULL); backup_list = catalog_get_backup_list(NULL);
if (!backup_list) if (!backup_list)
elog(ERROR_SYSTEM, "No backup list found, can't process any more."); elog(ERROR, "No backup list found, can't process any more.");
/* Find backups to be deleted */ /* Find backups to be deleted */
for (i = 0; i < parray_num(backup_list); i++) for (i = 0; i < parray_num(backup_list); i++)
@@ -51,7 +51,7 @@ do_delete(pgBackupRange *range)
{ {
/* check for interrupt */ /* check for interrupt */
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, "interrupted during delete backup"); elog(ERROR, "interrupted during delete backup");
pgBackupDeleteFiles(backup); pgBackupDeleteFiles(backup);
continue; continue;
+13 -13
View File
@@ -56,7 +56,7 @@ dir_create_dir(const char *dir, mode_t mode)
{ {
if (errno == EEXIST) /* already exist */ if (errno == EEXIST) /* already exist */
return 0; return 0;
elog(ERROR_SYSTEM, "cannot create directory \"%s\": %s", dir, elog(ERROR, "cannot create directory \"%s\": %s", dir,
strerror(errno)); strerror(errno));
} }
@@ -75,7 +75,7 @@ pgFileNew(const char *path, bool omit_symlink)
/* file not found is not an error case */ /* file not found is not an error case */
if (errno == ENOENT) if (errno == ENOENT)
return NULL; return NULL;
elog(ERROR_SYSTEM, "cannot stat file \"%s\": %s", path, elog(ERROR, "cannot stat file \"%s\": %s", path,
strerror(errno)); strerror(errno));
} }
@@ -113,7 +113,7 @@ pgFileDelete(pgFile *file)
else if (errno == ENOTDIR) /* could be symbolic link */ else if (errno == ENOTDIR) /* could be symbolic link */
goto delete_file; goto delete_file;
elog(ERROR_SYSTEM, "cannot remove directory \"%s\": %s", elog(ERROR, "cannot remove directory \"%s\": %s",
file->path, strerror(errno)); file->path, strerror(errno));
} }
return; return;
@@ -124,7 +124,7 @@ delete_file:
{ {
if (errno == ENOENT) if (errno == ENOENT)
return; return;
elog(ERROR_SYSTEM, "cannot remove file \"%s\": %s", file->path, elog(ERROR, "cannot remove file \"%s\": %s", file->path,
strerror(errno)); strerror(errno));
} }
} }
@@ -141,7 +141,7 @@ pgFileGetCRC(pgFile *file)
/* open file in binary read mode */ /* open file in binary read mode */
fp = fopen(file->path, "r"); fp = fopen(file->path, "r");
if (fp == NULL) if (fp == NULL)
elog(ERROR_SYSTEM, "cannot open file \"%s\": %s", elog(ERROR, "cannot open file \"%s\": %s",
file->path, strerror(errno)); file->path, strerror(errno));
/* calc CRC of backup file */ /* calc CRC of backup file */
@@ -149,7 +149,7 @@ pgFileGetCRC(pgFile *file)
while ((len = fread(buf, 1, sizeof(buf), fp)) == sizeof(buf)) while ((len = fread(buf, 1, sizeof(buf), fp)) == sizeof(buf))
{ {
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, "interrupted during CRC calculation"); elog(ERROR, "interrupted during CRC calculation");
COMP_CRC32C(crc, buf, len); COMP_CRC32C(crc, buf, len);
} }
errno_tmp = errno; errno_tmp = errno;
@@ -246,7 +246,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
black_list = parray_new(); black_list = parray_new();
black_list_file = fopen(path, "r"); black_list_file = fopen(path, "r");
if (black_list_file == NULL) if (black_list_file == NULL)
elog(ERROR_SYSTEM, "cannot open black_list: %s", elog(ERROR, "cannot open black_list: %s",
strerror(errno)); strerror(errno));
while (fgets(buf, lengthof(buf), black_list_file) != NULL) while (fgets(buf, lengthof(buf), black_list_file) != NULL)
{ {
@@ -294,7 +294,7 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
len = readlink(file->path, linked, sizeof(linked)); len = readlink(file->path, linked, sizeof(linked));
if (len == -1) if (len == -1)
{ {
elog(ERROR_SYSTEM, "cannot read link \"%s\": %s", file->path, elog(ERROR, "cannot read link \"%s\": %s", file->path,
strerror(errno)); strerror(errno));
} }
linked[len] = '\0'; linked[len] = '\0';
@@ -376,7 +376,7 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
/* maybe the direcotry was removed */ /* maybe the direcotry was removed */
return; return;
} }
elog(ERROR_SYSTEM, "cannot open directory \"%s\": %s", elog(ERROR, "cannot open directory \"%s\": %s",
file->path, strerror(errno)); file->path, strerror(errno));
} }
@@ -397,7 +397,7 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
{ {
int errno_tmp = errno; int errno_tmp = errno;
closedir(dir); closedir(dir);
elog(ERROR_SYSTEM, "cannot read directory \"%s\": %s", elog(ERROR, "cannot read directory \"%s\": %s",
file->path, strerror(errno_tmp)); file->path, strerror(errno_tmp));
} }
closedir(dir); closedir(dir);
@@ -514,7 +514,7 @@ dir_read_file_list(const char *root, const char *file_txt)
fp = fopen(file_txt, "rt"); fp = fopen(file_txt, "rt");
if (fp == NULL) if (fp == NULL)
elog(errno == ENOENT ? ERROR_CORRUPTED : ERROR_SYSTEM, elog(errno == ENOENT ? ERROR : ERROR,
"cannot open \"%s\": %s", file_txt, strerror(errno)); "cannot open \"%s\": %s", file_txt, strerror(errno));
files = parray_new(); files = parray_new();
@@ -535,12 +535,12 @@ dir_read_file_list(const char *root, const char *file_txt)
&tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 11) &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 11)
{ {
elog(ERROR_CORRUPTED, "invalid format found in \"%s\"", elog(ERROR, "invalid format found in \"%s\"",
file_txt); file_txt);
} }
if (type != 'f' && type != 'F' && type != 'd' && type != 'l') if (type != 'f' && type != 'F' && type != 'd' && type != 'l')
{ {
elog(ERROR_CORRUPTED, "invalid type '%c' found in \"%s\"", elog(ERROR, "invalid type '%c' found in \"%s\"",
type, file_txt); type, file_txt);
} }
tm.tm_isdst = -1; tm.tm_isdst = -1;
+3 -18
View File
@@ -370,24 +370,9 @@ pg_arman returns exit codes for each error status.
Code Name Description Code Name Description
0 SUCCESS Operation succeeded. 0 SUCCESS Operation succeeded.
1 HELP Print help, then exit 1 ERROR Generic error
2 ERROR Generic error 2 FATAL Exit because of repeated errors
3 FATAL Exit because of repeated errors 3 PANIC Unknown critical condition
4 PANIC Unknown critical condition
10 ERROR_SYSTEM I/O or system error
11 ERROR_NOMEM Out of memory
12 ERROR_ARGS Invalid input parameters
13 ERROR_INTERRUPTED Interrupted by user (Ctrl+C etc.)
14 ERROR_PG_COMMAND SQL error
15 ERROR_PG_CONNECT Cannot connect to PostgreSQL server
20 ERROR_ARCHIVE_FAILED Cannot archive WAL file
21 ERROR_NO_BACKUP Backup file not found
22 ERROR_CORRUPTED Backup file is broken
23 ERROR_ALREADY_RUNNING Cannot start because another pg_arman
is running
24 ERROR_PG_INCOMPATIBLE Version conflicted with server
25 ERROR_PG_RUNNING Error due to server running
26 ERROR_PID_BROKEN postmaster.pid is broken
== AUTHOR == == AUTHOR ==
pg_arman is a fork of pg_arman that was originally written by NTT, now pg_arman is a fork of pg_arman that was originally written by NTT, now
+1 -1
View File
@@ -29,6 +29,6 @@ Number of deleted backups : 2
###### BACKUP COMMAND TEST-0005 ###### ###### BACKUP COMMAND TEST-0005 ######
###### switch backup mode from page to full ###### ###### switch backup mode from page to full ######
page-level backup without validated full backup page-level backup without validated full backup
10 1
0 0
0 0
+2 -2
View File
@@ -24,10 +24,10 @@ results/init/backup/pg_arman.ini
###### INIT COMMAND TEST-0004 ###### ###### INIT COMMAND TEST-0004 ######
###### failure with backup catalog already existed ###### ###### failure with backup catalog already existed ######
ERROR: backup catalog already exist. and it's not empty ERROR: backup catalog already exist. and it's not empty
2 1
###### INIT COMMAND TEST-0005 ###### ###### INIT COMMAND TEST-0005 ######
###### failure with backup catalog should be given as absolute path ###### ###### failure with backup catalog should be given as absolute path ######
ERROR: -B, --backup-path must be an absolute path ERROR: -B, --backup-path must be an absolute path
12 1
+11 -11
View File
@@ -59,56 +59,56 @@ pg_arman 0.1
###### COMMAND OPTION TEST-0003 ###### ###### COMMAND OPTION TEST-0003 ######
###### backup command failure without backup path option ###### ###### backup command failure without backup path option ######
ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path) ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path)
12 1
###### COMMAND OPTION TEST-0004 ###### ###### COMMAND OPTION TEST-0004 ######
###### backup command failure without backup mode option ###### ###### backup command failure without backup mode option ######
ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode) ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode)
12 1
###### COMMAND OPTION TEST-0005 ###### ###### COMMAND OPTION TEST-0005 ######
###### backup command failure with invalid backup mode option ###### ###### backup command failure with invalid backup mode option ######
ERROR: invalid backup-mode "bad" ERROR: invalid backup-mode "bad"
12 1
###### COMMAND OPTION TEST-0006 ###### ###### COMMAND OPTION TEST-0006 ######
###### delete failure without archive path ###### ###### delete failure without archive path ######
ERROR: delete command needs ARCLOG_PATH (-A, --arclog-path) to be set ERROR: delete command needs ARCLOG_PATH (-A, --arclog-path) to be set
12 1
###### COMMAND OPTION TEST-0007 ###### ###### COMMAND OPTION TEST-0007 ######
###### delete failure without DATE ###### ###### delete failure without DATE ######
ERROR: required delete range option not specified: delete DATE ERROR: required delete range option not specified: delete DATE
12 1
###### COMMAND OPTION TEST-0008 ###### ###### COMMAND OPTION TEST-0008 ######
###### syntax error in pg_arman.ini ###### ###### syntax error in pg_arman.ini ######
WARNING: syntax error in " = INFINITE" WARNING: syntax error in " = INFINITE"
ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode) ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode)
12 1
###### COMMAND OPTION TEST-0009 ###### ###### COMMAND OPTION TEST-0009 ######
###### invalid value in pg_arman.ini ###### ###### invalid value in pg_arman.ini ######
ERROR: invalid backup-mode "" ERROR: invalid backup-mode ""
12 1
###### COMMAND OPTION TEST-0010 ###### ###### COMMAND OPTION TEST-0010 ######
###### invalid value in pg_arman.ini ###### ###### invalid value in pg_arman.ini ######
ERROR: option --keep-data-generations should be a 32bit signed integer: 'TRUE' ERROR: option --keep-data-generations should be a 32bit signed integer: 'TRUE'
12 1
###### COMMAND OPTION TEST-0011 ###### ###### COMMAND OPTION TEST-0011 ######
###### invalid value in pg_arman.ini ###### ###### invalid value in pg_arman.ini ######
ERROR: option -C, --smooth-checkpoint should be a boolean: 'FOO' ERROR: option -C, --smooth-checkpoint should be a boolean: 'FOO'
12 1
###### COMMAND OPTION TEST-0012 ###### ###### COMMAND OPTION TEST-0012 ######
###### invalid option in pg_arman.ini ###### ###### invalid option in pg_arman.ini ######
ERROR: invalid option "TIMELINEID" ERROR: invalid option "TIMELINEID"
12 1
###### COMMAND OPTION TEST-0013 ###### ###### COMMAND OPTION TEST-0013 ######
###### check priority of several pg_arman.ini files ###### ###### check priority of several pg_arman.ini files ######
ERROR: invalid backup-mode "ENV_PATH" ERROR: invalid backup-mode "ENV_PATH"
12 1
+3 -3
View File
@@ -43,11 +43,11 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
snprintf(fullpath, sizeof(fullpath), "%s/%s", datadir, path); snprintf(fullpath, sizeof(fullpath), "%s/%s", datadir, path);
if ((fd = open(fullpath, O_RDONLY | PG_BINARY, 0)) == -1) if ((fd = open(fullpath, O_RDONLY | PG_BINARY, 0)) == -1)
elog(ERROR_CORRUPTED, "could not open file \"%s\" for reading: %s", elog(ERROR, "could not open file \"%s\" for reading: %s",
fullpath, strerror(errno)); fullpath, strerror(errno));
if (fstat(fd, &statbuf) < 0) if (fstat(fd, &statbuf) < 0)
elog(ERROR_CORRUPTED, "could not open file \"%s\" for reading: %s", elog(ERROR, "could not open file \"%s\" for reading: %s",
fullpath, strerror(errno)); fullpath, strerror(errno));
len = statbuf.st_size; len = statbuf.st_size;
@@ -55,7 +55,7 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
buffer = pg_malloc(len + 1); buffer = pg_malloc(len + 1);
if (read(fd, buffer, len) != len) if (read(fd, buffer, len) != len)
elog(ERROR_CORRUPTED, "could not read file \"%s\": %s\n", elog(ERROR, "could not read file \"%s\": %s\n",
fullpath, strerror(errno)); fullpath, strerror(errno));
close(fd); close(fd);
+1 -1
View File
@@ -64,7 +64,7 @@ do_init(void)
join_path_components(path, backup_path, PG_RMAN_INI_FILE); join_path_components(path, backup_path, PG_RMAN_INI_FILE);
fp = fopen(path, "wt"); fp = fopen(path, "wt");
if (fp == NULL) if (fp == NULL)
elog(ERROR_SYSTEM, "cannot create pg_arman.ini: %s", strerror(errno)); elog(ERROR, "cannot create pg_arman.ini: %s", strerror(errno));
/* set ARCLOG_PATH refered with log_directory */ /* set ARCLOG_PATH refered with log_directory */
if (arclog_path == NULL && archive_command && archive_command[0]) if (arclog_path == NULL && archive_command && archive_command[0])
+13 -13
View File
@@ -102,14 +102,14 @@ main(int argc, char *argv[])
else if (range2 == NULL) else if (range2 == NULL)
range2 = argv[i]; range2 = argv[i];
else else
elog(ERROR_ARGS, "too many arguments"); elog(ERROR, "too many arguments");
} }
/* command argument (backup/restore/show/...) is required. */ /* command argument (backup/restore/show/...) is required. */
if (cmd == NULL) if (cmd == NULL)
{ {
help(false); help(false);
return HELP; return 1;
} }
/* get object range argument if any */ /* get object range argument if any */
@@ -130,27 +130,27 @@ main(int argc, char *argv[])
/* If rc == -1, there is no file or directory. So it's OK. */ /* If rc == -1, there is no file or directory. So it's OK. */
if (rc != -1 && !S_ISDIR(stat_buf.st_mode)) if (rc != -1 && !S_ISDIR(stat_buf.st_mode))
elog(ERROR_ARGS, "-B, --backup-path must be a path to directory"); elog(ERROR, "-B, --backup-path must be a path to directory");
join_path_components(path, backup_path, PG_RMAN_INI_FILE); join_path_components(path, backup_path, PG_RMAN_INI_FILE);
pgut_readopt(path, options, ERROR_ARGS); pgut_readopt(path, options, ERROR);
} }
/* BACKUP_PATH is always required */ /* BACKUP_PATH is always required */
if (backup_path == NULL) if (backup_path == NULL)
elog(ERROR_ARGS, "required parameter not specified: BACKUP_PATH (-B, --backup-path)"); elog(ERROR, "required parameter not specified: BACKUP_PATH (-B, --backup-path)");
/* path must be absolute */ /* path must be absolute */
if (backup_path != NULL && !is_absolute_path(backup_path)) if (backup_path != NULL && !is_absolute_path(backup_path))
elog(ERROR_ARGS, "-B, --backup-path must be an absolute path"); elog(ERROR, "-B, --backup-path must be an absolute path");
if (pgdata != NULL && !is_absolute_path(pgdata)) if (pgdata != NULL && !is_absolute_path(pgdata))
elog(ERROR_ARGS, "-D, --pgdata must be an absolute path"); elog(ERROR, "-D, --pgdata must be an absolute path");
if (arclog_path != NULL && !is_absolute_path(arclog_path)) if (arclog_path != NULL && !is_absolute_path(arclog_path))
elog(ERROR_ARGS, "-A, --arclog-path must be an absolute path"); elog(ERROR, "-A, --arclog-path must be an absolute path");
/* Sanity checks with commands */ /* Sanity checks with commands */
if (pg_strcasecmp(cmd, "delete") == 0 && arclog_path == NULL) if (pg_strcasecmp(cmd, "delete") == 0 && arclog_path == NULL)
elog(ERROR_ARGS, "delete command needs ARCLOG_PATH (-A, --arclog-path) to be set"); elog(ERROR, "delete command needs ARCLOG_PATH (-A, --arclog-path) to be set");
/* setup exclusion list for file search */ /* setup exclusion list for file search */
for (i = 0; pgdata_exclude[i]; i++) /* find first empty slot */ for (i = 0; pgdata_exclude[i]; i++) /* find first empty slot */
@@ -190,7 +190,7 @@ main(int argc, char *argv[])
else if (pg_strcasecmp(cmd, "delete") == 0) else if (pg_strcasecmp(cmd, "delete") == 0)
return do_delete(&range); return do_delete(&range);
else else
elog(ERROR_ARGS, "invalid command \"%s\"", cmd); elog(ERROR, "invalid command \"%s\"", cmd);
return 0; return 0;
} }
@@ -264,9 +264,9 @@ parse_range(pgBackupRange *range, const char *arg1, const char *arg2)
if (num < 1) if (num < 1)
{ {
if (strcmp(tmp,"") != 0) if (strcmp(tmp,"") != 0)
elog(ERROR_ARGS, "supplied id(%s) is invalid", tmp); elog(ERROR, "supplied id(%s) is invalid", tmp);
else else
elog(ERROR_ARGS, "arguments are invalid. near \"%s\"", arg1); elog(ERROR, "arguments are invalid. near \"%s\"", arg1);
} }
free(tmp); free(tmp);
@@ -278,7 +278,7 @@ parse_range(pgBackupRange *range, const char *arg1, const char *arg2)
tm.tm_isdst = -1; tm.tm_isdst = -1;
if (!IsValidTime(tm)) if (!IsValidTime(tm))
elog(ERROR_ARGS, "supplied time(%s) is invalid.", arg1); elog(ERROR, "supplied time(%s) is invalid.", arg1);
range->begin = mktime(&tm); range->begin = mktime(&tm);
-9
View File
@@ -41,15 +41,6 @@
#define DIR_PERMISSION (0700) #define DIR_PERMISSION (0700)
#define FILE_PERMISSION (0600) #define FILE_PERMISSION (0600)
/* Exit code */
#define ERROR_ARCHIVE_FAILED 20 /* cannot archive xlog file */
#define ERROR_NO_BACKUP 21 /* backup was not found in the catalog */
#define ERROR_CORRUPTED 22 /* backup catalog is corrupted */
#define ERROR_ALREADY_RUNNING 23 /* another pg_arman is running */
#define ERROR_PG_INCOMPATIBLE 24 /* block size is not compatible */
#define ERROR_PG_RUNNING 25 /* PostgreSQL server is running */
#define ERROR_PID_BROKEN 26 /* postmaster.pid file is broken */
/* backup mode file */ /* backup mode file */
typedef struct pgFile typedef struct pgFile
{ {
+17 -17
View File
@@ -150,7 +150,7 @@ assign_option(pgut_option *opt, const char *optarg, pgut_optsrc src)
if (opt == NULL) if (opt == NULL)
{ {
fprintf(stderr, "Try \"%s --help\" for more information.\n", PROGRAM_NAME); fprintf(stderr, "Try \"%s --help\" for more information.\n", PROGRAM_NAME);
exit_or_abort(ERROR_ARGS); exit_or_abort(ERROR);
} }
if (opt->source > src) if (opt->source > src)
@@ -241,10 +241,10 @@ assign_option(pgut_option *opt, const char *optarg, pgut_optsrc src)
} }
if (isprint(opt->sname)) if (isprint(opt->sname))
elog(ERROR_ARGS, "option -%c, --%s should be %s: '%s'", elog(ERROR, "option -%c, --%s should be %s: '%s'",
opt->sname, opt->lname, message, optarg); opt->sname, opt->lname, message, optarg);
else else
elog(ERROR_ARGS, "option --%s should be %s: '%s'", elog(ERROR, "option --%s should be %s: '%s'",
opt->lname, message, optarg); opt->lname, message, optarg);
} }
@@ -605,12 +605,12 @@ pgut_getopt(int argc, char **argv, pgut_option options[])
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{ {
help(true); help(true);
exit_or_abort(HELP); exit_or_abort(1);
} }
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
{ {
fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION); fprintf(stderr, "%s %s\n", PROGRAM_NAME, PROGRAM_VERSION);
exit_or_abort(HELP); exit_or_abort(1);
} }
} }
@@ -887,7 +887,7 @@ pgut_connect(int elevel)
PGconn *conn; PGconn *conn;
if (interrupted && !in_cleanup) if (interrupted && !in_cleanup)
elog(ERROR_INTERRUPTED, "interrupted"); elog(ERROR, "interrupted");
#ifndef PGUT_NO_PROMPT #ifndef PGUT_NO_PROMPT
if (prompt_password == YES) if (prompt_password == YES)
@@ -940,7 +940,7 @@ reconnect_elevel(int elevel)
void void
reconnect(void) reconnect(void)
{ {
reconnect_elevel(ERROR_PG_CONNECT); reconnect_elevel(ERROR);
} }
void void
@@ -984,7 +984,7 @@ pgut_execute(PGconn* conn, const char *query, int nParams, const char **params,
PGresult *res; PGresult *res;
if (interrupted && !in_cleanup) if (interrupted && !in_cleanup)
elog(ERROR_INTERRUPTED, "interrupted"); elog(ERROR, "interrupted");
/* write query to elog if verbose */ /* write query to elog if verbose */
if (verbose) if (verbose)
@@ -1039,7 +1039,7 @@ pgut_send(PGconn* conn, const char *query, int nParams, const char **params, int
int res; int res;
if (interrupted && !in_cleanup) if (interrupted && !in_cleanup)
elog(ERROR_INTERRUPTED, "interrupted"); elog(ERROR, "interrupted");
/* write query to elog if verbose */ /* write query to elog if verbose */
if (verbose) if (verbose)
@@ -1141,7 +1141,7 @@ execute_elevel(const char *query, int nParams, const char **params, int elevel)
PGresult * PGresult *
execute(const char *query, int nParams, const char **params) execute(const char *query, int nParams, const char **params)
{ {
return execute_elevel(query, nParams, params, ERROR_PG_COMMAND); return execute_elevel(query, nParams, params, ERROR);
} }
/* /*
@@ -1433,7 +1433,7 @@ get_username(void)
#endif #endif
if (ret == NULL) if (ret == NULL)
elog(ERROR_SYSTEM, "%s: could not get current user name: %s", elog(ERROR, "%s: could not get current user name: %s",
PROGRAM_NAME, strerror(errno)); PROGRAM_NAME, strerror(errno));
return ret; return ret;
} }
@@ -1498,7 +1498,7 @@ pgut_malloc(size_t size)
char *ret; char *ret;
if ((ret = malloc(size)) == NULL) if ((ret = malloc(size)) == NULL)
elog(ERROR_NOMEM, "could not allocate memory (%lu bytes): %s", elog(ERROR, "could not allocate memory (%lu bytes): %s",
(unsigned long) size, strerror(errno)); (unsigned long) size, strerror(errno));
return ret; return ret;
} }
@@ -1509,7 +1509,7 @@ pgut_realloc(void *p, size_t size)
char *ret; char *ret;
if ((ret = realloc(p, size)) == NULL) if ((ret = realloc(p, size)) == NULL)
elog(ERROR_NOMEM, "could not re-allocate memory (%lu bytes): %s", elog(ERROR, "could not re-allocate memory (%lu bytes): %s",
(unsigned long) size, strerror(errno)); (unsigned long) size, strerror(errno));
return ret; return ret;
} }
@@ -1523,7 +1523,7 @@ pgut_strdup(const char *str)
return NULL; return NULL;
if ((ret = strdup(str)) == NULL) if ((ret = strdup(str)) == NULL)
elog(ERROR_NOMEM, "could not duplicate string \"%s\": %s", elog(ERROR, "could not duplicate string \"%s\": %s",
str, strerror(errno)); str, strerror(errno));
return ret; return ret;
} }
@@ -1568,7 +1568,7 @@ pgut_fopen(const char *path, const char *mode, bool missing_ok)
if (missing_ok && errno == ENOENT) if (missing_ok && errno == ENOENT)
return NULL; return NULL;
elog(ERROR_SYSTEM, "could not open file \"%s\": %s", elog(ERROR, "could not open file \"%s\": %s",
path, strerror(errno)); path, strerror(errno));
} }
@@ -1601,9 +1601,9 @@ wait_for_sockets(int nfds, fd_set *fds, struct timeval *timeout)
if (i < 0) if (i < 0)
{ {
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, "interrupted"); elog(ERROR, "interrupted");
else if (errno != EINTR) else if (errno != EINTR)
elog(ERROR_SYSTEM, "select failed: %s", strerror(errno)); elog(ERROR, "select failed: %s", strerror(errno));
} }
else else
return i; return i;
+3 -11
View File
@@ -155,17 +155,9 @@ extern FILE *pgut_fopen(const char *path, const char *mode, bool missing_ok);
#define INFO (-3) #define INFO (-3)
#define NOTICE (-2) #define NOTICE (-2)
#define WARNING (-1) #define WARNING (-1)
#define HELP 1 #define ERROR 1
#define ERROR 2 #define FATAL 2
#define FATAL 3 #define PANIC 3
#define PANIC 4
#define ERROR_SYSTEM 10 /* I/O or system error */
#define ERROR_NOMEM 11 /* memory exhausted */
#define ERROR_ARGS 12 /* some configurations are invalid */
#define ERROR_INTERRUPTED 13 /* interrupted by signal */
#define ERROR_PG_COMMAND 14 /* PostgreSQL query or command error */
#define ERROR_PG_CONNECT 15 /* PostgreSQL connection error */
#undef elog #undef elog
extern void extern void
+27 -27
View File
@@ -57,10 +57,10 @@ do_restore(const char *target_time,
/* PGDATA and ARCLOG_PATH are always required */ /* PGDATA and ARCLOG_PATH are always required */
if (pgdata == NULL) if (pgdata == NULL)
elog(ERROR_ARGS, elog(ERROR,
"required parameter not specified: PGDATA (-D, --pgdata)"); "required parameter not specified: PGDATA (-D, --pgdata)");
if (arclog_path == NULL) if (arclog_path == NULL)
elog(ERROR_ARGS, elog(ERROR,
"required parameter not specified: ARCLOG_PATH (-A, --arclog-path)"); "required parameter not specified: ARCLOG_PATH (-A, --arclog-path)");
elog(LOG, "========================================"); elog(LOG, "========================================");
@@ -69,23 +69,23 @@ do_restore(const char *target_time,
/* get exclusive lock of backup catalog */ /* get exclusive lock of backup catalog */
ret = catalog_lock(); ret = catalog_lock();
if (ret == -1) if (ret == -1)
elog(ERROR_SYSTEM, "cannot lock backup catalog."); elog(ERROR, "cannot lock backup catalog.");
else if (ret == 1) else if (ret == 1)
elog(ERROR_ALREADY_RUNNING, elog(ERROR,
"another pg_arman is running, stop restore."); "another pg_arman is running, stop restore.");
/* confirm the PostgreSQL server is not running */ /* confirm the PostgreSQL server is not running */
if (is_pg_running()) if (is_pg_running())
elog(ERROR_PG_RUNNING, "PostgreSQL server is running"); elog(ERROR, "PostgreSQL server is running");
rt = checkIfCreateRecoveryConf(target_time, target_xid, target_inclusive); rt = checkIfCreateRecoveryConf(target_time, target_xid, target_inclusive);
if (rt == NULL) if (rt == NULL)
elog(ERROR_ARGS, "cannot create recovery.conf. specified args are invalid."); elog(ERROR, "cannot create recovery.conf. specified args are invalid.");
/* get list of backups. (index == 0) is the last backup */ /* get list of backups. (index == 0) is the last backup */
backups = catalog_get_backup_list(NULL); backups = catalog_get_backup_list(NULL);
if (!backups) if (!backups)
elog(ERROR_SYSTEM, "cannot process any more."); elog(ERROR, "cannot process any more.");
cur_tli = get_current_timeline(); cur_tli = get_current_timeline();
backup_tli = get_fullbackup_timeline(backups, rt); backup_tli = get_fullbackup_timeline(backups, rt);
@@ -141,7 +141,7 @@ do_restore(const char *target_time,
goto base_backup_found; goto base_backup_found;
} }
/* no full backup found, cannot restore */ /* no full backup found, cannot restore */
elog(ERROR_NO_BACKUP, "no full backup found, cannot restore."); elog(ERROR, "no full backup found, cannot restore.");
base_backup_found: base_backup_found:
base_index = i; base_index = i;
@@ -232,11 +232,11 @@ restore_database(pgBackup *backup)
/* confirm block size compatibility */ /* confirm block size compatibility */
if (backup->block_size != BLCKSZ) if (backup->block_size != BLCKSZ)
elog(ERROR_PG_INCOMPATIBLE, elog(ERROR,
"BLCKSZ(%d) is not compatible(%d expected)", "BLCKSZ(%d) is not compatible(%d expected)",
backup->block_size, BLCKSZ); backup->block_size, BLCKSZ);
if (backup->wal_block_size != XLOG_BLCKSZ) if (backup->wal_block_size != XLOG_BLCKSZ)
elog(ERROR_PG_INCOMPATIBLE, elog(ERROR,
"XLOG_BLCKSZ(%d) is not compatible(%d expected)", "XLOG_BLCKSZ(%d) is not compatible(%d expected)",
backup->wal_block_size, XLOG_BLCKSZ); backup->wal_block_size, XLOG_BLCKSZ);
@@ -261,7 +261,7 @@ restore_database(pgBackup *backup)
/* keep orginal directory */ /* keep orginal directory */
if (getcwd(pwd, sizeof(pwd)) == NULL) if (getcwd(pwd, sizeof(pwd)) == NULL)
elog(ERROR_SYSTEM, "cannot get current working directory: %s", elog(ERROR, "cannot get current working directory: %s",
strerror(errno)); strerror(errno));
/* create pgdata directory */ /* create pgdata directory */
@@ -269,18 +269,18 @@ restore_database(pgBackup *backup)
/* change directory to pgdata */ /* change directory to pgdata */
if (chdir(pgdata)) if (chdir(pgdata))
elog(ERROR_SYSTEM, "cannot change directory: %s", elog(ERROR, "cannot change directory: %s",
strerror(errno)); strerror(errno));
/* Execute mkdirs.sh */ /* Execute mkdirs.sh */
ret = system(path); ret = system(path);
if (ret != 0) if (ret != 0)
elog(ERROR_SYSTEM, "cannot execute mkdirs.sh: %s", elog(ERROR, "cannot execute mkdirs.sh: %s",
strerror(errno)); strerror(errno));
/* go back to original directory */ /* go back to original directory */
if (chdir(pwd)) if (chdir(pwd))
elog(ERROR_SYSTEM, "cannot change directory: %s", elog(ERROR, "cannot change directory: %s",
strerror(errno)); strerror(errno));
} }
@@ -309,7 +309,7 @@ restore_database(pgBackup *backup)
/* check for interrupt */ /* check for interrupt */
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, "interrupted during restore database"); elog(ERROR, "interrupted during restore database");
/* print progress */ /* print progress */
if (!check) if (!check)
@@ -378,7 +378,7 @@ restore_database(pgBackup *backup)
/* remove postmaster.pid */ /* remove postmaster.pid */
snprintf(path, lengthof(path), "%s/postmaster.pid", pgdata); snprintf(path, lengthof(path), "%s/postmaster.pid", pgdata);
if (remove(path) == -1 && errno != ENOENT) if (remove(path) == -1 && errno != ENOENT)
elog(ERROR_SYSTEM, "cannot remove postmaster.pid: %s", elog(ERROR, "cannot remove postmaster.pid: %s",
strerror(errno)); strerror(errno));
/* cleanup */ /* cleanup */
@@ -410,7 +410,7 @@ create_recovery_conf(const char *target_time,
snprintf(path, lengthof(path), "%s/recovery.conf", pgdata); snprintf(path, lengthof(path), "%s/recovery.conf", pgdata);
fp = fopen(path, "wt"); fp = fopen(path, "wt");
if (fp == NULL) if (fp == NULL)
elog(ERROR_SYSTEM, "cannot open recovery.conf \"%s\": %s", path, elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
strerror(errno)); strerror(errno));
fprintf(fp, "# recovery.conf generated by pg_arman %s\n", fprintf(fp, "# recovery.conf generated by pg_arman %s\n",
@@ -497,7 +497,7 @@ readTimeLineHistory(TimeLineID targetTLI)
if (fd == NULL) if (fd == NULL)
{ {
if (errno != ENOENT) if (errno != ENOENT)
elog(ERROR_SYSTEM, "could not open file \"%s\": %s", path, elog(ERROR, "could not open file \"%s\": %s", path,
strerror(errno)); strerror(errno));
/* search from restore work directory next */ /* search from restore work directory next */
@@ -507,7 +507,7 @@ readTimeLineHistory(TimeLineID targetTLI)
if (fd == NULL) if (fd == NULL)
{ {
if (errno != ENOENT) if (errno != ENOENT)
elog(ERROR_SYSTEM, "could not open file \"%s\": %s", path, elog(ERROR, "could not open file \"%s\": %s", path,
strerror(errno)); strerror(errno));
} }
} }
@@ -544,17 +544,17 @@ readTimeLineHistory(TimeLineID targetTLI)
if (nfields < 1) if (nfields < 1)
{ {
/* expect a numeric timeline ID as first field of line */ /* expect a numeric timeline ID as first field of line */
elog(ERROR_CORRUPTED, elog(ERROR,
"syntax error in history file: %s. Expected a numeric timeline ID.", "syntax error in history file: %s. Expected a numeric timeline ID.",
fline); fline);
} }
if (nfields != 3) if (nfields != 3)
elog(ERROR_CORRUPTED, elog(ERROR,
"syntax error in history file: %s. Expected a transaction log switchpoint location.", "syntax error in history file: %s. Expected a transaction log switchpoint location.",
fline); fline);
if (last_timeline && timeline->tli <= last_timeline->tli) if (last_timeline && timeline->tli <= last_timeline->tli)
elog(ERROR_CORRUPTED, elog(ERROR,
"Timeline IDs must be in increasing sequence."); "Timeline IDs must be in increasing sequence.");
/* Build list with newest item first */ /* Build list with newest item first */
@@ -570,7 +570,7 @@ readTimeLineHistory(TimeLineID targetTLI)
fclose(fd); fclose(fd);
if (last_timeline && targetTLI <= last_timeline->tli) if (last_timeline && targetTLI <= last_timeline->tli)
elog(ERROR_CORRUPTED, elog(ERROR,
"Timeline IDs must be less than child timeline's ID."); "Timeline IDs must be less than child timeline's ID.");
/* append target timeline */ /* append target timeline */
@@ -654,7 +654,7 @@ get_fullbackup_timeline(parray *backups, const pgRecoveryTarget *rt)
} }
/* no full backup found, cannot restore */ /* no full backup found, cannot restore */
if (i == parray_num(backups)) if (i == parray_num(backups))
elog(ERROR_NO_BACKUP, "no full backup found, cannot restore."); elog(ERROR, "no full backup found, cannot restore.");
ret = base_backup->tli; ret = base_backup->tli;
@@ -759,7 +759,7 @@ checkIfCreateRecoveryConf(const char *target_time,
if (parse_time(target_time, &dummy_time)) if (parse_time(target_time, &dummy_time))
rt->recovery_target_time = dummy_time; rt->recovery_target_time = dummy_time;
else else
elog(ERROR_ARGS, "cannot create recovery.conf with %s", target_time); elog(ERROR, "cannot create recovery.conf with %s", target_time);
} }
if (target_xid) if (target_xid)
{ {
@@ -767,14 +767,14 @@ checkIfCreateRecoveryConf(const char *target_time,
if (parse_uint32(target_xid, &dummy_xid)) if (parse_uint32(target_xid, &dummy_xid))
rt->recovery_target_xid = dummy_xid; rt->recovery_target_xid = dummy_xid;
else else
elog(ERROR_ARGS, "cannot create recovery.conf with %s", target_xid); elog(ERROR, "cannot create recovery.conf with %s", target_xid);
} }
if (target_inclusive) if (target_inclusive)
{ {
if (parse_bool(target_inclusive, &dummy_bool)) if (parse_bool(target_inclusive, &dummy_bool))
rt->recovery_target_inclusive = dummy_bool; rt->recovery_target_inclusive = dummy_bool;
else else
elog(ERROR_ARGS, "cannot create recovery.conf with %s", target_inclusive); elog(ERROR, "cannot create recovery.conf with %s", target_inclusive);
} }
return rt; return rt;
+4 -4
View File
@@ -26,7 +26,7 @@ do_show(pgBackupRange *range, bool show_all)
* child timeline is chosen. * child timeline is chosen.
*/ */
if (arclog_path == NULL) if (arclog_path == NULL)
elog(ERROR_ARGS, elog(ERROR,
"required parameter not specified: ARCLOG_PATH (-A, --arclog-path)"); "required parameter not specified: ARCLOG_PATH (-A, --arclog-path)");
if (pgBackupRangeIsSingle(range)) if (pgBackupRangeIsSingle(range))
@@ -54,7 +54,7 @@ do_show(pgBackupRange *range, bool show_all)
backup_list = catalog_get_backup_list(range); backup_list = catalog_get_backup_list(range);
if (backup_list == NULL) if (backup_list == NULL)
elog(ERROR_SYSTEM, "can't process any more."); elog(ERROR, "can't process any more.");
show_backup_list(stdout, backup_list, show_all); show_backup_list(stdout, backup_list, show_all);
@@ -126,7 +126,7 @@ get_parent_tli(TimeLineID child_tli)
if (fd == NULL) if (fd == NULL)
{ {
if (errno != ENOENT) if (errno != ENOENT)
elog(ERROR_SYSTEM, "could not open file \"%s\": %s", path, elog(ERROR, "could not open file \"%s\": %s", path,
strerror(errno)); strerror(errno));
return 0; return 0;
@@ -152,7 +152,7 @@ get_parent_tli(TimeLineID child_tli)
/* expect a numeric timeline ID as first field of line */ /* expect a numeric timeline ID as first field of line */
result = (TimeLineID) strtoul(ptr, &endptr, 0); result = (TimeLineID) strtoul(ptr, &endptr, 0);
if (endptr == ptr) if (endptr == ptr)
elog(ERROR_CORRUPTED, elog(ERROR,
"syntax error(timeline ID) in history file: %s", "syntax error(timeline ID) in history file: %s",
fline); fline);
} }
+3 -3
View File
@@ -46,7 +46,7 @@ get_pgpid(void)
return 0; return 0;
else else
{ {
elog(ERROR_SYSTEM, "could not open PID file \"%s\": %s", elog(ERROR, "could not open PID file \"%s\": %s",
pid_file, strerror(errno)); pid_file, strerror(errno));
} }
} }
@@ -54,10 +54,10 @@ get_pgpid(void)
{ {
/* Is the file empty? */ /* Is the file empty? */
if (ftell(pidf) == 0 && feof(pidf)) if (ftell(pidf) == 0 && feof(pidf))
elog(ERROR_SYSTEM, "the PID file \"%s\" is empty", elog(ERROR, "the PID file \"%s\" is empty",
pid_file); pid_file);
else else
elog(ERROR_SYSTEM, "invalid data in PID file \"%s\"\n", elog(ERROR, "invalid data in PID file \"%s\"\n",
pid_file); pid_file);
} }
fclose(pidf); fclose(pidf);
+4 -4
View File
@@ -25,12 +25,12 @@ checkControlFile(ControlFileData *ControlFile)
/* Then compare it */ /* Then compare it */
if (!EQ_CRC32C(crc, ControlFile->crc)) if (!EQ_CRC32C(crc, ControlFile->crc))
elog(ERROR_CORRUPTED, "Calculated CRC checksum does not match value stored in file.\n" elog(ERROR, "Calculated CRC checksum does not match value stored in file.\n"
"Either the file is corrupt, or it has a different layout than this program\n" "Either the file is corrupt, or it has a different layout than this program\n"
"is expecting. The results below are untrustworthy."); "is expecting. The results below are untrustworthy.");
if (ControlFile->pg_control_version % 65536 == 0 && ControlFile->pg_control_version / 65536 != 0) if (ControlFile->pg_control_version % 65536 == 0 && ControlFile->pg_control_version / 65536 != 0)
elog(ERROR_CORRUPTED, "possible byte ordering mismatch\n" elog(ERROR, "possible byte ordering mismatch\n"
"The byte ordering used to store the pg_control file might not match the one\n" "The byte ordering used to store the pg_control file might not match the one\n"
"used by this program. In that case the results below would be incorrect, and\n" "used by this program. In that case the results below would be incorrect, and\n"
"the PostgreSQL installation would be incompatible with this data directory."); "the PostgreSQL installation would be incompatible with this data directory.");
@@ -43,7 +43,7 @@ static void
digestControlFile(ControlFileData *ControlFile, char *src, size_t size) digestControlFile(ControlFileData *ControlFile, char *src, size_t size)
{ {
if (size != PG_CONTROL_SIZE) if (size != PG_CONTROL_SIZE)
elog(ERROR_PG_INCOMPATIBLE, "unexpected control file size %d, expected %d", elog(ERROR, "unexpected control file size %d, expected %d",
(int) size, PG_CONTROL_SIZE); (int) size, PG_CONTROL_SIZE);
memcpy(ControlFile, src, sizeof(ControlFileData)); memcpy(ControlFile, src, sizeof(ControlFileData));
@@ -71,7 +71,7 @@ sanityChecks(void)
*/ */
if (ControlFile.data_checksum_version != PG_DATA_CHECKSUM_VERSION && if (ControlFile.data_checksum_version != PG_DATA_CHECKSUM_VERSION &&
!ControlFile.wal_log_hints) !ControlFile.wal_log_hints)
elog(ERROR_PG_INCOMPATIBLE, elog(ERROR,
"target master need to use either data checksums or \"wal_log_hints = on\"."); "target master need to use either data checksums or \"wal_log_hints = on\".");
} }
+3 -3
View File
@@ -32,7 +32,7 @@ do_validate(pgBackupRange *range)
/* get backup list matches given range */ /* get backup list matches given range */
backup_list = catalog_get_backup_list(range); backup_list = catalog_get_backup_list(range);
if (!backup_list) if (!backup_list)
elog(ERROR_SYSTEM, "cannot process any more."); elog(ERROR, "cannot process any more.");
parray_qsort(backup_list, pgBackupCompareId); parray_qsort(backup_list, pgBackupCompareId);
for (i = 0; i < parray_num(backup_list); i++) for (i = 0; i < parray_num(backup_list); i++)
@@ -143,7 +143,7 @@ pgBackupValidateFiles(parray *files, const char *root, bool size_only)
pgFile *file = (pgFile *) parray_get(files, i); pgFile *file = (pgFile *) parray_get(files, i);
if (interrupted) if (interrupted)
elog(ERROR_INTERRUPTED, "interrupted during validate"); elog(ERROR, "interrupted during validate");
/* skipped backup while differential backup */ /* skipped backup while differential backup */
if (file->write_size == BYTES_INVALID || !S_ISREG(file->mode)) if (file->write_size == BYTES_INVALID || !S_ISREG(file->mode))
@@ -159,7 +159,7 @@ pgBackupValidateFiles(parray *files, const char *root, bool size_only)
if (errno == ENOENT) if (errno == ENOENT)
elog(WARNING, "backup file \"%s\" vanished", file->path); elog(WARNING, "backup file \"%s\" vanished", file->path);
else else
elog(ERROR_SYSTEM, "cannot stat backup file \"%s\": %s", elog(ERROR, "cannot stat backup file \"%s\": %s",
get_relative_path(file->path, root), strerror(errno)); get_relative_path(file->path, root), strerror(errno));
return false; return false;
} }