-
Notifications
You must be signed in to change notification settings - Fork 76
WAL-Archiving + PITR #231
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
Merged
Merged
WAL-Archiving + PITR #231
Changes from 11 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
261167d
Allow cloud archiving to run next ot the primary
davissp14 c7e764a
fix test
davissp14 479dd0f
Retention work
davissp14 8d497ea
Cleanup
davissp14 2b69519
fix log
davissp14 2cc0b45
Fix deletion call
davissp14 ba33e59
Move the log under the debug flag
davissp14 39bc76a
Adding tests
davissp14 78c3ac0
Checkin
davissp14 47a6f21
Checkin
davissp14 d91ea1a
Add todo
davissp14 96190c4
Update AWS_ENDPOINT_URL -> AWS_ENDPOINT_URL_S3
davissp14 1033d55
Refactor
davissp14 645e07d
Checkin
davissp14 49784fe
Working PITR, but there's quite a bit of cleanup to do
davissp14 f5e1353
cleanup
davissp14 c1b27e5
cleanup
davissp14 a3e3ced
Didn't mean to remove this
davissp14 f431edb
Set archive_timeout
davissp14 383da38
More cleanup
davissp14 b17193f
fixes and cleanup
davissp14 4d6c412
Fixing up recovery time logic
davissp14 900b8e6
Adding todo's and removing unused code
davissp14 8fa510c
Unexport functions
davissp14 4ddcecc
Separate credentials into separate profiles
davissp14 61eedd0
Fix errcheck
davissp14 ea0c59e
Add todo
davissp14 fd001e5
static check fixes
davissp14 dc6c13c
Make archive settings configurable
davissp14 eba8aa7
Removing unnecessary change
davissp14 644c0d1
Cleanup
davissp14 d19644c
Adding tests
davissp14 2ac4327
Bug fix
davissp14 6284d76
Wait for PG to be up before monitoring. Also removing some logging t…
davissp14 6a76b7b
Fix compile error
c37df40
Adding log indicating the monitor is starting
davissp14 b7802e3
Rename the env vars to something more appropriate
davissp14 06c4695
Cleanup
davissp14 2029c2c
Fix that ensures the user configured full_backup_frequency is honored
davissp14 589866b
Cleanup
davissp14 5eaa2c2
Fixes issue where a failed backup was being selected as a base restor…
davissp14 5734e7c
Remove support for 'latest' string, since this should be controlled w…
davissp14 010ffb0
Don't allow full_backup_frequencies lower than 1h
davissp14 884a782
Cleaning up the config validations
davissp14 53c1112
Adding support for targetTimeline
davissp14 b8fdd5c
Do not perform a remote restore if there's an existing postgresql dir…
davissp14 096e3ad
Revert back to RFC3339
davissp14 fdbbc12
Postgres doesn't support 'Z', so trim it and conver to -00:00
davissp14 6e3aa73
Moving back to RFC3339, however, 'Z' needs to be stripped and replace…
davissp14 0f58fd5
Allow target to be left out
davissp14 5a6eae6
Cleanup
davissp14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "time" | ||
|
|
||
| "github.com/fly-apps/postgres-flex/internal/flypg" | ||
| ) | ||
|
|
||
| func monitorBackupRetention(ctx context.Context, barman *flypg.Barman) { | ||
| ticker := time.NewTicker(defaultBackupRetentionEvaluationThreshold) | ||
| defer ticker.Stop() | ||
| for range ticker.C { | ||
| result, err := barman.WALArchiveDelete(ctx) | ||
| if err != nil { | ||
| log.Printf("Backup retention failed with: %s", err) | ||
| } | ||
|
|
||
| if len(result) > 0 { | ||
| log.Printf("Backup retention response: %s", result) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package flypg | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/fly-apps/postgres-flex/internal/utils" | ||
| ) | ||
|
|
||
| const ( | ||
| barmanRecoveryDirectory = "/data/postgresql" | ||
| ) | ||
|
|
||
| type Barman struct { | ||
| appName string | ||
| provider string | ||
| endpoint string | ||
| bucket string | ||
|
|
||
| // fullBackupFrequency string | ||
| minimumRedundancy string | ||
| retentionDays string | ||
| } | ||
|
|
||
| func NewBarman() (*Barman, error) { | ||
| if err := validateBarman(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // TODO - Validate minimum and retention day values | ||
| minRedundancy := getenv("CLOUD_ARCHIVING_MINIMUM_REDUNDANCY", "3") | ||
| retentionDays := getenv("CLOUD_ARCHIVING_RETENTION_DAYS", "7") | ||
|
|
||
| return &Barman{ | ||
| appName: os.Getenv("FLY_APP_NAME"), | ||
| provider: "aws-s3", | ||
| endpoint: strings.TrimSpace(os.Getenv("AWS_ENDPOINT_URL")), | ||
| bucket: strings.TrimSpace(os.Getenv("AWS_BUCKET_NAME")), | ||
|
|
||
| // fullBackupFrequency: getenv("CLOUD_ARCHIVING_FULL_BACKUP_FREQUENCY", "1"), | ||
| minimumRedundancy: minRedundancy, | ||
| retentionDays: retentionDays, | ||
| }, nil | ||
| } | ||
|
|
||
| func (b *Barman) RetentionPolicy() string { | ||
| return fmt.Sprintf("'RECOVERY WINDOW OF %s days'", b.retentionDays) | ||
| } | ||
|
|
||
| // WALArchiveDelete deletes backups/WAL based on the specified retention policy. | ||
| func (b *Barman) WALArchiveDelete(ctx context.Context) ([]byte, error) { | ||
| return utils.RunCommand(b.walArchiveDeleteCommand(), "postgres") | ||
| } | ||
|
|
||
| func (b *Barman) PrintRetentionPolicy() { | ||
| str := ` | ||
| Retention Policy | ||
| ----------------- | ||
| RECOVERY WINDOW OF %s days | ||
| MINIMUM BACKUP REDUNDANCY: %s | ||
| FULL BACKUP FREQUENCY: %s day(s) | ||
| ` | ||
| log.Printf(str, b.retentionDays, b.minimumRedundancy) | ||
| } | ||
|
|
||
| func (b *Barman) walArchiveDeleteCommand() string { | ||
| return fmt.Sprintf("barman-cloud-backup-delete --cloud-provider %s --endpoint-url %s --retention %s --minimum-redundancy %s s3://%s %s", | ||
| b.provider, | ||
| b.endpoint, | ||
| b.RetentionPolicy(), | ||
| b.minimumRedundancy, | ||
| b.bucket, | ||
| b.appName, | ||
| ) | ||
| } | ||
|
|
||
| func (b *Barman) walArchiveCommand() string { | ||
| // TODO - Make compression configurable | ||
| return fmt.Sprintf("barman-cloud-wal-archive --cloud-provider %s --gzip --endpoint-url %s s3://%s %s %%p", | ||
| b.provider, | ||
| b.endpoint, | ||
| b.bucket, | ||
| b.appName, | ||
| ) | ||
| } | ||
|
|
||
| func validateBarman() error { | ||
| if os.Getenv("AWS_ACCESS_KEY_ID") == "" { | ||
| return fmt.Errorf("AWS_ACCESS_KEY_ID secret must be set") | ||
| } | ||
|
|
||
| if os.Getenv("AWS_SECRET_ACCESS_KEY") == "" { | ||
| return fmt.Errorf("AWS_SECRET_ACCESS_KEY secret must be set") | ||
| } | ||
|
|
||
| if os.Getenv("AWS_BUCKET_NAME") == "" { | ||
| return fmt.Errorf("AWS_BUCKET_NAME envvar must be set") | ||
| } | ||
|
|
||
| if os.Getenv("AWS_ENDPOINT_URL") == "" { | ||
| return fmt.Errorf("AWS_ENDPOINT_URL envvar must be set") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func getenv(key, fallback string) string { | ||
| value := os.Getenv(key) | ||
| if len(value) == 0 { | ||
| return fallback | ||
| } | ||
| return value | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.