# Unpacks an archive made by backup.ps1 (or backup.sh) into a data volume. # The volume must be new or empty: this never writes over existing data. # # usage: .\restore.ps1 # .\restore.ps1 .\backups\rasterizeddb-data-20261127T101500Z.tar.gz rasterizeddb-restored param( [Parameter(Mandatory = $true, Position = 0)] [string] $Archive, [Parameter(Mandatory = $true, Position = 1)] [string] $Volume, [string] $Image = 'milendenev/rasterizeddb:1.1.0' ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -PathType Leaf $Archive)) { throw "No such file: $Archive" } $full = (Resolve-Path $Archive).Path $dir = Split-Path -Parent $full $name = Split-Path -Leaf $full $existing = docker volume ls -q --filter "name=^${Volume}$" if ($LASTEXITCODE -ne 0) { throw 'docker volume ls failed' } if ($existing -contains $Volume) { docker run --rm --user 0 --entrypoint sh -v "${Volume}:/data" $Image -c '[ $(ls -A /data | wc -l) -eq 0 ]' if ($LASTEXITCODE -ne 0) { throw "Volume $Volume is not empty. Restore into a new volume, or remove this one first." } } else { docker volume create $Volume | Out-Null if ($LASTEXITCODE -ne 0) { throw "docker volume create $Volume failed" } } # As root, so the files keep their owner (uid 10001) and modes. docker run --rm --user 0 --entrypoint sh ` -v "${Volume}:/data" ` --mount "type=bind,source=$dir,target=/backup,readonly" ` $Image -c "tar --numeric-owner -xzpf '/backup/$name' -C /data && chown 10001:10001 /data && chmod 700 /data && sync" if ($LASTEXITCODE -ne 0) { throw 'the restore failed' } Write-Host "Restored $Archive into volume $Volume."