snow-editor

small markdown and org-mode editor
Log | Files | Refs | README

backup-db.ps1 (640B)


      1 $Root = Split-Path -Parent $PSScriptRoot
      2 $Db = Join-Path $Root "data\snow.db"
      3 $BackupDir = Join-Path $Root "data\backups"
      4 
      5 if (-not (Test-Path $Db)) {
      6     Write-Error "Database not found: $Db"
      7     exit 1
      8 }
      9 
     10 New-Item -ItemType Directory -Force -Path $BackupDir | Out-Null
     11 $Stamp = Get-Date -Format "yyyy-MM-dd-HHmmss"
     12 $Dest = Join-Path $BackupDir "snow-$Stamp.db"
     13 
     14 $sqlite3 = Get-Command sqlite3 -ErrorAction SilentlyContinue
     15 if ($sqlite3) {
     16     & sqlite3 $Db ".backup '$Dest'"
     17 } else {
     18     Write-Host "sqlite3 not found — copying file (stop the backend first for a safe copy)."
     19     Copy-Item $Db $Dest
     20 }
     21 
     22 Write-Host "Backup saved: $Dest"