Requirement: postgresql backups should be copied to another server on daily basis to keep them safe using a script.
- Identify the name of the backup folder created on daily basis
- Identify the associated WAL segments
Why WAL segments are required? Without proper WAL segments postgresql cannot be started and end up getting error
INFO: archive-get command end: aborted with exception  LOG: could not open file "pg_xlog/###" (log file #, segment ##): No such file or directory
Option 1 - More coding to create the copy script
Get the name of the backup folder created on daily basis from the last line of /var/lib/pgbackrest/backup/bahmni-postgres/backup.info. Copy this folder.
Get the name of the WAL segments to be copied to ensure the backup sanctity is tricky as all WAL segments are archived in the same Archive folder /var/lib/pgbackrest/archive/. To identify the name of the WAL segments read /var/lib/pgbackrest/backup/bahmni-postgres/<name of the folder identified in step 1 above>/backup.manifest and read
[backup] backup-archive-start="<start of WAL>" backup-archive-stop="<end of WAL>"
Copy all files from to from /var/lib/pgbackrest/archive/
- Backup folder of step 1 and WAL segment files of step 2 will maintain the sanctity of the backup and will be able to restore on another machine.
Option 2 - Moderate coding to create copy script
Copy WAL segments which are stored in /var/lib/pgsql/9.6/data/pg_xlog/ folder, in to the backup folders using --archive-copy option as mentioned here
Option 3 - Easy coding to create copy script While copying specific backup folder, also copy the entire /var/lib/pgbackrest/archive/. Size is the main Issue with this option archive folder stores all previous WAL segements too.