feat: Add --workdir flag for cluster restore

Solves disk space issues on VMs with small system disks but large NFS mounts.

Use case:
- VM has small / partition (e.g., 7.8G with 2.3G used)
- Backup archive on NFS mount (e.g., /u01/dba with 140G free)
- Restore fails: "insufficient disk space: 74.7% used - need at least 4x archive size"

Solution:
- Added --workdir flag to restore cluster command
- Allows specifying alternative extraction directory
- Interactive confirmation required for safety
- Updated error messages with helpful tip

Example:
  dbbackup restore cluster backup.tar.gz --workdir /u01/dba/restore_tmp --confirm

This is environmental, not a bug. Code working brilliantly! 👨‍🍳💋
This commit is contained in:
2025-11-28 11:24:19 +00:00
parent 57ba8c7c1e
commit e581f0a357
3 changed files with 70 additions and 7 deletions

View File

@@ -230,6 +230,11 @@ func containsSQLKeywords(content string) bool {
// CheckDiskSpace verifies sufficient disk space for restore
func (s *Safety) CheckDiskSpace(archivePath string, multiplier float64) error {
return s.CheckDiskSpaceAt(archivePath, s.cfg.BackupDir, multiplier)
}
// CheckDiskSpaceAt verifies sufficient disk space at a specific directory
func (s *Safety) CheckDiskSpaceAt(archivePath string, checkDir string, multiplier float64) error {
// Get archive size
stat, err := os.Stat(archivePath)
if err != nil {
@@ -242,18 +247,33 @@ func (s *Safety) CheckDiskSpace(archivePath string, multiplier float64) error {
requiredSpace := int64(float64(archiveSize) * multiplier)
// Get available disk space
availableSpace, err := getDiskSpace(s.cfg.BackupDir)
availableSpace, err := getDiskSpace(checkDir)
if err != nil {
s.log.Warn("Cannot check disk space", "error", err)
return nil // Don't fail if we can't check
}
usagePercent := float64(availableSpace-requiredSpace) / float64(availableSpace) * 100
if usagePercent < 0 {
usagePercent = 100 + usagePercent // Show how much over we are
}
if availableSpace < requiredSpace {
return fmt.Errorf("insufficient disk space: need %s, have %s",
FormatBytes(requiredSpace), FormatBytes(availableSpace))
return fmt.Errorf("insufficient disk space for restore: %.1f%% used - need at least 4x archive size\\n"+
" Required: %s\\n"+
" Available: %s\\n"+
" Archive: %s\\n"+
" Check location: %s\\n\\n"+
"Tip: Use --workdir to specify extraction directory with more space (e.g., --workdir /u01/dba/restore_tmp)",
usagePercent,
FormatBytes(requiredSpace),
FormatBytes(availableSpace),
FormatBytes(archiveSize),
checkDir)
}
s.log.Info("Disk space check passed",
"location", checkDir,
"required", FormatBytes(requiredSpace),
"available", FormatBytes(availableSpace))