-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use barman-cloud-backup
as hook?
#1051
Comments
Hey @ImSingee, I have just been through this for a solution I'm building. The key is to add The giveaway is this:
To answer your other queries:
I tried doing the deletion as part of the same command but it won't work because the server/backup will be in progress until after the hook script has finished. This is why you need it to run after the hook script finishes. Feel free to modify to run sooner etc. You raise a good point about the WALs, I will have to investigate that too. Curious to know which way you went to sort this out. |
It looks like you can add
Based on an initial look, it appears that using this as a hook will have the same behaviour where the WALs are copied to S3 but the local copy remains. I would expect you'd probably want the local WALs to remain until the next backup anyway perhaps? One strange thing is that I'd love if someone on the dev side could chime in with their recommendations/thoughts on how to manage WALs in between hook-ed cloud backup sync jobs:
Is it best practice to have the Additionally, I have a query about the following:
|
@kcslb92 Thanks for your reply! I found this document: https://docs.pgbarman.org/release/3.12.0/user_guide/hook_scripts.html#using-barman-cloud-scripts-as-hooks-in-barman The hook only feels like it's not running—it actually does run (with no log). Not sure why I thought it wasn't working before, but after retrying just now, everything works perfectly. With the following config, both backup and wal can be replicated to s3 successfully:
About the deleting: I'm not really care if backups and wals exists in my local server. I can accept save some copies in my local server, while I want the s3 server can save more. For example, I may want my local server have one copy and the server have recent 1 year's. I haven't tried this. But I believe the following solution will work:
|
Please find some thoughts below.
Right, that's the documentation about how to use
Please note that The On the other hand, With that in mind, if you want to save the output of
Yes, there is a way. If you want increased logging output, please use the
Deleting backups is outside of the scope of the Instead of scheduling these deletes after the hook runs, I'd advise to use retention policies in Barman. It is configured slightly differently for
You might be interested in reading the Retention policies section for more details.
Yes, that's what the documentation recommends. Please refer to Using barman-cloud-* scripts as hooks in barman.
When running
In any case, as mentioned earlier, when
$ aws --profile barman-cloud s3 ls s3://barman-s3-test/cloud/wals/0000000100000000/
2025-01-16 12:14:58 16777216 000000010000000000000067
2025-01-16 12:14:59 351 000000010000000000000067.00000110.backup
2025-01-16 12:36:09 16777216 000000010000000000000068
2025-01-16 12:36:13 16777216 000000010000000000000069
2025-01-16 12:36:14 351 000000010000000000000069.00000028.backup
2025-01-16 12:36:48 16777216 00000001000000000000006A
2025-01-16 12:36:52 16777216 00000001000000000000006B
2025-01-16 12:36:53 351 00000001000000000000006B.00000028.backup
2025-01-16 12:36:55 16777216 00000001000000000000006C
$ barman-cloud-backup-delete -P barman-cloud s3://barman-s3-test cloud -r 'REDUNDANCY 1' -v
2025-01-16 12:37:03,921 [46187] INFO: Found credentials in shared credentials file: ~/.aws/credentials
2025-01-16 12:37:04,094 [46187] INFO: Found file from backup '20250116T123608' of server 'cloud': cloud/base/20250116T123608/24576.tar
2025-01-16 12:37:04,094 [46187] INFO: Found file from backup '20250116T123608' of server 'cloud': cloud/base/20250116T123608/data.tar
$ aws --profile barman-cloud s3 ls s3://barman-s3-test/cloud/wals/0000000100000000/
2025-01-16 12:36:52 16777216 00000001000000000000006B
2025-01-16 12:36:53 351 00000001000000000000006B.00000028.backup
2025-01-16 12:36:55 16777216 00000001000000000000006C
No, that's out of the scope of
Please refer to a previous sentence in this reply, which explains about the relationship between
Yes, that's the recommended way of dealing with this situation. Best regards, |
I've already set up the Barman server with
backup_method = postgres
.Now I want to sync it to the cloud, but it fails.
I'm using 3.12 now. I've found a statement "This script can be used in conjunction with post_backup_script or post_backup_retry_script to relay barman backups to cloud" from the 3.10 document and using the provided example:
After executing
barman backup pg
, I got errors from the log:I guess maybe I should use
wait
to make it work, and then I encountered with #1043.Is there a bug or an intentional change? And if it's intentional, how can I set it up?
BTW, if I'm not misunderstanding, this will (if it works well) also only sync backups, not wals. Is there any ways to sync wal to cloud?
And maybe a feature request in the meantime: I want to save backups and wals to s3 only so that I can have nearly unlimited retention. I believe this is already possible when using
barman-cloud-backup
only, but it requires installing and configuring barman on each pg server. I want to have only one dedicated server for barman, to manage several pg servers, and save data to s3.The text was updated successfully, but these errors were encountered: