Files
nib-v1/cmd/backup.go
lerko e9ecc4c1f7
CI / test (pull_request) Successful in 2m13s
fix: address code review findings across backend and frontend
Fix goroutine-unsafe ULID entropy by wrapping in LockedMonotonicReader.
Move PRAGMA foreign_keys outside transaction in v3 migration where
SQLite was silently ignoring it. Escape LIKE wildcards in link
resolution to prevent false matches. Add non-localhost binding warning,
log writeJSON encoder errors, add ?permanent=true for explicit hard
delete, preserve title/description during absorb, use millisecond
backup timestamps, add path.Clean to spaHandler. Frontend gains
checkedJSON() for resp.ok validation, consistent stopPropagation, and
shared renderCardSections() to eliminate duplicate rendering.
2026-05-21 16:02:57 -04:00

47 lines
900 B
Go

package cmd
import (
"fmt"
"time"
"github.com/lerko/nib/internal/db"
"github.com/spf13/cobra"
)
var backupCmd = &cobra.Command{
Use: "backup [path]",
Short: "create a safe backup of the database",
Long: "Creates an atomic backup using VACUUM INTO. Safe with WAL mode — no need to stop the server.",
Args: cobra.MaximumNArgs(1),
RunE: runBackup,
}
func init() {
rootCmd.AddCommand(backupCmd)
}
func runBackup(cmd *cobra.Command, args []string) error {
srcPath, err := db.DefaultPath()
if err != nil {
return err
}
dst := fmt.Sprintf("%s.backup-%s", srcPath, time.Now().Format("20060102-150405.000"))
if len(args) > 0 {
dst = args[0]
}
store, err := db.Open(srcPath)
if err != nil {
return err
}
defer store.Close()
if err := store.Backup(dst); err != nil {
return fmt.Errorf("backup failed: %w", err)
}
fmt.Printf("backed up to %s\n", dst)
return nil
}