fix: verify server snapshots and recover whole migration sessions (#3)
This commit is contained in:
1 parent
3d4101ecc0
commit
8569871a17
29 files changed
+1923
-133
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package appstate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// ServerMigrationBackupDir is separate from local backup retention.
|
||||
func ServerMigrationBackupDir(dbPath string) (string, error) {
|
||||
root := filepath.Join(resolveBackupRoot(dbPath), "server-migrations")
|
||||
if err := ValidateBackupLocation(root); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := os.MkdirAll(root, 0700); err != nil {
|
||||
return "", fmt.Errorf("create server backup directory: %w", err)
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(root)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("resolve server backup directory: %w", err)
|
||||
}
|
||||
if err := ValidateBackupLocation(resolved); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
// ValidateBackupLocation checks the destination, including existing symlinks.
|
||||
func ValidateBackupLocation(path string) error {
|
||||
if err := validateBackupRoot(path); err != nil {
|
||||
return err
|
||||
}
|
||||
existing := path
|
||||
for {
|
||||
if _, err := os.Lstat(existing); err == nil {
|
||||
break
|
||||
} else if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("inspect backup path: %w", err)
|
||||
}
|
||||
parent := filepath.Dir(existing)
|
||||
if parent == existing {
|
||||
return fmt.Errorf("backup path has no existing parent")
|
||||
}
|
||||
existing = parent
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(existing)
|
||||
if err != nil {
|
||||
return fmt.Errorf("resolve backup path: %w", err)
|
||||
}
|
||||
return validateBackupRoot(resolved)
|
||||
}
|
||||
Reference in new issue
Block a user