83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
// Command zfs-client is a simple CLI tool for creating and sending ZFS snapshots.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.ma-al.com/goc_marek/zfs/internal/client"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
printUsage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Load configuration from environment and .env file
|
|
config := client.LoadConfig()
|
|
c := client.New(config)
|
|
|
|
command := os.Args[1]
|
|
|
|
switch command {
|
|
case "snap", "snapshot":
|
|
// Create snapshot and send to server (auto full/incremental)
|
|
// Optional: specify dataset as argument
|
|
targetDataset := ""
|
|
if len(os.Args) > 2 {
|
|
targetDataset = os.Args[2]
|
|
fmt.Printf("→ Using dataset: %s\n", targetDataset)
|
|
}
|
|
|
|
fmt.Println("=== Creating and sending snapshot ===\n")
|
|
|
|
snapshot, err := c.CreateAndSend(targetDataset)
|
|
if err != nil {
|
|
fmt.Printf("Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if snapshot.FullBackup {
|
|
fmt.Println("\n✓ Full backup completed!")
|
|
} else {
|
|
fmt.Println("\n✓ Incremental backup completed!")
|
|
}
|
|
|
|
case "status":
|
|
// Check server connection and quota
|
|
if err := c.GetStatus(); err != nil {
|
|
fmt.Printf("Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
case "help", "-h", "--help":
|
|
printUsage()
|
|
|
|
default:
|
|
fmt.Printf("Unknown command: %s\n", command)
|
|
printUsage()
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func printUsage() {
|
|
fmt.Println("ZFS Snapshot Backup Client - Simple Version")
|
|
fmt.Println("\nUsage: zfs-client [command] [dataset]")
|
|
fmt.Println("\nCommands:")
|
|
fmt.Println(" snap [dataset] - Create snapshot and send to server")
|
|
fmt.Println(" If dataset not specified, uses LOCAL_DATASET from config")
|
|
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):")
|
|
fmt.Println(" CLIENT_ID - Client identifier (default: client1)")
|
|
fmt.Println(" API_KEY - API key for authentication (default: secret123)")
|
|
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("\nExamples:")
|
|
fmt.Println(" zfs-client snap # Use configured dataset")
|
|
fmt.Println(" zfs-client snap tank/data # Backup specific dataset")
|
|
fmt.Println(" zfs-client status")
|
|
}
|