diff options
author | Lingxian Kong <anlin.kong@gmail.com> | 2021-07-22 16:38:08 +1200 |
---|---|---|
committer | Lingxian Kong <anlin.kong@gmail.com> | 2021-07-23 22:16:20 +1200 |
commit | 02971d850b57ac27a126ecb8ca4012f97ae856fd (patch) | |
tree | 0ae1bf0909bcbc13b74a4b7ba35f083c4fcbfb2a /backup | |
parent | 69f08ab470a0d1d1d4676b41ad29a9c19ce28648 (diff) | |
download | trove-02971d850b57ac27a126ecb8ca4012f97ae856fd.tar.gz |
Add periodic task to remove postgres archived wal files
* Added a periodic task for postgresql datastore to clean up the
archived WAL files.
* Added a check when creating incremental backups for postgresql.
* A new container image ``openstacktrove/db-backup-postgresql:1.1.2``
is uploaded to docker hub.
Story: 2009066
Task: 42871
Change-Id: I235e2abf8c0405e143ded6fb48017d596b8b41a1
Diffstat (limited to 'backup')
-rw-r--r-- | backup/drivers/postgres.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/backup/drivers/postgres.py b/backup/drivers/postgres.py index 0b6538bb..143ba506 100644 --- a/backup/drivers/postgres.py +++ b/backup/drivers/postgres.py @@ -70,12 +70,13 @@ class PgBasebackup(base.BaseRunner): if wal_re.search(wal_file) and wal_file >= last_wal] return wal_files - def get_backup_file(self, backup_pos=0): + def get_backup_file(self, backup_pos=0, regex=None): """Look for the most recent .backup file that basebackup creates :return: a string like 000000010000000000000006.00000168.backup """ - backup_re = re.compile("[0-9A-F]{24}.*.backup") + regex = regex or r"[0-9A-F]{24}\..*\.backup" + backup_re = re.compile(regex) wal_files = [wal_file for wal_file in os.listdir(self.wal_archive_dir) if backup_re.search(wal_file)] wal_files = sorted(wal_files, reverse=True) @@ -177,12 +178,20 @@ class PgBasebackupIncremental(PgBasebackup): def __init__(self, *args, **kwargs): self.parent_location = kwargs.pop('parent_location', '') self.parent_checksum = kwargs.pop('parent_checksum', '') + self.parent_stop_wal = kwargs.pop('stop_wal_file', '') super(PgBasebackupIncremental, self).__init__(*args, **kwargs) self.incr_restore_cmd = f'tar -xzf - -C {self.wal_archive_dir}' def pre_backup(self): + # Check if the parent stop wal file still exists. It may be removed + # by trove-guestagent. + parent_wal_name = self.get_backup_file( + backup_pos=0, regex=fr'{self.parent_stop_wal}\..+\.backup') + if not parent_wal_name: + raise Exception("Cannot find parent backup WAL file.") + with psql_util.PostgresConnection('postgres') as conn: self.start_segment = conn.query( f"SELECT pg_start_backup('{self.filename}', false, false)" |