mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2025-12-29 03:42:08 +00:00
- Use module logger in backup/db.py - Skip db dump when no databases.csv entry is present - Apply black/formatting cleanup across backup/restore/tests https://chatgpt.com/share/69519d45-b0dc-800f-acb6-6fb8504e9b46
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
from .run import run, docker_volume_exists
|
|
|
|
|
|
def restore_volume_files(
|
|
volume_name: str, backup_files_dir: str, *, rsync_image: 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
|
|
|
|
if not docker_volume_exists(volume_name):
|
|
print(f"Volume {volume_name} does not exist. Creating...")
|
|
run(["docker", "volume", "create", volume_name])
|
|
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/",
|
|
]
|
|
)
|
|
print("File restore complete.")
|
|
return 0
|