From dc650f1ac1d8b29a355b61284eb2cf734adba3ad Mon Sep 17 00:00:00 2001 From: Michael Wallace Date: Mon, 10 Oct 2022 10:48:38 +0100 Subject: [PATCH] Warn about `.partial` files in the WAL archive during recovery Updates _xlog_copy so that special handling is only used for `.partial` files in the streaming directory. Any `.partial` files found in the WAL archive are handled the same way Barman would previously handle them, i.e. they are copied across to the recovery WAL destination (decompressing if necessary) and *not* renamed. Because this is a situation which requires some manual intervention a warning message is now logged to tell the user about each `.partial` WAL found in the archive. The user must then determine whether the `.partial` WAL in the archive is the result of a recovery from backup or a standby promotion and, if so, can rename the file to omit its `.partial` extension. There is a clear opportunity for Barman to handle this itself however this is deliberately not tackled by this patch and will instead be added at a later date when we improve the behaviour of Barman in a clustered environment. Relates to #393. --- barman/recovery_executor.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/barman/recovery_executor.py b/barman/recovery_executor.py index 491c7506d..da37b34f5 100644 --- a/barman/recovery_executor.py +++ b/barman/recovery_executor.py @@ -785,9 +785,27 @@ def _xlog_copy(self, required_xlog_files, wal_dest, remote_command): compression_manager = self.backup_manager.compression_manager # Fill xlogs and compressors maps from required_xlog_files for wal_info in required_xlog_files: - if xlog.is_partial_file(wal_info.name): + if ( + xlog.is_partial_file(wal_info.name) + and hasattr(wal_info, "orig_filename") + and ( + os.path.dirname(wal_info.orig_filename) + == self.config.streaming_wals_directory + ) + ): + # If a .partial file is in the `streaming` directory then add it to a + # separate list so it can be renamed and transferred in a separate + # Rsync operation. partial_xlogs.append(wal_info) else: + if xlog.is_partial_file(wal_info.name): + # If a .partial file is in the main WAL archive then either a + # standby was promoted or a primary was recovered from a backup. + # In either case we do not attempt to handle it and instead warn + # the user. + output.warning( + ".partial WAL file '%s' found in WAL archive", wal_info.name + ) hashdir = xlog.hash_dir(wal_info.name) xlogs[hashdir].append(wal_info) # If a compressor is required, make sure it exists in the cache