Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ The run ends with a summary table, including how long each restore took, which i
| Option | Effect |
|---|---|
| `-s`, `--set SET` | Test this set instead of the latest. |
| `-i`, `--image IMAGE` | The db-backup image to use (default `$DBBACKUP_IMAGE`, else `ghcr.io/arkane-systems/db-backup:latest`). |
| `-i`, `--image IMAGE` | The db-backup image to use (default `$DBBACKUP_IMAGE`, else `ghcr.io/arkane-systems/db-backup:latest`). It's pulled first, so a tag like `latest` is current; an image that exists only locally is used as it is. |
| `-b`, `--build` | Build the image from the checkout instead. |
| `-t`, `--tmpfs` | Keep the scratch servers' data in RAM. Faster, but the restored data must fit in memory. |
| `-k`, `--keep` | Leave each scratch server running afterwards, to look around in. The script prints how to remove it. |
Expand Down
10 changes: 9 additions & 1 deletion scripts/restore-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# Options:
# -s, --set SET set to test: "latest" (default) or a timestamp like 20261009T021500Z
# -i, --image IMAGE db-backup image to test with (default: $DBBACKUP_IMAGE, else
# ghcr.io/arkane-systems/db-backup:latest)
# ghcr.io/arkane-systems/db-backup:latest); pulled first, so
# a moving tag is current
# -b, --build build the image from this checkout instead
# -t, --tmpfs keep the scratch servers' data in RAM: faster, but it must fit
# -k, --keep leave each scratch server running afterwards, for inspection
Expand Down Expand Up @@ -70,6 +71,13 @@ if $build; then
echo "$build_log" >&2
die "image build failed"
fi
else
# docker compose run uses any local copy as is, and a cached :latest can be
# releases behind the sets it's testing. A local-only image can't be pulled.
if ! docker pull --quiet "$image" >/dev/null 2>&1; then
docker image inspect "$image" >/dev/null 2>&1 || die "can't pull $image, and there's no local copy"
echo "restore-test: couldn't pull $image; using the local copy" >&2
fi
fi

if ((${#targets[@]} == 0)); then
Expand Down
10 changes: 10 additions & 0 deletions src/dbbackup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import __version__
from .config import ConfigError, load_config
from .engines import Connection, EngineError, engine_for
from .engines.base import version_tuple
from .notify import publish_statuses
from .proc import CommandError
from .restoretest import DEFAULT_TOLERANCE, run_restore_test, target_for_set
Expand Down Expand Up @@ -280,6 +281,15 @@ def cmd_restore_test(args) -> int:
target = target_for_set(bset)
if not (args.host or args.uri_env):
raise ConfigError("restore-test needs the scratch server: --host (with --username/--password-env), or --uri-env")
made_by = bset.manifest.get("tool_version", "")
if version_tuple(made_by) > version_tuple(__version__):
log.warning(
"%s/%s was made by dbbackup %s, newer than this one (%s): it may record things this version doesn't check",
bset.target,
bset.name,
made_by,
__version__,
)
report = run_restore_test(bset, connection_from_args(args, target), tolerance=args.tolerance)

name = f"{report.target}/{report.set}"
Expand Down
14 changes: 12 additions & 2 deletions tests/test_restoretest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from dbbackup.cli import main
from dbbackup.restoretest import compare_inventory, counts_match, target_for_set
from dbbackup.restoretest import CheckResult, RestoreTestReport, compare_inventory, counts_match, target_for_set
from dbbackup.storage import StorageError, Store, open_set

EXPECTED = {
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_users_not_listable_on_either_side():
assert result.errors == [] and result.warnings


def make_set(tmp_path, target="pg-main", ttype="postgres", *, extensions=True):
def make_set(tmp_path, target="pg-main", ttype="postgres", *, extensions=True, **extra):
store = Store(tmp_path)
when = datetime(2026, 10, 9, 2, 15, tzinfo=UTC)
partial = store.begin(target, when)
Expand All @@ -133,6 +133,7 @@ def make_set(tmp_path, target="pg-main", ttype="postgres", *, extensions=True):
}
if not extensions: # as made by 0.2.x and earlier
del manifest["inventory"]
manifest.update(extra)
return store.finalize(partial, manifest)


Expand Down Expand Up @@ -181,6 +182,15 @@ def test_extensions_not_compared_when_the_backup_recorded_none():
assert compare_inventory(expected, actual, {"app"}).errors == []


@pytest.mark.parametrize(("made_by", "warned"), [("99.0.0", True), ("0.1.0", False), (None, False)])
def test_restore_test_warns_about_sets_from_a_newer_version(tmp_path, monkeypatch, caplog, made_by, warned):
bset = make_set(tmp_path, **({"tool_version": made_by} if made_by else {}))
report = RestoreTestReport("pg-main", bset.name, 0.1, CheckResult(), [])
monkeypatch.setattr("dbbackup.cli.run_restore_test", lambda *a, **k: report)
assert main(["restore-test", str(tmp_path / "pg-main"), "--host", "scratch"]) == 0
assert ("newer than this one" in caplog.text) is warned


def test_restore_test_needs_a_scratch_server(tmp_path):
make_set(tmp_path)
assert main(["restore-test", str(tmp_path / "pg-main")]) == 2
Loading