mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-01-09 14:45:47 +02:00
Refactor delete command and add delwal command.
This commit is contained in:
parent
ff61fcc341
commit
7ba03021c5
62
delete.c
62
delete.c
@ -13,6 +13,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static int pgBackupDeleteFiles(pgBackup *backup);
|
static int pgBackupDeleteFiles(pgBackup *backup);
|
||||||
|
int do_deletewal(time_t backup_id, bool strict);
|
||||||
|
|
||||||
int
|
int
|
||||||
do_delete(time_t backup_id)
|
do_delete(time_t backup_id)
|
||||||
@ -21,8 +22,6 @@ do_delete(time_t backup_id)
|
|||||||
int b_index;
|
int b_index;
|
||||||
int ret;
|
int ret;
|
||||||
parray *backup_list;
|
parray *backup_list;
|
||||||
XLogRecPtr oldest_lsn = InvalidXLogRecPtr;
|
|
||||||
TimeLineID oldest_tli;
|
|
||||||
pgBackup *last_backup;
|
pgBackup *last_backup;
|
||||||
|
|
||||||
/* DATE are always required */
|
/* DATE are always required */
|
||||||
@ -82,37 +81,58 @@ found_backup:
|
|||||||
/* cleanup */
|
/* cleanup */
|
||||||
parray_walk(backup_list, pgBackupFree);
|
parray_walk(backup_list, pgBackupFree);
|
||||||
parray_free(backup_list);
|
parray_free(backup_list);
|
||||||
|
|
||||||
|
if (delete_wal)
|
||||||
|
do_deletewal(backup_id, false);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_deletewal(time_t backup_id, bool strict)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int ret;
|
||||||
|
parray *backup_list;
|
||||||
|
XLogRecPtr oldest_lsn = InvalidXLogRecPtr;
|
||||||
|
TimeLineID oldest_tli;
|
||||||
|
pgBackup *last_backup;
|
||||||
|
bool backup_found = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete in archive WAL segments that are not needed anymore. The oldest
|
* Delete in archive WAL segments that are not needed anymore. The oldest
|
||||||
* segment to be kept is the first segment that the oldest full backup
|
* segment to be kept is the first segment that the oldest full backup
|
||||||
* found around needs to keep.
|
* found around needs to keep.
|
||||||
*/
|
*/
|
||||||
if (delete_wal)
|
/* Lock backup catalog */
|
||||||
{
|
ret = catalog_lock();
|
||||||
/* Lock backup catalog */
|
if (ret == -1)
|
||||||
ret = catalog_lock();
|
elog(ERROR, "can't lock backup catalog.");
|
||||||
if (ret == -1)
|
else if (ret == 1)
|
||||||
elog(ERROR, "can't lock backup catalog.");
|
elog(ERROR,
|
||||||
else if (ret == 1)
|
"another pg_arman is running, stop delete.");
|
||||||
elog(ERROR,
|
|
||||||
"another pg_arman is running, stop delete.");
|
|
||||||
|
|
||||||
backup_list = catalog_get_backup_list(0);
|
backup_list = catalog_get_backup_list(0);
|
||||||
for (i = 0; i < parray_num(backup_list); i++)
|
for (i = 0; i < parray_num(backup_list); i++)
|
||||||
|
{
|
||||||
|
last_backup = (pgBackup *) parray_get(backup_list, i);
|
||||||
|
if (last_backup->status == BACKUP_STATUS_OK)
|
||||||
{
|
{
|
||||||
last_backup = (pgBackup *) parray_get(backup_list, i);
|
oldest_lsn = last_backup->start_lsn;
|
||||||
if (last_backup->status == BACKUP_STATUS_OK)
|
oldest_tli = last_backup->tli;
|
||||||
|
if (strict && backup_id != 0 && backup_id >= last_backup->start_time)
|
||||||
{
|
{
|
||||||
oldest_lsn = last_backup->start_lsn;
|
backup_found = true;
|
||||||
oldest_tli = last_backup->tli;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catalog_unlock();
|
|
||||||
parray_walk(backup_list, pgBackupFree);
|
|
||||||
parray_free(backup_list);
|
|
||||||
}
|
}
|
||||||
|
if (strict && backup_id != 0 && backup_found == false)
|
||||||
|
elog(ERROR, "not found backup for deletwal command");
|
||||||
|
catalog_unlock();
|
||||||
|
parray_walk(backup_list, pgBackupFree);
|
||||||
|
parray_free(backup_list);
|
||||||
|
|
||||||
if (delete_wal && !XLogRecPtrIsInvalid(oldest_lsn))
|
if (!XLogRecPtrIsInvalid(oldest_lsn))
|
||||||
{
|
{
|
||||||
XLogSegNo targetSegNo;
|
XLogSegNo targetSegNo;
|
||||||
char oldestSegmentNeeded[MAXFNAMELEN];
|
char oldestSegmentNeeded[MAXFNAMELEN];
|
||||||
|
@ -10,6 +10,7 @@ Usage:
|
|||||||
pg_arman OPTION show [ID]
|
pg_arman OPTION show [ID]
|
||||||
pg_arman OPTION validate [ID]
|
pg_arman OPTION validate [ID]
|
||||||
pg_arman OPTION delete ID
|
pg_arman OPTION delete ID
|
||||||
|
pg_arman OPTION delwal [ID]
|
||||||
|
|
||||||
Common Options:
|
Common Options:
|
||||||
-D, --pgdata=PATH location of the database storage area
|
-D, --pgdata=PATH location of the database storage area
|
||||||
|
@ -110,7 +110,8 @@ main(int argc, char *argv[])
|
|||||||
if(strcmp(cmd, "show") != 0 &&
|
if(strcmp(cmd, "show") != 0 &&
|
||||||
strcmp(cmd, "validate") != 0 &&
|
strcmp(cmd, "validate") != 0 &&
|
||||||
strcmp(cmd, "delete") != 0 &&
|
strcmp(cmd, "delete") != 0 &&
|
||||||
strcmp(cmd, "restore") != 0)
|
strcmp(cmd, "restore") != 0 &&
|
||||||
|
strcmp(cmd, "delwal") != 0)
|
||||||
break;
|
break;
|
||||||
} else if (backup_id_string == NULL)
|
} else if (backup_id_string == NULL)
|
||||||
backup_id_string = argv[i];
|
backup_id_string = argv[i];
|
||||||
@ -209,6 +210,8 @@ main(int argc, char *argv[])
|
|||||||
return do_validate(backup_id);
|
return do_validate(backup_id);
|
||||||
else if (pg_strcasecmp(cmd, "delete") == 0)
|
else if (pg_strcasecmp(cmd, "delete") == 0)
|
||||||
return do_delete(backup_id);
|
return do_delete(backup_id);
|
||||||
|
else if (pg_strcasecmp(cmd, "delwal") == 0)
|
||||||
|
return do_deletewal(backup_id, true);
|
||||||
else
|
else
|
||||||
elog(ERROR, "invalid command \"%s\"", cmd);
|
elog(ERROR, "invalid command \"%s\"", cmd);
|
||||||
|
|
||||||
@ -226,6 +229,7 @@ pgut_help(bool details)
|
|||||||
printf(_(" %s OPTION show [ID]\n"), PROGRAM_NAME);
|
printf(_(" %s OPTION show [ID]\n"), PROGRAM_NAME);
|
||||||
printf(_(" %s OPTION validate [ID]\n"), PROGRAM_NAME);
|
printf(_(" %s OPTION validate [ID]\n"), PROGRAM_NAME);
|
||||||
printf(_(" %s OPTION delete ID\n"), PROGRAM_NAME);
|
printf(_(" %s OPTION delete ID\n"), PROGRAM_NAME);
|
||||||
|
printf(_(" %s OPTION delwal [ID]\n"), PROGRAM_NAME);
|
||||||
|
|
||||||
if (!details)
|
if (!details)
|
||||||
return;
|
return;
|
||||||
|
@ -230,6 +230,7 @@ extern int do_show(time_t backup_id, bool show_all);
|
|||||||
/* in delete.c */
|
/* in delete.c */
|
||||||
extern int do_delete(time_t backup_id);
|
extern int do_delete(time_t backup_id);
|
||||||
extern void pgBackupDelete(int keep_generations, int keep_days);
|
extern void pgBackupDelete(int keep_generations, int keep_days);
|
||||||
|
extern int do_deletewal(time_t backup_id, bool strict);
|
||||||
|
|
||||||
/* in fetch.c */
|
/* in fetch.c */
|
||||||
extern char *slurpFile(const char *datadir,
|
extern char *slurpFile(const char *datadir,
|
||||||
|
Loading…
Reference in New Issue
Block a user