mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-11-05 02:37:49 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d672388f63 | ||
|
|
5817078643 | ||
|
|
4214d3709a | ||
|
|
4c51da009c |
No files matched your search
@@ -1,5 +1,20 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [7.2.0] - 2026-11-03
|
||||||
|
|
||||||
|
Added:
|
||||||
|
|
||||||
|
- Seed: *--password-stdin* reads the database password from stdin
|
||||||
|
- Seed: a password given both ways or not at all is rejected
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
|
||||||
|
- Seed: the password argument still works but warns it is visible in *ps*
|
||||||
|
|
||||||
|
Upgrade notes:
|
||||||
|
|
||||||
|
- Seed: pass the password via *--password-stdin*; the argument is deprecated
|
||||||
|
|
||||||
## [7.1.2] - 2026-10-18
|
## [7.1.2] - 2026-10-18
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "backup-docker-to-local"
|
name = "backup-docker-to-local"
|
||||||
version = "7.1.2"
|
version = "7.2.0"
|
||||||
description = "Backup Docker volumes to local with rsync and optional DB dumps."
|
description = "Backup Docker volumes to local with rsync and optional DB dumps."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
@@ -19,7 +19,7 @@ dependencies = [
|
|||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
# Pinned: a ruff minor bump changes which rules fire, and `make test` gates on
|
# Pinned: a ruff minor bump changes which rules fire, and `make test` gates on
|
||||||
# a clean run, so an unpinned lint would fail the suite on an unrelated day.
|
# a clean run, so an unpinned lint would fail the suite on an unrelated day.
|
||||||
lint = ["ruff==0.16.7"]
|
lint = ["ruff==0.17.3"]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
baudolo = "baudolo.backup.__main__:main"
|
baudolo = "baudolo.backup.__main__:main"
|
||||||
|
|||||||
@@ -73,9 +73,30 @@ def main() -> None:
|
|||||||
help="Database name or '*' to dump all databases",
|
help="Database name or '*' to dump all databases",
|
||||||
)
|
)
|
||||||
parser.add_argument("username", help="Database username")
|
parser.add_argument("username", help="Database username")
|
||||||
parser.add_argument("password", help="Database password")
|
parser.add_argument(
|
||||||
|
"password",
|
||||||
|
nargs="?",
|
||||||
|
help="Deprecated: database password as an argument, visible in the "
|
||||||
|
"process list; use --password-stdin",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--password-stdin",
|
||||||
|
action="store_true",
|
||||||
|
help="Read the database password from stdin",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if args.password_stdin == (args.password is not None):
|
||||||
|
parser.error("give the password either via --password-stdin or as an argument")
|
||||||
|
if args.password_stdin:
|
||||||
|
password = sys.stdin.read().removesuffix("\n")
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
"WARNING: a password argument is visible in the process list; "
|
||||||
|
"use --password-stdin",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
password = args.password
|
||||||
|
|
||||||
try:
|
try:
|
||||||
check_and_add_entry(
|
check_and_add_entry(
|
||||||
@@ -83,7 +104,7 @@ def main() -> None:
|
|||||||
instance=args.instance,
|
instance=args.instance,
|
||||||
database=args.database,
|
database=args.database,
|
||||||
username=args.username,
|
username=args.username,
|
||||||
password=args.password,
|
password=password,
|
||||||
)
|
)
|
||||||
except Exception as exc: # noqa: BLE001 - CLI boundary: any failure becomes exit 1
|
except Exception as exc: # noqa: BLE001 - CLI boundary: any failure becomes exit 1
|
||||||
print(f"ERROR: {exc}", file=sys.stderr)
|
print(f"ERROR: {exc}", file=sys.stderr)
|
||||||
|
|||||||
@@ -65,6 +65,32 @@ def run_seed_expect_fail(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_seed_stdin(
|
||||||
|
csv_path: Path, instance: str, database: str, username: str, stdin: str, *extra: str
|
||||||
|
) -> subprocess.CompletedProcess:
|
||||||
|
"""
|
||||||
|
Run the real CLI with --password-stdin, feeding the password on stdin.
|
||||||
|
Any extra arguments are appended after the username.
|
||||||
|
"""
|
||||||
|
return subprocess.run(
|
||||||
|
[
|
||||||
|
sys.executable,
|
||||||
|
"-m",
|
||||||
|
"baudolo.seed",
|
||||||
|
"--password-stdin",
|
||||||
|
str(csv_path),
|
||||||
|
instance,
|
||||||
|
database,
|
||||||
|
username,
|
||||||
|
*extra,
|
||||||
|
],
|
||||||
|
input=stdin,
|
||||||
|
text=True,
|
||||||
|
capture_output=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def read_csv_semicolon(path: Path) -> list[dict]:
|
def read_csv_semicolon(path: Path) -> list[dict]:
|
||||||
with path.open("r", encoding="utf-8", newline="") as f:
|
with path.open("r", encoding="utf-8", newline="") as f:
|
||||||
reader = csv.DictReader(f, delimiter=";")
|
reader = csv.DictReader(f, delimiter=";")
|
||||||
@@ -195,6 +221,61 @@ class TestSeedIntegration(unittest.TestCase):
|
|||||||
self.assertEqual(len(rows), 1)
|
self.assertEqual(len(rows), 1)
|
||||||
self.assertEqual(rows[0]["database"], "my_db-1")
|
self.assertEqual(rows[0]["database"], "my_db-1")
|
||||||
|
|
||||||
|
def test_password_stdin_stores_the_password_without_its_trailing_newline(
|
||||||
|
self,
|
||||||
|
) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as td:
|
||||||
|
p = Path(td) / "databases.csv"
|
||||||
|
|
||||||
|
cp = run_seed_stdin(p, "docker.test", "appdb", "alice", "s3cr;et\n")
|
||||||
|
|
||||||
|
self.assertEqual(cp.returncode, 0, cp.stderr)
|
||||||
|
self.assertNotIn("WARNING", cp.stderr)
|
||||||
|
rows = read_csv_semicolon(p)
|
||||||
|
self.assertEqual(len(rows), 1)
|
||||||
|
self.assertEqual(rows[0]["username"], "alice")
|
||||||
|
self.assertEqual(rows[0]["password"], "s3cr;et")
|
||||||
|
|
||||||
|
def test_password_argument_still_works_with_a_deprecation_warning(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as td:
|
||||||
|
p = Path(td) / "databases.csv"
|
||||||
|
|
||||||
|
cp = run_seed(p, "docker.test", "appdb", "alice", "secret")
|
||||||
|
|
||||||
|
self.assertIn("--password-stdin", cp.stderr)
|
||||||
|
self.assertEqual(read_csv_semicolon(p)[0]["password"], "secret")
|
||||||
|
|
||||||
|
def test_password_given_both_ways_is_rejected(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as td:
|
||||||
|
p = Path(td) / "databases.csv"
|
||||||
|
|
||||||
|
cp = run_seed_stdin(p, "docker.test", "appdb", "alice", "pw\n", "pw")
|
||||||
|
|
||||||
|
self.assertNotEqual(cp.returncode, 0)
|
||||||
|
self.assertFalse(p.exists(), "Should not create file on invalid input")
|
||||||
|
|
||||||
|
def test_password_given_no_way_is_rejected(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as td:
|
||||||
|
p = Path(td) / "databases.csv"
|
||||||
|
|
||||||
|
cp = subprocess.run(
|
||||||
|
[
|
||||||
|
sys.executable,
|
||||||
|
"-m",
|
||||||
|
"baudolo.seed",
|
||||||
|
str(p),
|
||||||
|
"docker.test",
|
||||||
|
"appdb",
|
||||||
|
"alice",
|
||||||
|
],
|
||||||
|
text=True,
|
||||||
|
capture_output=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertNotEqual(cp.returncode, 0)
|
||||||
|
self.assertFalse(p.exists(), "Should not create file on invalid input")
|
||||||
|
|
||||||
def test_file_is_semicolon_delimited_and_has_header(self) -> None:
|
def test_file_is_semicolon_delimited_and_has_header(self) -> None:
|
||||||
with tempfile.TemporaryDirectory() as td:
|
with tempfile.TemporaryDirectory() as td:
|
||||||
p = Path(td) / "databases.csv"
|
p = Path(td) / "databases.csv"
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ class TestSeedMain(unittest.TestCase):
|
|||||||
ns.database = "db"
|
ns.database = "db"
|
||||||
ns.username = "user"
|
ns.username = "user"
|
||||||
ns.password = "pass"
|
ns.password = "pass"
|
||||||
|
ns.password_stdin = False
|
||||||
parse_args.return_value = ns
|
parse_args.return_value = ns
|
||||||
|
|
||||||
seed_main.main()
|
seed_main.main()
|
||||||
@@ -195,6 +196,7 @@ class TestSeedMain(unittest.TestCase):
|
|||||||
ns.database = "db"
|
ns.database = "db"
|
||||||
ns.username = "user"
|
ns.username = "user"
|
||||||
ns.password = "pass"
|
ns.password = "pass"
|
||||||
|
ns.password_stdin = False
|
||||||
parse_args.return_value = ns
|
parse_args.return_value = ns
|
||||||
|
|
||||||
seed_main.main()
|
seed_main.main()
|
||||||
|
|||||||
Reference in new issue
Block a user