mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-07-17 06:05:13 +00:00
refactor(restore)!: rsync volumes directly on the host, drop alpine-rsync
Restore now resolves the target volume's mountpoint via docker volume inspect and rsyncs into it directly, mirroring how the backup path already reads the mountpoint; the alpine-rsync container and the --rsync-image flag are gone. The e2e harness mounts /var/lib/docker read-write in the test container so the direct restore can write, the same way baudolo runs as root on a real host. BREAKING CHANGE: the restore 'files' subcommand no longer accepts --rsync-image; the caller must have write access to the docker volume root (root on the host), which is baudolo's normal privilege. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,10 +38,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
# ------------------------------------------------------------------
|
||||
p_files = sub.add_parser("files", help="Restore files into a docker volume")
|
||||
_add_common_backup_args(p_files)
|
||||
p_files.add_argument(
|
||||
"--rsync-image",
|
||||
default="ghcr.io/kevinveenbirkenbach/alpine-rsync",
|
||||
)
|
||||
p_files.add_argument(
|
||||
"--source-volume",
|
||||
default=None,
|
||||
@@ -95,7 +91,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
return restore_volume_files(
|
||||
args.volume_name,
|
||||
bp_files.files_dir(),
|
||||
rsync_image=args.rsync_image,
|
||||
)
|
||||
|
||||
if args.cmd == "postgres":
|
||||
|
||||
@@ -3,12 +3,10 @@ from __future__ import annotations
|
||||
import os
|
||||
import sys
|
||||
|
||||
from .run import run, docker_volume_exists
|
||||
from .run import docker_volume_exists, run
|
||||
|
||||
|
||||
def restore_volume_files(
|
||||
volume_name: str, backup_files_dir: str, *, rsync_image: str
|
||||
) -> int:
|
||||
def restore_volume_files(volume_name: str, backup_files_dir: str) -> int:
|
||||
if not os.path.isdir(backup_files_dir):
|
||||
print(f"ERROR: backup files dir not found: {backup_files_dir}", file=sys.stderr)
|
||||
return 2
|
||||
@@ -19,21 +17,21 @@ def restore_volume_files(
|
||||
else:
|
||||
print(f"Volume {volume_name} already exists.")
|
||||
|
||||
# Keep behavior close to the old script: rsync -avv --delete
|
||||
run(
|
||||
[
|
||||
"docker",
|
||||
"run",
|
||||
"--rm",
|
||||
"-v",
|
||||
f"{volume_name}:/recover/",
|
||||
"-v",
|
||||
f"{backup_files_dir}:/backup/",
|
||||
rsync_image,
|
||||
"sh",
|
||||
"-lc",
|
||||
"rsync -avv --delete /backup/ /recover/",
|
||||
]
|
||||
cp = run(
|
||||
["docker", "volume", "inspect", "--format", "{{ .Mountpoint }}", volume_name],
|
||||
capture=True,
|
||||
)
|
||||
raw = cp.stdout or b""
|
||||
mountpoint = (raw.decode() if isinstance(raw, bytes) else raw).strip()
|
||||
if not mountpoint:
|
||||
print(
|
||||
f"ERROR: could not resolve mountpoint for volume {volume_name}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
|
||||
src = os.path.join(backup_files_dir, "")
|
||||
dest = os.path.join(mountpoint, "")
|
||||
run(["rsync", "-avv", "--delete", src, dest])
|
||||
print("File restore complete.")
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user