All import paths updated to git.wntrmute.dev/mc/. Bumps mcdsl to v1.2.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
mcdsldb "git.wntrmute.dev/mc/mcdsl/db"
|
|
"git.wntrmute.dev/mc/metacrypt/internal/config"
|
|
"git.wntrmute.dev/mc/metacrypt/internal/db"
|
|
)
|
|
|
|
var snapshotCmd = &cobra.Command{
|
|
Use: "snapshot",
|
|
Short: "Create a database snapshot",
|
|
Long: "Create a backup of the Metacrypt database using SQLite's VACUUM INTO.",
|
|
RunE: runSnapshot,
|
|
}
|
|
|
|
var snapshotOutput string
|
|
|
|
func init() {
|
|
snapshotCmd.Flags().StringVarP(&snapshotOutput, "output", "o", "backup.db", "output file path")
|
|
rootCmd.AddCommand(snapshotCmd)
|
|
}
|
|
|
|
func runSnapshot(cmd *cobra.Command, args []string) error {
|
|
configPath := cfgFile
|
|
if configPath == "" {
|
|
configPath = "/srv/metacrypt/metacrypt.toml"
|
|
}
|
|
|
|
cfg, err := config.Load(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
database, err := db.Open(cfg.Database.Path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() { _ = database.Close() }()
|
|
|
|
if err := mcdsldb.Snapshot(database, snapshotOutput); err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("Snapshot saved to %s\n", snapshotOutput)
|
|
return nil
|
|
}
|