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

FMWK-604 Implement XDR restore handler #197

Merged
merged 12 commits into from
Jan 9, 2025
Prev Previous commit
Next Next commit
FMWK-604-xdr-restore-handler
- fix reader and encoder initialization.
  • Loading branch information
filkeith committed Jan 9, 2025
commit 903aeb7aa7e8629ace70ac6d538b935736b820e8
4 changes: 2 additions & 2 deletions cmd/internal/app/asbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (b *ASBackup) Run(ctx context.Context) error {
return fmt.Errorf("failed to xdr backup: %w", err)
}

printBackupReport(h.GetStats())
printBackupReport(reportHeaderBackupXDR, h.GetStats())
default:
// Running ordinary backup.
h, err := b.backupClient.Backup(ctx, b.backupConfig, b.writer, b.reader)
Expand All @@ -239,7 +239,7 @@ func (b *ASBackup) Run(ctx context.Context) error {
return fmt.Errorf("failed to backup: %w", err)
}

printBackupReport(h.GetStats())
printBackupReport(reportHeaderBackup, h.GetStats())
}

return nil
Expand Down
21 changes: 15 additions & 6 deletions cmd/internal/app/asrestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (r *ASRestore) Run(ctx context.Context) error {

switch r.mode {
case models.RestoreModeASB:
r.restoreConfig.EncoderType = backup.EncoderTypeASB

h, err := r.backupClient.Restore(ctx, r.restoreConfig, r.reader)
if err != nil {
return fmt.Errorf("failed to start restore: %w", err)
Expand All @@ -101,24 +103,30 @@ func (r *ASRestore) Run(ctx context.Context) error {
return fmt.Errorf("failed to restore: %w", err)
}

printRestoreReport(h.GetStats())
printRestoreReport(reportHeaderRestore, h.GetStats())
case models.RestoreModeASBX:
h, err := r.backupClient.RestoreXDR(ctx, r.restoreConfig, r.xdrReader)
r.restoreConfig.EncoderType = backup.EncoderTypeASBX

hXdr, err := r.backupClient.RestoreXDR(ctx, r.restoreConfig, r.xdrReader)
if err != nil {
return fmt.Errorf("failed to start xdr restore: %w", err)
}

if err = h.Wait(ctx); err != nil {
if err = hXdr.Wait(ctx); err != nil {
return fmt.Errorf("failed to xdr restore: %w", err)
}

printRestoreReport(h.GetStats())
printRestoreReport(reportHeaderRestoreXDR, hXdr.GetStats())
case models.RestoreModeAuto:
r.restoreConfig.EncoderType = backup.EncoderTypeASB

h, err := r.backupClient.Restore(ctx, r.restoreConfig, r.reader)
if err != nil {
return fmt.Errorf("failed to start restore: %w", err)
}

r.restoreConfig.EncoderType = backup.EncoderTypeASBX

hXdr, err := r.backupClient.RestoreXDR(ctx, r.restoreConfig, r.xdrReader)
if err != nil {
return fmt.Errorf("failed to start xdr restore: %w", err)
Expand All @@ -132,8 +140,9 @@ func (r *ASRestore) Run(ctx context.Context) error {
return fmt.Errorf("failed to xdr restore: %w", err)
}

printRestoreReport(h.GetStats())
printRestoreReport(hXdr.GetStats())
printRestoreReport(reportHeaderRestore, h.GetStats())
fmt.Println() // For pretty print.
printRestoreReport(reportHeaderRestoreXDR, hXdr.GetStats())
default:
return fmt.Errorf("invalid mode: %s", r.mode)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/internal/app/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func mapRestoreConfig(params *ASRestoreParams) *backup.RestoreConfig {
params.RestoreParams.RetryBaseTimeout,
params.RestoreParams.RetryMultiplier, params.RestoreParams.RetryMaxRetries,
)
c.EncoderType = backup.EncoderTypeASB

return c
}
Expand Down
15 changes: 11 additions & 4 deletions cmd/internal/app/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ import (
bModels "github.com/aerospike/backup-go/models"
)

func printBackupReport(stats *bModels.BackupStats) {
fmt.Println("Backup Report")
const (
reportHeaderBackup = "Backup Report"
reportHeaderBackupXDR = "XDR Backup Report"
reportHeaderRestore = "Restore Report"
reportHeaderRestoreXDR = "XDR Restore Report"
)

func printBackupReport(header string, stats *bModels.BackupStats) {
fmt.Println(header)
fmt.Println("--------------")
fmt.Printf("Start Time: %s\n", stats.StartTime.Format(time.RFC1123))
fmt.Printf("Duration: %s\n", stats.GetDuration())
Expand All @@ -35,8 +42,8 @@ func printBackupReport(stats *bModels.BackupStats) {
fmt.Printf("Files Written: %d\n", stats.GetFileCount())
}

func printRestoreReport(stats *bModels.RestoreStats) {
fmt.Println("Restore Report")
func printRestoreReport(header string, stats *bModels.RestoreStats) {
fmt.Println(header)
fmt.Println("--------------")
fmt.Printf("Start Time: %s\n", stats.StartTime.Format(time.RFC1123))
fmt.Printf("Duration: %s\n", stats.GetDuration())
Expand Down
11 changes: 6 additions & 5 deletions io/aws/s3/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ func (r *Reader) StreamFiles(
switch r.isDir {
case true:
path = cleanPath(path)

err := r.checkRestoreDirectory(ctx, path)
if err != nil {
errorsCh <- err
return
if !r.skipDirCheck {
err := r.checkRestoreDirectory(ctx, path)
if err != nil {
errorsCh <- err
return
}
}

r.streamDirectory(ctx, path, readersCh, errorsCh)
Expand Down
11 changes: 6 additions & 5 deletions io/azure/blob/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ func (r *Reader) StreamFiles(
switch r.isDir {
case true:
path = cleanPath(path)

err := r.checkRestoreDirectory(ctx, path)
if err != nil {
errorsCh <- err
return
if !r.skipDirCheck {
err := r.checkRestoreDirectory(ctx, path)
if err != nil {
errorsCh <- err
return
}
}

r.streamDirectory(ctx, path, readersCh, errorsCh)
Expand Down
11 changes: 6 additions & 5 deletions io/gcp/storage/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ func (r *Reader) StreamFiles(
switch r.isDir {
case true:
path = cleanPath(path)

err := r.checkRestoreDirectory(ctx, path)
if err != nil {
errorsCh <- err
return
if !r.skipDirCheck {
err := r.checkRestoreDirectory(ctx, path)
if err != nil {
errorsCh <- err
return
}
}

r.streamDirectory(ctx, path, readersCh, errorsCh)
Expand Down
10 changes: 6 additions & 4 deletions io/local/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ func (r *Reader) StreamFiles(
// If it is a folder, open and return.
switch r.isDir {
case true:
err := r.checkRestoreDirectory(path)
if err != nil {
errorsCh <- err
return
if !r.skipDirCheck {
err := r.checkRestoreDirectory(path)
if err != nil {
errorsCh <- err
return
}
}

r.streamDirectory(ctx, path, readersCh, errorsCh)
Expand Down
Loading