snow-editor

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

restore-db.ps1 (767B)


      1 param(
      2     [Parameter(Mandatory = $true)]
      3     [string]$Backup
      4 )
      5 
      6 $Root = Split-Path -Parent $PSScriptRoot
      7 $Db = Join-Path $Root "data\snow.db"
      8 $BackupDir = Join-Path $Root "data\backups"
      9 
     10 $Source = $Backup
     11 if (-not (Test-Path $Source)) {
     12     $Source = Join-Path $BackupDir $Backup
     13 }
     14 
     15 if (-not (Test-Path $Source)) {
     16     Write-Error "Backup not found: $Source"
     17     exit 1
     18 }
     19 
     20 Write-Host "This will overwrite $Db with:"
     21 Write-Host "  $Source"
     22 Write-Host "Stop the backend first: docker compose stop backend"
     23 $Confirm = Read-Host "Type RESTORE to continue"
     24 
     25 if ($Confirm -ne "RESTORE") {
     26     Write-Host "Aborted."
     27     exit 0
     28 }
     29 
     30 New-Item -ItemType Directory -Force -Path (Split-Path $Db) | Out-Null
     31 Copy-Item $Source $Db -Force
     32 Write-Host "Database restored from $Source"