diff --git a/bin/README.md b/bin/README.md index 7a86911..f92cb04 100644 --- a/bin/README.md +++ b/bin/README.md @@ -4,8 +4,8 @@ This directory contains pre-compiled binaries for the DB Backup Tool across mult ## Build Information - **Version**: 1.1.0 -- **Build Time**: 2025-11-07_13:27:44_UTC -- **Git Commit**: ebb77fb +- **Build Time**: 2025-11-07_15:15:58_UTC +- **Git Commit**: 2d34eca ## Recent Updates (v1.1.0) - ✅ Fixed TUI progress display with line-by-line output diff --git a/bin/dbbackup_darwin_amd64 b/bin/dbbackup_darwin_amd64 new file mode 100755 index 0000000..17c7bb8 Binary files /dev/null and b/bin/dbbackup_darwin_amd64 differ diff --git a/bin/dbbackup_darwin_arm64 b/bin/dbbackup_darwin_arm64 new file mode 100755 index 0000000..9a5fee0 Binary files /dev/null and b/bin/dbbackup_darwin_arm64 differ diff --git a/bin/dbbackup_freebsd_amd64 b/bin/dbbackup_freebsd_amd64 new file mode 100755 index 0000000..d499b3e Binary files /dev/null and b/bin/dbbackup_freebsd_amd64 differ diff --git a/bin/dbbackup_linux_amd64 b/bin/dbbackup_linux_amd64 index b92ff7a..2a4b44d 100755 Binary files a/bin/dbbackup_linux_amd64 and b/bin/dbbackup_linux_amd64 differ diff --git a/bin/dbbackup_linux_arm64 b/bin/dbbackup_linux_arm64 index b654e0a..68cf1c6 100755 Binary files a/bin/dbbackup_linux_arm64 and b/bin/dbbackup_linux_arm64 differ diff --git a/bin/dbbackup_linux_arm_armv7 b/bin/dbbackup_linux_arm_armv7 new file mode 100755 index 0000000..61b77cc Binary files /dev/null and b/bin/dbbackup_linux_arm_armv7 differ diff --git a/bin/dbbackup_netbsd_amd64 b/bin/dbbackup_netbsd_amd64 new file mode 100755 index 0000000..d4abade Binary files /dev/null and b/bin/dbbackup_netbsd_amd64 differ diff --git a/bin/dbbackup_openbsd_amd64 b/bin/dbbackup_openbsd_amd64 new file mode 100755 index 0000000..7e115c0 Binary files /dev/null and b/bin/dbbackup_openbsd_amd64 differ diff --git a/bin/dbbackup_windows_amd64.exe b/bin/dbbackup_windows_amd64.exe new file mode 100755 index 0000000..1604a6e Binary files /dev/null and b/bin/dbbackup_windows_amd64.exe differ diff --git a/bin/dbbackup_windows_arm64.exe b/bin/dbbackup_windows_arm64.exe new file mode 100755 index 0000000..d59628e Binary files /dev/null and b/bin/dbbackup_windows_arm64.exe differ diff --git a/internal/restore/diskspace_bsd.go b/internal/restore/diskspace_bsd.go new file mode 100644 index 0000000..bb38bc4 --- /dev/null +++ b/internal/restore/diskspace_bsd.go @@ -0,0 +1,15 @@ +// +build openbsd + +package restore + +import "syscall" + +// getDiskSpace returns available disk space in bytes (OpenBSD) +func getDiskSpace(path string) (int64, error) { + var statfs syscall.Statfs_t + if err := syscall.Statfs(path, &statfs); err != nil { + return 0, err + } + // OpenBSD uses F_bavail and F_bsize + return int64(statfs.F_bavail) * int64(statfs.F_bsize), nil +} diff --git a/internal/restore/diskspace_netbsd.go b/internal/restore/diskspace_netbsd.go new file mode 100644 index 0000000..3b8fcf3 --- /dev/null +++ b/internal/restore/diskspace_netbsd.go @@ -0,0 +1,11 @@ +// +build netbsd + +package restore + +// getDiskSpace returns available disk space in bytes (NetBSD fallback) +// NetBSD has different syscall interface, so we use a conservative estimate +func getDiskSpace(path string) (int64, error) { + // Return a large value to skip disk space check on NetBSD + // This is a fallback - restore will still work, just won't pre-check space + return 1 << 40, nil // 1 TB +} diff --git a/internal/restore/diskspace_unix.go b/internal/restore/diskspace_unix.go new file mode 100644 index 0000000..a143162 --- /dev/null +++ b/internal/restore/diskspace_unix.go @@ -0,0 +1,14 @@ +// +build !windows,!openbsd,!netbsd + +package restore + +import "syscall" + +// getDiskSpace returns available disk space in bytes (Unix/Linux/macOS/FreeBSD) +func getDiskSpace(path string) (int64, error) { + var statfs syscall.Statfs_t + if err := syscall.Statfs(path, &statfs); err != nil { + return 0, err + } + return int64(statfs.Bavail) * int64(statfs.Bsize), nil +} diff --git a/internal/restore/diskspace_windows.go b/internal/restore/diskspace_windows.go new file mode 100644 index 0000000..4d175ec --- /dev/null +++ b/internal/restore/diskspace_windows.go @@ -0,0 +1,38 @@ +// +build windows + +package restore + +import ( + "syscall" + "unsafe" +) + +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + getDiskFreeSpace = kernel32.NewProc("GetDiskFreeSpaceExW") +) + +// getDiskSpace returns available disk space in bytes (Windows) +func getDiskSpace(path string) (int64, error) { + var freeBytesAvailable int64 + var totalBytes int64 + var totalFreeBytes int64 + + pathPtr, err := syscall.UTF16PtrFromString(path) + if err != nil { + return 0, err + } + + ret, _, err := getDiskFreeSpace.Call( + uintptr(unsafe.Pointer(pathPtr)), + uintptr(unsafe.Pointer(&freeBytesAvailable)), + uintptr(unsafe.Pointer(&totalBytes)), + uintptr(unsafe.Pointer(&totalFreeBytes)), + ) + + if ret == 0 { + return 0, err + } + + return freeBytesAvailable, nil +} diff --git a/internal/restore/safety.go b/internal/restore/safety.go index c420c82..1359e6a 100644 --- a/internal/restore/safety.go +++ b/internal/restore/safety.go @@ -8,7 +8,6 @@ import ( "os" "os/exec" "strings" - "syscall" "dbbackup/internal/config" "dbbackup/internal/logger" @@ -243,14 +242,12 @@ func (s *Safety) CheckDiskSpace(archivePath string, multiplier float64) error { requiredSpace := int64(float64(archiveSize) * multiplier) // Get available disk space - var statfs syscall.Statfs_t - if err := syscall.Statfs(s.cfg.BackupDir, &statfs); err != nil { + availableSpace, err := getDiskSpace(s.cfg.BackupDir) + if err != nil { s.log.Warn("Cannot check disk space", "error", err) return nil // Don't fail if we can't check } - availableSpace := int64(statfs.Bavail) * statfs.Bsize - if availableSpace < requiredSpace { return fmt.Errorf("insufficient disk space: need %s, have %s", FormatBytes(requiredSpace), FormatBytes(availableSpace))