Skip to content

Commit a365520

Browse files
committed
Removed --error-state option and added --status option for delete command
1 parent 2cc3d03 commit a365520

File tree

4 files changed

+56
-17
lines changed

4 files changed

+56
-17
lines changed

src/delete.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,13 +1026,20 @@ do_delete_instance(void)
10261026

10271027
/* Delete all error backup files of given instance. */
10281028
int
1029-
do_delete_error(void)
1029+
do_delete_status(char* status)
10301030
{
10311031
parray *backup_list;
10321032
parray *xlog_files_list;
10331033
int i;
10341034
int rc;
10351035
char instance_config_path[MAXPGPATH];
1036+
1037+
BackupStatus status_for_delete;
1038+
1039+
status_for_delete = str2status(status);
1040+
1041+
if (status_for_delete == BACKUP_STATUS_INVALID)
1042+
elog(ERROR, "Unknown '%s' value for --status option", status);
10361043

10371044

10381045
/* Delete all error backups. */
@@ -1041,7 +1048,7 @@ do_delete_error(void)
10411048
for (i = 0; i < parray_num(backup_list); i++)
10421049
{
10431050
pgBackup *backup = (pgBackup *) parray_get(backup_list, i);
1044-
if (backup->status == BACKUP_STATUS_ERROR){
1051+
if (backup->status == status_for_delete){
10451052
/* elog(INFO, "Delete error backup '%s' ", base36enc(backup->backup_id)); */
10461053
catalog_lock_backup_list(backup_list, i, i);
10471054
delete_backup_files(backup);
@@ -1053,6 +1060,6 @@ do_delete_error(void)
10531060
parray_free(backup_list);
10541061

10551062

1056-
elog(INFO, "Error backups from instance '%s' successfully deleted", instance_name);
1063+
elog(INFO, "Backups with status '%s' from instance '%s' successfully deleted", status, instance_name);
10571064
return 0;
10581065
}

src/pg_probackup.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool delete_expired = false;
117117
bool merge_expired = false;
118118
bool force = false;
119119
bool dry_run = false;
120-
bool delete_error = false;
120+
static char *delete_status = NULL;
121121
/* compression options */
122122
bool compress_shortcut = false;
123123

@@ -201,7 +201,8 @@ static ConfigOption cmd_options[] =
201201
/* delete options */
202202
{ 'b', 145, "wal", &delete_wal, SOURCE_CMD_STRICT },
203203
{ 'b', 146, "expired", &delete_expired, SOURCE_CMD_STRICT },
204-
{ 'b', 172, "error-state", &delete_error, SOURCE_CMD_STRICT },
204+
{ 's', 172, "status", &delete_status, SOURCE_CMD_STRICT },
205+
205206
/* TODO not implemented yet */
206207
{ 'b', 147, "force", &force, SOURCE_CMD_STRICT },
207208
/* compression options */
@@ -787,14 +788,14 @@ main(int argc, char *argv[])
787788
elog(ERROR, "You cannot specify --delete-expired and (-i, --backup-id) options together");
788789
if (merge_expired && backup_id_string)
789790
elog(ERROR, "You cannot specify --merge-expired and (-i, --backup-id) options together");
790-
if (delete_error && backup_id_string)
791-
elog(ERROR, "You cannot specify --error-state and (-i, --backup-id) options together");
792-
if (!delete_expired && !merge_expired && !delete_wal && !delete_error && !backup_id_string)
791+
if (delete_status && backup_id_string)
792+
elog(ERROR, "You cannot specify --status and (-i, --backup-id) options together");
793+
if (!delete_expired && !merge_expired && !delete_wal && delete_status==NULL && !backup_id_string)
793794
elog(ERROR, "You must specify at least one of the delete options: "
794-
"--delete-expired |--delete-wal |--merge-expired |--error-state |(-i, --backup-id)");
795+
"--delete-expired |--delete-wal |--merge-expired |--status |(-i, --backup-id)");
795796
if (!backup_id_string)
796-
if(delete_error)
797-
do_delete_error();
797+
if (delete_status)
798+
do_delete_status(delete_status);
798799
else
799800
return do_retention();
800801
else

src/pg_probackup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ extern void do_delete(time_t backup_id);
706706
extern void delete_backup_files(pgBackup *backup);
707707
extern int do_retention(void);
708708
extern int do_delete_instance(void);
709-
extern int do_delete_error(void);
709+
extern int do_delete_status(char *status);
710710

711711
/* in fetch.c */
712712
extern char *slurpFile(const char *datadir,
@@ -915,6 +915,7 @@ extern void copy_pgcontrol_file(const char *from_fullpath, fio_location from_loc
915915

916916
extern void time2iso(char *buf, size_t len, time_t time);
917917
extern const char *status2str(BackupStatus status);
918+
extern BackupStatus str2status(const char *status);
918919
extern const char *base36enc(long unsigned int value);
919920
extern char *base36enc_dup(long unsigned int value);
920921
extern long unsigned int base36dec(const char *text);

src/util.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,37 @@ parse_program_version(const char *program_version)
458458

459459
return result;
460460
}
461+
static const char *statusName[] =
462+
{
463+
"UNKNOWN",
464+
"OK",
465+
"ERROR",
466+
"RUNNING",
467+
"MERGING",
468+
"MERGED",
469+
"DELETING",
470+
"DELETED",
471+
"DONE",
472+
"ORPHAN",
473+
"CORRUPT"
474+
};
461475

462476
const char *
463477
status2str(BackupStatus status)
464478
{
465-
static const char *statusName[] =
479+
if (status < BACKUP_STATUS_INVALID || BACKUP_STATUS_CORRUPT < status)
480+
return "UNKNOWN";
481+
482+
return statusName[status];
483+
}
484+
485+
486+
487+
BackupStatus
488+
str2status(const char *status)
489+
{
490+
491+
/* static const char *statusName[] =
466492
{
467493
"UNKNOWN",
468494
"OK",
@@ -475,9 +501,13 @@ status2str(BackupStatus status)
475501
"DONE",
476502
"ORPHAN",
477503
"CORRUPT"
478-
};
479-
if (status < BACKUP_STATUS_INVALID || BACKUP_STATUS_CORRUPT < status)
480-
return "UNKNOWN";
504+
};*/
481505

482-
return statusName[status];
506+
507+
for (int i = 0; i <= BACKUP_STATUS_CORRUPT; i++)
508+
{
509+
if (pg_strcasecmp(status, statusName[i]) == 0) return i;
510+
}
511+
512+
return 0;
483513
}

0 commit comments

Comments
 (0)