Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --restore-point flag to Greenplum backup-fetch (#1221)
* Add --restore-point flag to the greenplum backup-fetch * Add tests * Fix problems
- Loading branch information
1 parent
9e4e777
commit 4ef9f23
Showing
10 changed files
with
190 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,38 @@ | ||
package greenplum | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/pkg/storages/storage" | ||
"github.com/wal-g/wal-g/utility" | ||
) | ||
|
||
//TODO: Implement backup-list handler | ||
|
||
// ListStorageBackups returns the list of storage backups sorted by finish time (in ascending order) | ||
func ListStorageBackups(folder storage.Folder) ([]Backup, error) { | ||
backupObjects, err := internal.GetBackups(folder.GetSubFolder(utility.BaseBackupPath)) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch list of backups in storage: %w", err) | ||
} | ||
|
||
backups := make([]Backup, 0, len(backupObjects)) | ||
for _, b := range backupObjects { | ||
backup := NewBackup(folder, b.BackupName) | ||
|
||
_, err = backup.GetSentinel() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load sentinel for backup %s: %w", b.BackupName, err) | ||
} | ||
|
||
backups = append(backups, backup) | ||
} | ||
|
||
sort.Slice(backups, func(i, j int) bool { | ||
return backups[i].SentinelDto.FinishTime.Before(backups[j].SentinelDto.FinishTime) | ||
}) | ||
|
||
return backups, nil | ||
} |
This file contains 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,38 @@ | ||
package greenplum | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/wal-g/wal-g/pkg/storages/storage" | ||
) | ||
|
||
type RestorePointBackupSelector struct { | ||
restorePoint string | ||
} | ||
|
||
func NewRestorePointBackupSelector(restorePoint string) *RestorePointBackupSelector { | ||
return &RestorePointBackupSelector{restorePoint: restorePoint} | ||
} | ||
|
||
func (s *RestorePointBackupSelector) Select(folder storage.Folder) (string, error) { | ||
restorePoint, err := FetchRestorePointMetadata(folder, s.restorePoint) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
backups, err := ListStorageBackups(folder) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// pick the latest (closest) backup to the restore point | ||
for i := len(backups) - 1; i >= 0; i-- { | ||
if backups[i].SentinelDto.FinishTime.Before(restorePoint.FinishTime) { | ||
return backups[i].Name, nil | ||
} | ||
} | ||
|
||
return "", fmt.Errorf( | ||
"failed to find matching backup (earlier than the finish time %s of the restore point %s)", | ||
restorePoint.Name, restorePoint.FinishTime) | ||
} |
This file contains 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 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 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