Skip to content
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

Fix of deleting WAL-E backups #1292

Merged
merged 10 commits into from
Jun 15, 2022
22 changes: 22 additions & 0 deletions docker/pg_tests/scripts/tests/wale_compatibility_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ PGHOST=/var/run/postgresql \
WALE_FILE_PREFIX=file://localhost/tmp \
wal-e backup-push ${PGDATA}

pgbench -i -s 10 postgres
pg_dumpall -f /tmp/dump1
pgbench -c 2 -T 100000000 -S &
sleep 1
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE \
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \
AWS_ENDPOINT=http://s3:9000 \
AWS_S3_FORCE_PATH_STYLE=true \
WALG_COMPRESSION_METHOD=brotli \
WALG_DELTA_MAX_STEPS=6 \
WALG_UPLOAD_CONCURRENCY=10 \
WALG_DISK_RATE_LIMIT=41943040 \
WALG_NETWORK_RATE_LIMIT=10485760 \
PGSSLMODE=allow \
PGDATABASE=postgres \
PGHOST=/var/run/postgresql \
WALE_FILE_PREFIX=file://localhost/tmp \
wal-e backup-push ${PGDATA}

pkill -9 postgres

mkdir /tmp/conf_files
Expand Down Expand Up @@ -98,4 +117,7 @@ diff /tmp/dump1 /tmp/dump2
rm -rf /tmp/conf_files
/tmp/scripts/drop_pg.sh

WALE_FILE_PREFIX=file://localhost/tmp \
wal-g delete RETAIN 1 --confirm

echo "WAL-E compatible backup-fetch success!!!!!!"
3 changes: 1 addition & 2 deletions internal/backup_mark.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ func GetPermanentBackups(folder storage.Folder, metaFetcher GenericMetaFetcher)
for _, backupTime := range backupTimes {
meta, err := metaFetcher.Fetch(backupTime.BackupName, folder)
if err != nil {
tracelog.ErrorLogger.Printf("failed to fetch backup meta for backup %s with error %s, ignoring...",
backupTime.BackupName, err.Error())
PrintMetadataNotFoundError(backupTime, err)
continue
}
if meta.IsPermanent {
Expand Down
3 changes: 1 addition & 2 deletions internal/databases/postgres/delete_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func GetPermanentBackupsAndWals(folder storage.Folder) (map[string]bool, map[str
backup := NewBackup(folder.GetSubFolder(utility.BaseBackupPath), backupTime.BackupName)
meta, err := backup.FetchMeta()
if err != nil {
tracelog.ErrorLogger.Printf("failed to fetch backup meta for backup %s with error %s, ignoring...",
backupTime.BackupName, err.Error())
internal.PrintMetadataNotFoundError(backupTime, err)
continue
}
if meta.IsPermanent {
Expand Down
13 changes: 11 additions & 2 deletions internal/delete_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func FindPermanentBackups(folder storage.Folder, metaFetcher GenericMetaFetcher)
meta, err := metaFetcher.Fetch(
backupTime.BackupName, folder.GetSubFolder(utility.BaseBackupPath))
if err != nil {
tracelog.ErrorLogger.Printf("failed to fetch backup meta for backup %s with error %s, ignoring...",
backupTime.BackupName, err.Error())
PrintMetadataNotFoundError(backupTime, err)
continue
}
if meta.IsPermanent {
Expand All @@ -33,6 +32,16 @@ func FindPermanentBackups(folder storage.Folder, metaFetcher GenericMetaFetcher)
return permanentBackups
}

func PrintMetadataNotFoundError(backupTime BackupTime, err error) {
x4m marked this conversation as resolved.
Show resolved Hide resolved
if _, ok := err.(storage.ObjectNotFoundError); ok {
tracelog.InfoLogger.Printf("Backup %s lacks metadata to check if it's permanent, ignoring...",
backupTime.BackupName)
} else {
tracelog.ErrorLogger.Printf("failed to fetch backup meta for backup %s with error %s, ignoring...",
backupTime.BackupName, err.Error())
}
}

// IsPermanent is a generic function to determine if the storage object is permanent.
// It does not support permanent WALs or binlogs.
func IsPermanent(objectName string, permanentBackups map[string]bool, backupNameLength int) bool {
Expand Down