- Implement deterministic blob hashing using double SHA256 of uncompressed plaintext data, enabling deduplication even after local DB is cleared - Add Stat() check before blob upload to skip existing blobs in storage - Add rclone storage backend for additional remote storage options - Add 'vaultik database purge' command to erase local state DB - Add 'vaultik remote check' command to verify remote connectivity - Show configured snapshots in 'vaultik snapshot list' output - Skip macOS resource fork files (._*) when listing remote snapshots - Use multi-threaded zstd compression (CPUs - 2 threads) - Add writer tests for double hashing behavior
103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.eeqj.de/sneak/vaultik/internal/config"
|
|
"git.eeqj.de/sneak/vaultik/internal/log"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewDatabaseCommand creates the database command group
|
|
func NewDatabaseCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "database",
|
|
Short: "Manage the local state database",
|
|
Long: `Commands for managing the local SQLite state database.`,
|
|
}
|
|
|
|
cmd.AddCommand(
|
|
newDatabasePurgeCommand(),
|
|
)
|
|
|
|
return cmd
|
|
}
|
|
|
|
// newDatabasePurgeCommand creates the database purge command
|
|
func newDatabasePurgeCommand() *cobra.Command {
|
|
var force bool
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "purge",
|
|
Short: "Delete the local state database",
|
|
Long: `Completely removes the local SQLite state database.
|
|
|
|
This will erase all local tracking of:
|
|
- File metadata and change detection state
|
|
- Chunk and blob mappings
|
|
- Local snapshot records
|
|
|
|
The remote storage is NOT affected. After purging, the next backup will
|
|
perform a full scan and re-deduplicate against existing remote blobs.
|
|
|
|
Use --force to skip the confirmation prompt.`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
// Resolve config path
|
|
configPath, err := ResolveConfigPath()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Load config to get database path
|
|
cfg, err := config.Load(configPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to load config: %w", err)
|
|
}
|
|
|
|
dbPath := cfg.IndexPath
|
|
|
|
// Check if database exists
|
|
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
|
|
fmt.Printf("Database does not exist: %s\n", dbPath)
|
|
return nil
|
|
}
|
|
|
|
// Confirm unless --force
|
|
if !force {
|
|
fmt.Printf("This will delete the local state database at:\n %s\n\n", dbPath)
|
|
fmt.Print("Are you sure? Type 'yes' to confirm: ")
|
|
var confirm string
|
|
if _, err := fmt.Scanln(&confirm); err != nil || confirm != "yes" {
|
|
fmt.Println("Aborted.")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// Delete the database file
|
|
if err := os.Remove(dbPath); err != nil {
|
|
return fmt.Errorf("failed to delete database: %w", err)
|
|
}
|
|
|
|
// Also delete WAL and SHM files if they exist
|
|
walPath := dbPath + "-wal"
|
|
shmPath := dbPath + "-shm"
|
|
_ = os.Remove(walPath) // Ignore errors - files may not exist
|
|
_ = os.Remove(shmPath)
|
|
|
|
rootFlags := GetRootFlags()
|
|
if !rootFlags.Quiet {
|
|
fmt.Printf("Database purged: %s\n", dbPath)
|
|
}
|
|
|
|
log.Info("Local state database purged", "path", dbPath)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&force, "force", false, "Skip confirmation prompt")
|
|
|
|
return cmd
|
|
}
|