Skip to content

Commit 976694f

Browse files
author
Arthur Zakirov
committed
Add retention show|purge commands. Add tests and documentation.
1 parent 7c4c842 commit 976694f

20 files changed

+486
-434
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
/regression.diffs
2626
/regression.out
2727
/results
28+
/env
29+
/tests/__pycache__/
30+
/tests/tmp_dirs/
2831

2932
# Extra files
3033
/datapagemap.c

backup.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct
5858
*/
5959
static void backup_cleanup(bool fatal, void *userdata);
6060
static void backup_files(void *arg);
61-
static parray *do_backup_database(parray *backup_list, pgBackupOption bkupopt);
61+
static parray *do_backup_database(parray *backup_list, bool smooth_checkpoint);
6262
static void confirm_block_size(const char *name, int blcksz);
6363
static void pg_start_backup(const char *label, bool smooth, pgBackup *backup);
6464
static void pg_stop_backup(pgBackup *backup);
@@ -96,7 +96,7 @@ static void StreamLog(void *arg);
9696
* Take a backup of database and return the list of files backed up.
9797
*/
9898
static parray *
99-
do_backup_database(parray *backup_list, pgBackupOption bkupopt)
99+
do_backup_database(parray *backup_list, bool smooth_checkpoint)
100100
{
101101
int i;
102102
parray *prev_files = NULL; /* file list of previous database backup */
@@ -113,9 +113,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
113113
backup_files_args *backup_threads_args[num_threads];
114114
bool is_ptrack_support;
115115

116-
117116
/* repack the options */
118-
bool smooth_checkpoint = bkupopt.smooth_checkpoint;
119117
pgBackup *prev_backup = NULL;
120118

121119
/* Block backup operations on a standby */
@@ -446,15 +444,11 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
446444

447445

448446
int
449-
do_backup(pgBackupOption bkupopt)
447+
do_backup(bool smooth_checkpoint)
450448
{
451-
parray *backup_list;
452-
parray *files_database;
453-
int ret;
454-
455-
/* repack the necessary options */
456-
int keep_data_generations = bkupopt.keep_data_generations;
457-
int keep_data_days = bkupopt.keep_data_days;
449+
int ret;
450+
parray *backup_list;
451+
parray *files_database;
458452

459453
/* PGDATA and BACKUP_MODE are always required */
460454
if (pgdata == NULL)
@@ -481,12 +475,12 @@ do_backup(pgBackupOption bkupopt)
481475
elog(LOG, "----------------------------------------");
482476

483477
/* get exclusive lock of backup catalog */
484-
ret = catalog_lock();
478+
ret = catalog_lock(true);
485479
if (ret == -1)
486480
elog(ERROR, "cannot lock backup catalog");
487481
else if (ret == 1)
488482
elog(ERROR,
489-
"another pg_probackup is running, skipping this backup");
483+
"another pg_probackup is running, skipping this backup");
490484

491485
/* initialize backup result */
492486
current.status = BACKUP_STATUS_RUNNING;
@@ -521,7 +515,7 @@ do_backup(pgBackupOption bkupopt)
521515
pgut_atexit_push(backup_cleanup, NULL);
522516

523517
/* backup data */
524-
files_database = do_backup_database(backup_list, bkupopt);
518+
files_database = do_backup_database(backup_list, smooth_checkpoint);
525519
pgut_atexit_pop(backup_cleanup, NULL);
526520

527521
/* update backup status to DONE */
@@ -550,10 +544,6 @@ do_backup(pgBackupOption bkupopt)
550544
elog(LOG, "========================================");
551545
}
552546

553-
554-
/* Delete old backup files after all backup operation. */
555-
pgBackupDelete(keep_data_generations, keep_data_days);
556-
557547
/* Cleanup backup mode file list */
558548
if (files_database)
559549
parray_walk(files_database, pgFileFree);

catalog.c

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "pgut/pgut-port.h"
2323

24-
static pgBackup *catalog_read_ini(const char *path);
24+
static pgBackup *read_backup_from_file(const char *path);
2525

2626
#define BOOL_TO_STR(val) ((val) ? "true" : "false")
2727

@@ -32,17 +32,16 @@ static int lock_fd = -1;
3232
* If the lock is held by another one, return 1 immediately.
3333
*/
3434
int
35-
catalog_lock(void)
35+
catalog_lock(bool check_catalog)
3636
{
37-
int ret;
38-
char id_path[MAXPGPATH];
37+
int ret;
38+
char id_path[MAXPGPATH];
3939

40-
join_path_components(id_path, backup_path, PG_RMAN_INI_FILE);
40+
join_path_components(id_path, backup_path, BACKUP_CATALOG_CONF_FILE);
4141
lock_fd = open(id_path, O_RDWR);
4242
if (lock_fd == -1)
4343
elog(errno == ENOENT ? ERROR : ERROR,
4444
"cannot open file \"%s\": %s", id_path, strerror(errno));
45-
4645
#ifdef __IBMC__
4746
ret = lockf(lock_fd, LOCK_EX | LOCK_NB, 0); /* non-blocking */
4847
#else
@@ -64,6 +63,19 @@ catalog_lock(void)
6463
}
6564
}
6665

66+
if (check_catalog)
67+
{
68+
uint64 id;
69+
70+
Assert(pgdata);
71+
72+
/* Check system-identifier */
73+
id = get_system_identifier(true);
74+
if (id != system_identifier)
75+
elog(ERROR, "Backup directory was initialized for system id = %ld, but target system id = %ld",
76+
system_identifier, id);
77+
}
78+
6779
return 0;
6880
}
6981

