RustFS all-in-one
The rustfs image runs RasterizedDB and RustFS (S3-compatible object storage) in one container, already wired together: continuous backup into one bucket, and a store for S3-backed tables in another. Use it when you want backups and object-backed tables on a single host without running a second service.
What you get
At start-up RustFS starts first, the two buckets are created if missing, and then the server starts with:
- Continuous backup to the bucket
rasterizeddb-backup: snapshots plus the archived log.BACKUP DATABASEandSHOW BACKUPSwork at once. - S3-backed tables in the bucket
rasterizeddb-tables, through a store namedrustfs. A table placed there keeps its rows in RustFS instead of in/var/lib/rasterizeddb.
| Port | |
|---|---|
| 5432 | PostgreSQL protocol |
| 61170 | native protocol |
| 9000 | S3 API. Not published here: the server reaches it inside the container. |
| 9001 | RustFS console, published on 127.0.0.1 |
| Volume | Holds |
|---|---|
/var/lib/rasterizeddb | the database |
/data | RustFS's objects: the backups and the S3-backed tables |
Both processes run as uid 10001. docker stop stops the database first, which still writes to RustFS while it shuts down, then RustFS. If either process ends on its own, the other is stopped and the container exits, so the restart policy brings both back.
Prerequisites
- Docker, with the Compose plugin for
compose.yaml. - On x86-64, a CPU with AVX2 (x86-64-v3).
psqlto check the result.
What to edit
Three settings are required:
| Variable | |
|---|---|
RASTERIZEDDB_PG_PASSWORD | the password of the role rasterized, for both protocols |
RUSTFS_ACCESS_KEY, RUSTFS_SECRET_KEY | RustFS's root credentials. The server signs with them too. The container refuses RustFS's default, rustfsadmin. |
Optional, with their defaults:
| Variable | Default | |
|---|---|---|
RASTERIZEDDB_BACKUP_BUCKET | rasterizeddb-backup | |
RASTERIZEDDB_TABLES_BUCKET | rasterizeddb-tables | must differ from the backup bucket |
RASTERIZEDDB_S3_STORE | rustfs | the store name in kv:<name> |
RASTERIZEDDB_S3_BACKUP | on | off leaves backups off |
With Compose, copy .env.example to .env and set the three secrets. With the scripts, set them in the environment.
Run it
Compose:
docker compose up -d
docker compose logs -f rasterizeddbLinux and macOS:
export RASTERIZEDDB_PG_PASSWORD='a-long-random-password'
export RUSTFS_ACCESS_KEY='rdb-admin'
export RUSTFS_SECRET_KEY='another-long-random-secret'
./run.shWindows:
$env:RASTERIZEDDB_PG_PASSWORD = 'a-long-random-password'
$env:RUSTFS_ACCESS_KEY = 'rdb-admin'
$env:RUSTFS_SECRET_KEY = 'another-long-random-secret'
.\run.ps1The server is ready when the log shows a line starting rasterizeddb-rustfs: ready.
Check that it works
Make one table on the S3 store and one on local disk, and take a backup:
psql "host=127.0.0.1 port=5432 user=rasterized dbname=postgres sslmode=require" \
-c "STORAGE PLACE TABLE events AT 'kv:rustfs'" \
-c "CREATE TABLE events (id BIGINT PRIMARY KEY, body TEXT)" \
-c "INSERT INTO events VALUES (1, 'stored in RustFS')" \
-c "CREATE TABLE notes (id BIGINT PRIMARY KEY, body TEXT)" \
-c "SHOW TABLES" \
-c "BACKUP DATABASE" \
-c "SHOW BACKUPS"SHOW TABLES reports events on s3 and notes on file. An existing table moves to the store with:
STORAGE MOVE TABLE notes TO 'kv:rustfs';Prove that a backup restores, inside the running container, without touching the live database. The server's S3 credentials are RustFS's, taken from the container's environment:
docker exec rasterizeddb sh -c '
AWS_ACCESS_KEY_ID="$RUSTFS_ACCESS_KEY" AWS_SECRET_ACCESS_KEY="$RUSTFS_SECRET_KEY" \
rasterizeddb --s3-endpoint http://127.0.0.1:9000 --s3-path-style \
--s3-bucket rasterizeddb-backup --restore-to /tmp/verify && rm -rf /tmp/verify'It prints a line starting Restored snapshot with what it rebuilt.
The RustFS console is at http://127.0.0.1:9001. Log in with the RustFS access and secret key.
Stop and clean up
docker compose down # Compose: keeps both volumes
docker compose down -v # Compose: deletes the database AND its backupsWithout Compose:
docker stop -t 90 rasterizeddb
docker rm rasterizeddb
docker volume rm rasterizeddb-db rasterizeddb-s3 # deletes the database AND its backupsLimits
- The backups live on the same host, and with the default volumes on the same disk, as the database. That survives a dropped table or a bad deploy, not a lost disk. Put
/dataon another disk, or copy the bucket elsewhere: the image ships RustFS'srcclient, whoserc mirrorcopies a bucket. - A table on the S3 store is backed up as of each snapshot, with no point-in-time replay of its changes.
- An in-place restore (
--restore-from-s3) does not work inside this image, and a restored database needs a backup prefix of its own (add--s3-prefix <new name>after the image name). Compose with S3 backups runs RustFS as a separate service and has the full restore procedure.
The files
#!/usr/bin/env bash
# Starts the `rustfs` image: RasterizedDB and RustFS object storage in one
# container, with continuous backup and S3-backed tables already set up.
#
# export RASTERIZEDDB_PG_PASSWORD='a-long-random-password'
# export RUSTFS_ACCESS_KEY='rdb-admin'
# export RUSTFS_SECRET_KEY='another-long-random-secret'
# ./run.sh # anything after the script name goes to the server
#
# Optional: IMAGE, NAME, BIND (default 127.0.0.1), DB_VOLUME, S3_VOLUME.
set -euo pipefail
IMAGE="${IMAGE:-milendenev/rasterizeddb:1.1.0-rustfs}"
NAME="${NAME:-rasterizeddb}"
BIND="${BIND:-127.0.0.1}"
DB_VOLUME="${DB_VOLUME:-rasterizeddb-db}"
S3_VOLUME="${S3_VOLUME:-rasterizeddb-s3}"
for var in RASTERIZEDDB_PG_PASSWORD RUSTFS_ACCESS_KEY RUSTFS_SECRET_KEY; do
if [ -z "${!var:-}" ]; then
echo "Set $var first." >&2
exit 1
fi
done
docker volume create "$DB_VOLUME" >/dev/null
docker volume create "$S3_VOLUME" >/dev/null
# The variables are passed by name, so their values stay off the docker
# command line. Port 9001 (the RustFS console) is published on BIND too;
# 9000 (the S3 API) is not, since the server reaches it inside the container.
docker run -d \
--name "$NAME" \
--restart unless-stopped \
--stop-timeout 90 \
-e RASTERIZEDDB_PG_PASSWORD \
-e RUSTFS_ACCESS_KEY \
-e RUSTFS_SECRET_KEY \
-p "$BIND:5432:5432" \
-p "$BIND:61170:61170" \
-p "$BIND:9001:9001" \
-v "$DB_VOLUME:/var/lib/rasterizeddb" \
-v "$S3_VOLUME:/data" \
"$IMAGE" "$@"
echo "Started $NAME from $IMAGE. Wait for 'rasterizeddb-rustfs: ready' in: docker logs -f $NAME"# Starts the `rustfs` image: RasterizedDB and RustFS object storage in one
# container, with continuous backup and S3-backed tables already set up.
#
# $env:RASTERIZEDDB_PG_PASSWORD = 'a-long-random-password'
# $env:RUSTFS_ACCESS_KEY = 'rdb-admin'
# $env:RUSTFS_SECRET_KEY = 'another-long-random-secret'
# .\run.ps1
# .\run.ps1 -ServerArgs '--log-level', 'info' # server flags, after the image's own
param(
[string] $Image = 'milendenev/rasterizeddb:1.1.0-rustfs',
[string] $Name = 'rasterizeddb',
[string] $Bind = '127.0.0.1',
[string] $DbVolume = 'rasterizeddb-db',
[string] $S3Volume = 'rasterizeddb-s3',
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $ServerArgs
)
$ErrorActionPreference = 'Stop'
foreach ($var in 'RASTERIZEDDB_PG_PASSWORD', 'RUSTFS_ACCESS_KEY', 'RUSTFS_SECRET_KEY') {
if (-not [Environment]::GetEnvironmentVariable($var)) { throw "Set `$env:$var first." }
}
foreach ($volume in $DbVolume, $S3Volume) {
docker volume create $volume | Out-Null
if ($LASTEXITCODE -ne 0) { throw "docker volume create $volume failed" }
}
# The variables are passed by name, so their values stay off the docker
# command line. Port 9001 (the RustFS console) is published on $Bind too;
# 9000 (the S3 API) is not, since the server reaches it inside the container.
$runArgs = @(
'run', '-d',
'--name', $Name,
'--restart', 'unless-stopped',
'--stop-timeout', '90',
'-e', 'RASTERIZEDDB_PG_PASSWORD',
'-e', 'RUSTFS_ACCESS_KEY',
'-e', 'RUSTFS_SECRET_KEY',
'-p', "${Bind}:5432:5432",
'-p', "${Bind}:61170:61170",
'-p', "${Bind}:9001:9001",
'-v', "${DbVolume}:/var/lib/rasterizeddb",
'-v', "${S3Volume}:/data",
$Image
)
if ($ServerArgs) { $runArgs += $ServerArgs }
docker @runArgs
if ($LASTEXITCODE -ne 0) { throw "docker run failed" }
Write-Host "Started $Name from $Image. Wait for 'rasterizeddb-rustfs: ready' in: docker logs -f $Name"# The `rustfs` image under Compose: RasterizedDB and RustFS in one container.
# Copy .env.example to .env first.
name: rasterizeddb-rustfs
services:
rasterizeddb:
image: ${RASTERIZEDDB_IMAGE:-milendenev/rasterizeddb:1.1.0-rustfs}
environment:
RASTERIZEDDB_PG_PASSWORD: ${RASTERIZEDDB_PG_PASSWORD:?set RASTERIZEDDB_PG_PASSWORD in .env}
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY:?set RUSTFS_ACCESS_KEY in .env}
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY:?set RUSTFS_SECRET_KEY in .env}
# Optional, shown with their defaults:
RASTERIZEDDB_BACKUP_BUCKET: rasterizeddb-backup
RASTERIZEDDB_TABLES_BUCKET: rasterizeddb-tables
RASTERIZEDDB_S3_STORE: rustfs
RASTERIZEDDB_S3_BACKUP: "on"
# Extra server flags, added after the entrypoint's own.
command: ["--log-level", "warn"]
ports:
- "127.0.0.1:5432:5432" # PostgreSQL protocol
- "127.0.0.1:61170:61170" # native protocol
- "127.0.0.1:9001:9001" # RustFS console
volumes:
- db:/var/lib/rasterizeddb
- s3:/data
restart: unless-stopped
# The database stops first, then RustFS.
stop_grace_period: 90s
healthcheck:
# This image has psql: check that a query succeeds.
test: ["CMD-SHELL", "PGPASSWORD=\"$$RASTERIZEDDB_PG_PASSWORD\" psql \"host=127.0.0.1 port=5432 user=rasterized dbname=postgres sslmode=require connect_timeout=3\" -qAtX -c 'SELECT 1'"]
interval: 10s
timeout: 10s
retries: 6
start_period: 60s
volumes:
db:
s3:# Copy to .env next to compose.yaml and change every secret.
# The password of the role `rasterized`, used on the first start only.
RASTERIZEDDB_PG_PASSWORD=change-me-to-a-long-random-password
# RustFS's root credentials; the server signs its backups and S3 tables with
# them. Must not be RustFS's default (rustfsadmin).
RUSTFS_ACCESS_KEY=rdb-admin
RUSTFS_SECRET_KEY=change-me-too-at-least-16-chars
# The image and tag. Pin a full version.
RASTERIZEDDB_IMAGE=milendenev/rasterizeddb:1.1.0-rustfs