remove s3 from client

This commit is contained in:
2026-02-15 11:41:05 +01:00
parent 5892ac2a2e
commit 8b592db3dd
10 changed files with 291 additions and 582 deletions

View File

@@ -58,7 +58,7 @@ func printUsage() {
fmt.Println("ZFS Snapshot Backup Client - Simple Version")
fmt.Println("\nUsage: zfs-client [command]")
fmt.Println("\nCommands:")
fmt.Println(" snap - Create snapshot and send to server (auto full/incremental)")
fmt.Println(" snap - Create snapshot and send to server")
fmt.Println(" status - Check server connection and quota")
fmt.Println(" help - Show this help message")
fmt.Println("\nEnvironment Variables (can be set in .env file):")
@@ -67,12 +67,6 @@ func printUsage() {
fmt.Println(" SERVER_URL - Backup server URL (default: http://localhost:8080)")
fmt.Println(" LOCAL_DATASET - ZFS dataset to backup (default: tank/data)")
fmt.Println(" COMPRESS - Enable LZ4 compression (default: true)")
fmt.Println("\nS3 Configuration (for direct S3 uploads):")
fmt.Println(" S3_ENDPOINT - S3 endpoint URL (e.g., https://s3.amazonaws.com)")
fmt.Println(" S3_REGION - AWS region (default: us-east-1)")
fmt.Println(" S3_BUCKET - S3 bucket name (default: zfs-backups)")
fmt.Println(" S3_ACCESS_KEY - AWS access key")
fmt.Println(" S3_SECRET_KEY - AWS secret key")
fmt.Println("\nExamples:")
fmt.Println(" zfs-client snap")
fmt.Println(" zfs-client status")

View File

@@ -1,5 +1,4 @@
// Command zfs-restore is a CLI tool for restoring ZFS snapshots from a backup server.
// It provides commands for listing, restoring, and mounting snapshots.
// Command zfs-restore is a simple CLI tool for restoring ZFS snapshots from a backup server.
package main
import (
@@ -23,7 +22,8 @@ func main() {
command := os.Args[1]
switch command {
case "list":
case "list", "ls":
// List available snapshots
snapshots, err := client.ListSnapshots()
if err != nil {
fmt.Printf("Error: %v\n", err)
@@ -32,8 +32,13 @@ func main() {
client.DisplaySnapshots(snapshots)
case "restore":
if len(os.Args) < 4 {
fmt.Println("Usage: zfs-restore restore <snapshot-number> <target-dataset> [--force]")
// Restore snapshot - can use number or "latest" keyword
if len(os.Args) < 3 {
fmt.Println("Usage: zfs-restore restore <snapshot-number-or-latest> <target-dataset> [--force]")
fmt.Println("\nExamples:")
fmt.Println(" zfs-restore restore 1 tank/restored")
fmt.Println(" zfs-restore restore latest tank/restored")
fmt.Println(" zfs-restore restore latest tank/restored --force")
os.Exit(1)
}
@@ -48,103 +53,56 @@ func main() {
return snapshots[i].Timestamp.After(snapshots[j].Timestamp)
})
// Parse snapshot number
var snapNum int
fmt.Sscanf(os.Args[2], "%d", &snapNum)
if snapNum < 1 || snapNum > len(snapshots) {
fmt.Printf("Invalid snapshot number. Use 'list' to see available snapshots.\n")
if len(snapshots) == 0 {
fmt.Println("No snapshots available. Run 'zfs-restore list' first.")
os.Exit(1)
}
snapshot := snapshots[snapNum-1]
targetDataset := os.Args[3]
force := len(os.Args) > 4 && os.Args[4] == "--force"
snapshotArg := os.Args[2]
var snapshot *restore.SnapshotMetadata
if snapshotArg == "latest" {
snapshot = snapshots[0]
fmt.Printf("→ Restoring latest snapshot from %s\n", snapshot.Timestamp.Format("2006-01-02 15:04:05"))
} else {
var snapNum int
fmt.Sscanf(snapshotArg, "%d", &snapNum)
if snapNum < 1 || snapNum > len(snapshots) {
fmt.Printf("Invalid snapshot number. Use 'zfs-restore list' to see available snapshots.\n")
os.Exit(1)
}
snapshot = snapshots[snapNum-1]
}
// Get target dataset (either from args or prompt)
targetDataset := ""
force := false
for i, arg := range os.Args {
if arg == "--force" {
force = true
}
if arg != "restore" && arg != snapshotArg && arg != "--force" && targetDataset == "" && i > 2 && arg != os.Args[0] {
targetDataset = arg
}
}
if targetDataset == "" {
fmt.Printf("Target dataset: ")
fmt.Scanln(&targetDataset)
}
if targetDataset == "" {
fmt.Println("Error: target dataset is required")
os.Exit(1)
}
if err := client.RestoreSnapshot(snapshot, targetDataset, force); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
case "save":
if len(os.Args) < 4 {
fmt.Println("Usage: zfs-restore save <snapshot-number> <output-file>")
os.Exit(1)
}
snapshots, err := client.ListSnapshots()
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
sort.Slice(snapshots, func(i, j int) bool {
return snapshots[i].Timestamp.After(snapshots[j].Timestamp)
})
var snapNum int
fmt.Sscanf(os.Args[2], "%d", &snapNum)
if snapNum < 1 || snapNum > len(snapshots) {
fmt.Printf("Invalid snapshot number.\n")
os.Exit(1)
}
snapshot := snapshots[snapNum-1]
outputFile := os.Args[3]
if err := client.RestoreToFile(snapshot, outputFile); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
case "mount":
if len(os.Args) < 4 {
fmt.Println("Usage: zfs-restore mount <dataset> <mountpoint>")
os.Exit(1)
}
dataset := os.Args[2]
mountpoint := os.Args[3]
if err := client.MountSnapshot(dataset, mountpoint); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
case "latest":
if len(os.Args) < 3 {
fmt.Println("Usage: zfs-restore latest <target-dataset> [--force]")
os.Exit(1)
}
snapshots, err := client.ListSnapshots()
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
if len(snapshots) == 0 {
fmt.Println("No snapshots available")
os.Exit(1)
}
// Sort and get latest
sort.Slice(snapshots, func(i, j int) bool {
return snapshots[i].Timestamp.After(snapshots[j].Timestamp)
})
latest := snapshots[0]
targetDataset := os.Args[2]
force := len(os.Args) > 3 && os.Args[3] == "--force"
fmt.Printf("Restoring latest snapshot from %s\n", latest.Timestamp.Format("2006-01-02 15:04:05"))
if err := client.RestoreSnapshot(latest, targetDataset, force); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
case "help", "-h", "--help":
printUsage()
@@ -156,21 +114,16 @@ func main() {
}
func printUsage() {
fmt.Println("ZFS Snapshot Restore Tool")
fmt.Println("\nUsage: zfs-restore [command] [options]")
fmt.Println("ZFS Snapshot Restore Tool - Simple Version")
fmt.Println("\nUsage: zfs-restore [command]")
fmt.Println("\nCommands:")
fmt.Println(" list - List available snapshots")
fmt.Println(" restore <#> <dataset> [--force] - Restore snapshot to ZFS dataset")
fmt.Println(" latest <dataset> [--force] - Restore most recent snapshot")
fmt.Println(" save <#> <file> - Save snapshot to file")
fmt.Println(" mount <dataset> <mountpoint> - Mount restored dataset")
fmt.Println(" help - Show this help message")
fmt.Println("\nExamples:")
fmt.Println(" zfs-restore list")
fmt.Println(" zfs-restore restore 1 tank/restored")
fmt.Println(" zfs-restore latest tank/restored --force")
fmt.Println(" zfs-restore save 2 backup.zfs.lz4")
fmt.Println(" zfs-restore mount tank/restored /mnt/restore")
fmt.Println(" list - List available snapshots")
fmt.Println(" restore <#|latest> <dataset> [--force] - Restore snapshot to ZFS")
fmt.Println(" help - Show this help message")
fmt.Println("\nQuick Examples:")
fmt.Println(" zfs-restore list - See available backups")
fmt.Println(" zfs-restore restore latest tank/data - Restore most recent backup")
fmt.Println(" zfs-restore restore 1 tank/restored - Restore snapshot #1")
fmt.Println("\nEnvironment Variables (can be set in .env file):")
fmt.Println(" CLIENT_ID - Client identifier (default: client1)")
fmt.Println(" API_KEY - API key for authentication (default: secret123)")

View File

@@ -19,7 +19,7 @@ func main() {
var err error
if cfg.S3Enabled {
s3Backend, err = server.NewS3Backend(cfg.S3Endpoint, cfg.S3AccessKey, cfg.S3SecretKey, cfg.S3BucketName, cfg.S3UseSSL, cfg.S3Region)
s3Backend, err = server.NewS3Backend(cfg.S3Endpoint, cfg.S3AccessKey, cfg.S3SecretKey, cfg.S3BucketName, cfg.S3UseSSL)
if err != nil {
log.Fatalf("Failed to initialize S3 backend: %v", err)
}