Removed --error-state option and added --status option for delete command

This commit is contained in:
Victor Spirin
2020-03-16 19:44:35 +03:00
parent 2cc3d03c4c
commit a365520a1c
4 changed files with 56 additions and 17 deletions
+10 -3
View File
@@ -1026,13 +1026,20 @@ do_delete_instance(void)
/* Delete all error backup files of given instance. */
int
do_delete_error(void)
do_delete_status(char* status)
{
parray *backup_list;
parray *xlog_files_list;
int i;
int rc;
char instance_config_path[MAXPGPATH];
BackupStatus status_for_delete;
status_for_delete = str2status(status);
if (status_for_delete == BACKUP_STATUS_INVALID)
elog(ERROR, "Unknown '%s' value for --status option", status);
/* Delete all error backups. */
@@ -1041,7 +1048,7 @@ do_delete_error(void)
for (i = 0; i < parray_num(backup_list); i++)
{
pgBackup *backup = (pgBackup *) parray_get(backup_list, i);
if (backup->status == BACKUP_STATUS_ERROR){
if (backup->status == status_for_delete){
/* elog(INFO, "Delete error backup '%s' ", base36enc(backup->backup_id)); */
catalog_lock_backup_list(backup_list, i, i);
delete_backup_files(backup);
@@ -1053,6 +1060,6 @@ do_delete_error(void)
parray_free(backup_list);
elog(INFO, "Error backups from instance '%s' successfully deleted", instance_name);
elog(INFO, "Backups with status '%s' from instance '%s' successfully deleted", status, instance_name);
return 0;
}
+9 -8
View File
@@ -117,7 +117,7 @@ bool delete_expired = false;
bool merge_expired = false;
bool force = false;
bool dry_run = false;
bool delete_error = false;
static char *delete_status = NULL;
/* compression options */
bool compress_shortcut = false;
@@ -201,7 +201,8 @@ static ConfigOption cmd_options[] =
/* delete options */
{ 'b', 145, "wal", &delete_wal, SOURCE_CMD_STRICT },
{ 'b', 146, "expired", &delete_expired, SOURCE_CMD_STRICT },
{ 'b', 172, "error-state", &delete_error, SOURCE_CMD_STRICT },
{ 's', 172, "status", &delete_status, SOURCE_CMD_STRICT },
/* TODO not implemented yet */
{ 'b', 147, "force", &force, SOURCE_CMD_STRICT },
/* compression options */
@@ -787,14 +788,14 @@ main(int argc, char *argv[])
elog(ERROR, "You cannot specify --delete-expired and (-i, --backup-id) options together");
if (merge_expired && backup_id_string)
elog(ERROR, "You cannot specify --merge-expired and (-i, --backup-id) options together");
if (delete_error && backup_id_string)
elog(ERROR, "You cannot specify --error-state and (-i, --backup-id) options together");
if (!delete_expired && !merge_expired && !delete_wal && !delete_error && !backup_id_string)
if (delete_status && backup_id_string)
elog(ERROR, "You cannot specify --status and (-i, --backup-id) options together");
if (!delete_expired && !merge_expired && !delete_wal && delete_status==NULL && !backup_id_string)
elog(ERROR, "You must specify at least one of the delete options: "
"--delete-expired |--delete-wal |--merge-expired |--error-state |(-i, --backup-id)");
"--delete-expired |--delete-wal |--merge-expired |--status |(-i, --backup-id)");
if (!backup_id_string)
if(delete_error)
do_delete_error();
if (delete_status)
do_delete_status(delete_status);
else
return do_retention();
else
+2 -1
View File
@@ -706,7 +706,7 @@ extern void do_delete(time_t backup_id);
extern void delete_backup_files(pgBackup *backup);
extern int do_retention(void);
extern int do_delete_instance(void);
extern int do_delete_error(void);
extern int do_delete_status(char *status);
/* in fetch.c */
extern char *slurpFile(const char *datadir,
@@ -915,6 +915,7 @@ extern void copy_pgcontrol_file(const char *from_fullpath, fio_location from_loc
extern void time2iso(char *buf, size_t len, time_t time);
extern const char *status2str(BackupStatus status);
extern BackupStatus str2status(const char *status);
extern const char *base36enc(long unsigned int value);
extern char *base36enc_dup(long unsigned int value);
extern long unsigned int base36dec(const char *text);
+35 -5
View File
@@ -458,11 +458,37 @@ parse_program_version(const char *program_version)
return result;
}
static const char *statusName[] =
{
"UNKNOWN",
"OK",
"ERROR",
"RUNNING",
"MERGING",
"MERGED",
"DELETING",
"DELETED",
"DONE",
"ORPHAN",
"CORRUPT"
};
const char *
status2str(BackupStatus status)
{
static const char *statusName[] =
if (status < BACKUP_STATUS_INVALID || BACKUP_STATUS_CORRUPT < status)
return "UNKNOWN";
return statusName[status];
}
BackupStatus
str2status(const char *status)
{
/* static const char *statusName[] =
{
"UNKNOWN",
"OK",
@@ -475,9 +501,13 @@ status2str(BackupStatus status)
"DONE",
"ORPHAN",
"CORRUPT"
};
if (status < BACKUP_STATUS_INVALID || BACKUP_STATUS_CORRUPT < status)
return "UNKNOWN";
};*/
return statusName[status];
for (int i = 0; i <= BACKUP_STATUS_CORRUPT; i++)
{
if (pg_strcasecmp(status, statusName[i]) == 0) return i;
}
return 0;
}