kp-sync 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kp_sync/__init__.py +5 -0
- kp_sync/__main__.py +8 -0
- kp_sync/access_op.py +146 -0
- kp_sync/access_ops.py +480 -0
- kp_sync/backups.py +86 -0
- kp_sync/baseline.py +804 -0
- kp_sync/classify.py +103 -0
- kp_sync/cleanup.py +177 -0
- kp_sync/cli.py +1123 -0
- kp_sync/cloud_contact.py +175 -0
- kp_sync/completion.py +119 -0
- kp_sync/config.py +1105 -0
- kp_sync/content.py +62 -0
- kp_sync/credentials.py +349 -0
- kp_sync/daemon/__init__.py +3 -0
- kp_sync/daemon/apps.py +658 -0
- kp_sync/daemon/client.py +388 -0
- kp_sync/daemon/dbus.py +332 -0
- kp_sync/daemon/inhibit.py +137 -0
- kp_sync/daemon/leases.py +203 -0
- kp_sync/daemon/protocol.py +305 -0
- kp_sync/daemon/rescue.py +755 -0
- kp_sync/daemon/server.py +2116 -0
- kp_sync/daemon/systemd.py +251 -0
- kp_sync/daemon/triggers.py +204 -0
- kp_sync/drive_retire.py +288 -0
- kp_sync/drive_setup.py +344 -0
- kp_sync/drive_sync.py +107 -0
- kp_sync/drives.py +349 -0
- kp_sync/endpoints/__init__.py +27 -0
- kp_sync/endpoints/access.py +26 -0
- kp_sync/endpoints/base.py +307 -0
- kp_sync/endpoints/command.py +172 -0
- kp_sync/endpoints/file.py +524 -0
- kp_sync/endpoints/rclone.py +1060 -0
- kp_sync/endpoints/session.py +37 -0
- kp_sync/engine.py +4887 -0
- kp_sync/history.py +375 -0
- kp_sync/history_command.py +154 -0
- kp_sync/idle.py +100 -0
- kp_sync/integration.py +1646 -0
- kp_sync/kdbx.py +127 -0
- kp_sync/keepassxc.py +280 -0
- kp_sync/lock.py +76 -0
- kp_sync/log.py +189 -0
- kp_sync/merge.py +2042 -0
- kp_sync/paths.py +153 -0
- kp_sync/pending.py +158 -0
- kp_sync/rclone_credentials.py +263 -0
- kp_sync/rclone_rcd.py +553 -0
- kp_sync/reach.py +448 -0
- kp_sync/repair.py +185 -0
- kp_sync/services.py +645 -0
- kp_sync/sessions/__init__.py +3 -0
- kp_sync/sessions/authkeys.py +425 -0
- kp_sync/sessions/diagnostic.py +191 -0
- kp_sync/sessions/records.py +457 -0
- kp_sync/sessions/session.py +792 -0
- kp_sync/sessions/sftp_serve.py +270 -0
- kp_sync/state.py +685 -0
- kp_sync/udevmon.py +94 -0
- kp_sync/ui/__init__.py +10 -0
- kp_sync/ui/base.py +106 -0
- kp_sync/ui/factory.py +51 -0
- kp_sync/ui/fake.py +66 -0
- kp_sync/ui/gui.py +417 -0
- kp_sync/ui/none.py +32 -0
- kp_sync/ui/progress.py +111 -0
- kp_sync/ui/tty.py +139 -0
- kp_sync/verify.py +196 -0
- kp_sync-0.6.0.data/data/share/man/man1/kp-sync.1 +975 -0
- kp_sync-0.6.0.data/data/share/man/man5/kp-sync-config.5 +899 -0
- kp_sync-0.6.0.dist-info/METADATA +333 -0
- kp_sync-0.6.0.dist-info/RECORD +78 -0
- kp_sync-0.6.0.dist-info/WHEEL +5 -0
- kp_sync-0.6.0.dist-info/entry_points.txt +2 -0
- kp_sync-0.6.0.dist-info/licenses/LICENSE +674 -0
- kp_sync-0.6.0.dist-info/top_level.txt +1 -0
kp_sync/backups.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
# Copyright (C) 2026 Juan Domingo Martín
|
|
3
|
+
"""Create and prune timestamped backups in private runtime storage."""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import shutil
|
|
8
|
+
import hashlib
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from kp_sync.paths import ensure_private_directory
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def backup_file(
|
|
16
|
+
source: str | os.PathLike[str],
|
|
17
|
+
backup_dir: str | os.PathLike[str],
|
|
18
|
+
*,
|
|
19
|
+
identity: str,
|
|
20
|
+
keep: int = 20,
|
|
21
|
+
now: datetime | None = None,
|
|
22
|
+
) -> Path:
|
|
23
|
+
"""Create and retain a private backup for one physical copy.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
source: Existing database file to preserve.
|
|
27
|
+
backup_dir: Private runtime directory for backup files.
|
|
28
|
+
identity: Copy identity used to group and name backups.
|
|
29
|
+
keep: Maximum number of backups retained for this identity.
|
|
30
|
+
now: Optional timestamp override for deterministic callers.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
The path of the newly fsynced backup.
|
|
34
|
+
"""
|
|
35
|
+
if keep < 1:
|
|
36
|
+
raise ValueError("backup retention must be at least one")
|
|
37
|
+
source_path = Path(source)
|
|
38
|
+
directory = ensure_private_directory(backup_dir)
|
|
39
|
+
timestamp = (now or datetime.now(timezone.utc)).strftime(
|
|
40
|
+
"%Y%m%dT%H%M%S.%fZ"
|
|
41
|
+
)
|
|
42
|
+
safe_identity = re.sub(r"[^A-Za-z0-9_.-]", "_", identity)
|
|
43
|
+
safe_identity = (
|
|
44
|
+
f"{safe_identity[:48]}-"
|
|
45
|
+
f"{hashlib.sha256(identity.encode()).hexdigest()[:12]}"
|
|
46
|
+
)
|
|
47
|
+
destination = directory / f"{timestamp}-{safe_identity}.kdbx"
|
|
48
|
+
suffix = 1
|
|
49
|
+
while destination.exists():
|
|
50
|
+
destination = directory / f"{timestamp}-{safe_identity}-{suffix}.kdbx"
|
|
51
|
+
suffix += 1
|
|
52
|
+
|
|
53
|
+
with (
|
|
54
|
+
source_path.open("rb") as source_file,
|
|
55
|
+
destination.open("xb") as backup,
|
|
56
|
+
):
|
|
57
|
+
os.fchmod(backup.fileno(), 0o600)
|
|
58
|
+
shutil.copyfileobj(source_file, backup)
|
|
59
|
+
backup.flush()
|
|
60
|
+
os.fsync(backup.fileno())
|
|
61
|
+
_fsync_directory(directory)
|
|
62
|
+
|
|
63
|
+
backups = sorted(
|
|
64
|
+
(
|
|
65
|
+
path
|
|
66
|
+
for path in directory.glob("*.kdbx")
|
|
67
|
+
if re.search(
|
|
68
|
+
rf"-{re.escape(safe_identity)}(?:-\d+)?\.kdbx\Z", path.name
|
|
69
|
+
)
|
|
70
|
+
),
|
|
71
|
+
key=lambda path: path.name,
|
|
72
|
+
reverse=True,
|
|
73
|
+
)
|
|
74
|
+
for old in backups[keep:]:
|
|
75
|
+
old.unlink()
|
|
76
|
+
if len(backups) > keep:
|
|
77
|
+
_fsync_directory(directory)
|
|
78
|
+
return destination
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _fsync_directory(path: Path) -> None:
|
|
82
|
+
fd = os.open(path, os.O_RDONLY | getattr(os, "O_DIRECTORY", 0))
|
|
83
|
+
try:
|
|
84
|
+
os.fsync(fd)
|
|
85
|
+
finally:
|
|
86
|
+
os.close(fd)
|