@@ -82,15 +94,15 @@ catalog_unlock(void)
8294
* If no backup matches, return NULL.
8395
*/
8496
pgBackup *
85-
catalog_get_backup(time_t timestamp)
97+
read_backup(time_t timestamp)
8698
{
8799
pgBackup tmp;
88-
char ini_path[MAXPGPATH];
100+
char conf_path[MAXPGPATH];
89101

90102
tmp.start_time = timestamp;
91-
pgBackupGetPath(&tmp, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
103+
pgBackupGetPath(&tmp, conf_path, lengthof(conf_path), BACKUP_CONF_FILE);
92104

93-
return catalog_read_ini(ini_path);
105+
return read_backup_from_file(conf_path);
94106
}
95107

96108
static bool
@@ -144,8 +156,8 @@ catalog_get_backup_list(time_t backup_id)
144156
join_path_components(date_path, backups_path, date_ent->d_name);
145157

146158
/* read backup information from backup.ini */
147-
snprintf(ini_path, MAXPGPATH, "%s/%s", date_path, BACKUP_INI_FILE);
148-
backup = catalog_read_ini(ini_path);
159+
snprintf(ini_path, MAXPGPATH, "%s/%s", date_path, BACKUP_CONF_FILE);
160+
backup = read_backup_from_file(ini_path);
149161

150162
/* ignore corrupted backup */
151163
if (backup)
@@ -309,7 +321,7 @@ pgBackupWriteIni(pgBackup *backup)
309321
FILE *fp = NULL;
310322
char ini_path[MAXPGPATH];
311323

312-
pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
324+
pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_CONF_FILE);
313325
fp = fopen(ini_path, "wt");
314326
if (fp == NULL)
315327
elog(ERROR, "cannot open INI file \"%s\": %s", ini_path,
@@ -330,7 +342,7 @@ pgBackupWriteIni(pgBackup *backup)
330342
* - Do not care section.
331343
*/
332344
static pgBackup *
333-
catalog_read_ini(const char *path)
345+
read_backup_from_file(const char *path)
334346
{
335347
pgBackup *backup;
336348
char *backup_mode = NULL;
@@ -342,29 +354,29 @@ catalog_read_ini(const char *path)
342354

343355
pgut_option options[] =
344356
{
345-
{'s', 0, "backup-mode", NULL, SOURCE_ENV},
346-
{'u', 0, "timelineid", NULL, SOURCE_ENV},
347-
{'s', 0, "start-lsn", NULL, SOURCE_ENV},
348-
{'s', 0, "stop-lsn", NULL, SOURCE_ENV},
349-
{'t', 0, "start-time", NULL, SOURCE_ENV},
350-
{'t', 0, "end-time", NULL, SOURCE_ENV},
351-
{'U', 0, "recovery-xid", NULL, SOURCE_ENV},
352-
{'t', 0, "recovery-time", NULL, SOURCE_ENV},
353-
{'I', 0, "data-bytes", NULL, SOURCE_ENV},
354-
{'u', 0, "block-size", NULL, SOURCE_ENV},
355-
{'u', 0, "xlog-block-size", NULL, SOURCE_ENV},
356-
{'u', 0, "checksum_version", NULL, SOURCE_ENV},
357-
{'u', 0, "stream", NULL, SOURCE_ENV},
358-
{'s', 0, "status", NULL, SOURCE_ENV},
359-
{'s', 0, "parent_backup", NULL, SOURCE_ENV},
357+
{'s', 0, "backup-mode", NULL, SOURCE_FILE_STRICT},
358+
{'u', 0, "timelineid", NULL, SOURCE_FILE_STRICT},
359+
{'s', 0, "start-lsn", NULL, SOURCE_FILE_STRICT},
360+
{'s', 0, "stop-lsn", NULL, SOURCE_FILE_STRICT},
361+
{'t', 0, "start-time", NULL, SOURCE_FILE_STRICT},
362+
{'t', 0, "end-time", NULL, SOURCE_FILE_STRICT},
363+
{'U', 0, "recovery-xid", NULL, SOURCE_FILE_STRICT},
364+
{'t', 0, "recovery-time", NULL, SOURCE_FILE_STRICT},
365+
{'I', 0, "data-bytes", NULL, SOURCE_FILE_STRICT},
366+
{'u', 0, "block-size", NULL, SOURCE_FILE_STRICT},
367+
{'u', 0, "xlog-block-size", NULL, SOURCE_FILE_STRICT},
368+
{'u', 0, "checksum_version", NULL, SOURCE_FILE_STRICT},
369+
{'u', 0, "stream", NULL, SOURCE_FILE_STRICT},
370+
{'s', 0, "status", NULL, SOURCE_FILE_STRICT},
371+
{'s', 0, "parent_backup", NULL, SOURCE_FILE_STRICT},
360372
{0}
361373
};
362374

363375
if (access(path, F_OK) != 0)
364376
return NULL;
365377

366378
backup = pgut_new(pgBackup);
367-
catalog_init_config(backup);
379+
init_backup(backup);
368380

369381
i = 0;
370382
options[i++].var = &backup_mode;
@@ -516,7 +528,7 @@ pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subd
516528
}
517529

518530
void
519-
catalog_init_config(pgBackup *backup)
531+
init_backup(pgBackup *backup)
520532
{
521533
backup->backup_mode = BACKUP_MODE_INVALID;
522534
backup->status = BACKUP_STATUS_INVALID;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy