DX-13: both shell scripts ran bare 'docker compose', which has no config
file to find in the layout docs/self-hosting.md tells people to use (only
docker-compose.selfhost.yml is downloaded) — they now fall back to it, while
a source checkout keeps resolving docker-compose.yml as before. The two
PowerShell scripts moved the dump through the PS pipeline, which corrupts
binary on 5.1 and cannot express -Encoding Byte at all on 7 ('Byte' is not a
supported encoding name), so they simply failed there; they now write inside
the container and 'docker compose cp' it across. backup.sh also wrote its
output straight into backups/, leaving a truncated file that looks like a
real backup when pg_dump fails — it writes a .part and promotes on success.
Both restores report a non-zero pg_restore rather than printing 'Restored'
over it. Docs now state that a backup is the dump PLUS .env: without
TOKEN_ENCRYPTION_KEY every encrypted secret in the restored database is
unreadable, which the old one-line 'back up the volume' never said.
DX-14: 'latest' moves with every release and migrations run on every boot,
so self-hosters had no way to choose when they move and no way back. Docs
gain IMAGE_TAG pinning, a rollback recipe (image-only vs schema-bearing) and
the migration-failed-at-boot case; CHANGELOG.md is generated from
releaseNotes.ts so the file cannot drift from what the app shows, and
'siftlode release' refuses on a stale one rather than regenerating it into
the clean tree it just demanded.
Verified: dump + restore round-trip on both platforms against localdev into
a scratch database (8 users, 262822 videos, schema 0082_invite_lang), and
IMAGE_TAG=0.80.0 resolves on both services in 'compose config'.
44 lines
2.2 KiB
PowerShell
44 lines
2.2 KiB
PowerShell
# Dumps the Siftlode Postgres database to backups\siftlode-<timestamp>.dump (custom format).
|
|
# Run from the project root: .\scripts\backup.ps1
|
|
#
|
|
# A dump is only HALF a backup. The other half is your .env — it holds TOKEN_ENCRYPTION_KEY, without
|
|
# which every encrypted value in the restored database (Google credentials, SMTP password, Plex
|
|
# token, stored refresh tokens) is unreadable. See docs/self-hosting.md § Backups.
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
# The dump is moved with `docker compose cp`, never through the PowerShell pipeline. Piping a binary
|
|
# stream corrupts it on Windows PowerShell 5.1 (text decoding), and on PowerShell 7 the old
|
|
# `-Encoding Byte` workaround does not even exist any more — it throws "'Byte' is not a supported
|
|
# encoding name", so this script simply failed there.
|
|
$remote = "/tmp/siftlode-backup.dump"
|
|
|
|
# `docker compose` finds docker-compose.yml on its own and honours $env:COMPOSE_FILE. The documented
|
|
# self-host layout (docs/self-hosting.md § Get the files) has NEITHER — just the selfhost file.
|
|
if (-not $env:COMPOSE_FILE -and -not (Test-Path "docker-compose.yml") -and (Test-Path "docker-compose.selfhost.yml")) {
|
|
$env:COMPOSE_FILE = "docker-compose.selfhost.yml"
|
|
}
|
|
|
|
$user = if ($env:POSTGRES_USER) { $env:POSTGRES_USER } else { "siftlode" }
|
|
$dbname = if ($env:POSTGRES_DB) { $env:POSTGRES_DB } else { "siftlode" }
|
|
New-Item -ItemType Directory -Force -Path "backups" | Out-Null
|
|
$ts = Get-Date -Format "yyyyMMdd-HHmmss"
|
|
$out = "backups\siftlode-$ts.dump"
|
|
|
|
docker compose exec -T db pg_dump -U $user -Fc $dbname -f $remote
|
|
if ($LASTEXITCODE -ne 0) {
|
|
docker compose exec -T db rm -f $remote 2>$null
|
|
throw "BACKUP FAILED — pg_dump returned $LASTEXITCODE; no file was written."
|
|
}
|
|
|
|
docker compose cp "db:$remote" $out
|
|
$cpCode = $LASTEXITCODE
|
|
docker compose exec -T db rm -f $remote 2>$null
|
|
if ($cpCode -ne 0) { throw "BACKUP FAILED — could not copy the dump out of the container (exit $cpCode)." }
|
|
if (-not (Test-Path $out) -or (Get-Item $out).Length -eq 0) {
|
|
if (Test-Path $out) { Remove-Item $out }
|
|
throw "BACKUP FAILED — the dump came out empty; no backup was written."
|
|
}
|
|
|
|
Write-Output "Wrote $out"
|
|
Write-Output "Remember: back up your .env too (TOKEN_ENCRYPTION_KEY) — this dump alone cannot be fully restored."
|