MCPcopy
hub / github.com/basecamp/once / BackupToFile

Method BackupToFile

internal/docker/application_backup.go:45–75  ·  view source on GitHub ↗
(ctx context.Context, dir string, name string)

Source from the content-addressed store, hash-verified

43}
44
45func (a *Application) BackupToFile(ctx context.Context, dir string, name string) error {
46 if dir == "" {
47 return fmt.Errorf("backup location is required")
48 }
49 if !filepath.IsAbs(dir) {
50 return ErrBackupPathRelative
51 }
52
53 filePath := filepath.Join(dir, name)
54 file, err := fsutil.CreateFile(filePath)
55 if err != nil {
56 slog.Error("Failed to create backup file", "app", a.Settings.Name, "filename", filePath, "error", err)
57 return fmt.Errorf("creating backup file: %w", err)
58 }
59 defer file.Close()
60
61 err = a.backupToWriter(ctx, file)
62 a.saveOperationResult(ctx, func(s *State) { s.RecordBackup(a.Settings.Name, err) })
63
64 if err != nil {
65 if !errors.Is(err, ErrUnpauseFailed) {
66 os.Remove(filePath)
67 }
68 slog.Error("Backup failed", "app", a.Settings.Name, "filename", filePath, "error", err)
69 return err
70 }
71
72 slog.Info("Created backup file", "app", a.Settings.Name, "filename", filePath)
73
74 return nil
75}
76
77func (a *Application) TrimBackups() error {
78 if a.Settings.Backup.Path == "" {

Callers 10

BackupMethod · 0.95
TestBackupFunction · 0.80
TestRestoreFunction · 0.80
TestBackupHookBehaviorFunction · 0.80
runMethod · 0.80
runBackupFunction · 0.80

Calls 7

backupToWriterMethod · 0.95
saveOperationResultMethod · 0.95
CreateFileFunction · 0.92
RecordBackupMethod · 0.80
RemoveMethod · 0.65
ErrorMethod · 0.45
CloseMethod · 0.45

Tested by 7

TestBackupFunction · 0.64
TestRestoreFunction · 0.64
TestBackupHookBehaviorFunction · 0.64