backea/cmd/restore/main.go
2025-03-20 22:14:45 +01:00

52 lines
1.6 KiB
Go

package main
import (
"backea/internal/backup"
b2_client "backea/internal/client"
"context"
"log"
"time"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Println("Starting Kopia Restore Tool")
// Create context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
// Create B2 client
b2Client, err := b2_client.NewClientFromEnv()
if err != nil {
log.Fatalf("Failed to create B2 client: %v", err)
}
// Create restore manager
restoreManager := backup.NewRestoreManager(b2Client)
// List snapshots for the 'montre' service
serviceName := "montre"
log.Printf("Listing snapshots for service '%s' (bucket: 'backea-%s')", serviceName, serviceName)
err = restoreManager.ListSnapshots(ctx, serviceName)
if err != nil {
log.Fatalf("Failed to list snapshots: %v", err)
}
// Example usage of RestoreFile function
// Use the complete snapshot ID from the output
// Looking at your output, let's use the most recent snapshot for /home/gevo/Documents/backea2
snapshotID := "kdf031570cab920b40d296bda16d27ae7" // The latest snapshot ID
sourcePath := "" // Leave empty to restore the entire snapshot
targetPath := "./restored_files" // Local directory to restore files to
log.Printf("Restoring files from snapshot %s to %s", snapshotID, targetPath)
err = restoreManager.RestoreFile(ctx, serviceName, snapshotID, sourcePath, targetPath)
if err != nil {
log.Fatalf("Failed to restore files: %v", err)
}
log.Println("Restore tool completed successfully")
}