termux-sync 1.2.8__tar.gz → 1.3.0__tar.gz
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.
- {termux_sync-1.2.8 → termux_sync-1.3.0}/CHANGELOG.md +21 -0
- {termux_sync-1.2.8 → termux_sync-1.3.0}/PKG-INFO +1 -1
- {termux_sync-1.2.8 → termux_sync-1.3.0}/pyproject.toml +1 -1
- {termux_sync-1.2.8 → termux_sync-1.3.0}/src/termux_sync/__init__.py +242 -175
- {termux_sync-1.2.8 → termux_sync-1.3.0}/LICENSE +0 -0
- {termux_sync-1.2.8 → termux_sync-1.3.0}/README.md +0 -0
|
@@ -11,6 +11,27 @@ Version numbers follow [Semantic Versioning](https://semver.org/).
|
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
+
## [1.3.0] - 2026-10-21
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- **Cleaner, phone-friendly output.** All progress bars now use a single non-wrapping line per task: the label is cut with "…" instead of pushing the bar and timer onto a second line.
|
|
18
|
+
- Backup picker (`restore`, `delete`) no longer overflows the screen. On narrow terminals each backup is shown as a compact two-line card (name, then date · packages · size · label); on wide terminals it stays a table, now with Size and Pkgs columns. The redundant "Storage" column was removed.
|
|
19
|
+
- `setup`: wrapped text keeps its indentation, the exclude-pattern list is shown as a short summary (full list only when you choose to edit it), and the compression hint is its own line.
|
|
20
|
+
- Summary panels (backup, restore, setup) are more compact and show short paths (`~/.config/...`).
|
|
21
|
+
- The `TERMUX` ASCII banner falls back to a one-line title on terminals too narrow to draw it.
|
|
22
|
+
- `restore` step 4 now shows which package is being installed (`12/496 git`) and reports how many could not be installed; failures are written to the log.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- **`restore` from GitHub flooded the screen.** Every downloaded part (25+) kept its own progress row, so the display grew taller than the screen and was drawn over itself. Downloads now use one overall progress bar (bytes, current part, elapsed time) that disappears when finished and is replaced by a single "Downloaded N files (size, time)" line.
|
|
26
|
+
- GitHub downloads are streamed to disk in blocks instead of being read fully into memory, and parts are joined without loading them into RAM. A full disk now stops immediately instead of retrying.
|
|
27
|
+
- `backup` to GitHub: finished upload rows no longer pile up in the progress display.
|
|
28
|
+
- Backups without a manifest no longer show their tag name as a duplicate "Label".
|
|
29
|
+
|
|
30
|
+
### Security
|
|
31
|
+
- `setup` no longer prints a saved GitHub token back to the screen when you re-run it (the default value is hidden).
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
14
35
|
## [1.2.8] - 2026-10-15
|
|
15
36
|
|
|
16
37
|
## Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: termux-sync
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Backup and restore your entire Termux environment across devices
|
|
5
5
|
Project-URL: Homepage, https://github.com/djunekz/termux-sync
|
|
6
6
|
Project-URL: Repository, https://github.com/djunekz/termux-sync
|
|
@@ -34,7 +34,7 @@ try:
|
|
|
34
34
|
TextColumn, TimeElapsedColumn, FileSizeColumn,
|
|
35
35
|
TransferSpeedColumn, TaskProgressColumn,
|
|
36
36
|
)
|
|
37
|
-
from rich.table import Table
|
|
37
|
+
from rich.table import Table, Column
|
|
38
38
|
from rich.prompt import Prompt, Confirm
|
|
39
39
|
from rich.text import Text
|
|
40
40
|
from rich import box
|
|
@@ -60,7 +60,7 @@ except ImportError:
|
|
|
60
60
|
)
|
|
61
61
|
sys.exit(1)
|
|
62
62
|
|
|
63
|
-
VERSION = "1.
|
|
63
|
+
VERSION = "1.3.0"
|
|
64
64
|
APP_NAME = "termux-sync"
|
|
65
65
|
CONFIG_DIR = Path.home() / ".config" / APP_NAME
|
|
66
66
|
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
@@ -261,9 +261,15 @@ def handle_crash(exc: Exception):
|
|
|
261
261
|
|
|
262
262
|
|
|
263
263
|
def print_banner():
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
art_width = max(len(line) for line in BANNER.splitlines())
|
|
265
|
+
if console.width >= art_width + 2:
|
|
266
|
+
console.print(
|
|
267
|
+
Align.center(
|
|
268
|
+
f"[bold green]{BANNER}[/bold green]"))
|
|
269
|
+
else:
|
|
270
|
+
console.print()
|
|
271
|
+
console.print(Align.center("[bold green]T E R M U X - S Y N C[/bold green]"))
|
|
272
|
+
console.print()
|
|
267
273
|
console.print(
|
|
268
274
|
Align.center(
|
|
269
275
|
f"[dim]Version: [/dim][bold white]v{VERSION}[/bold white]\n"
|
|
@@ -275,11 +281,17 @@ def print_banner():
|
|
|
275
281
|
console.print()
|
|
276
282
|
|
|
277
283
|
|
|
284
|
+
def note(text: str, style: str = ""):
|
|
285
|
+
"""Print wrapped text with a 2-space margin on both sides, so lines that
|
|
286
|
+
wrap on a narrow screen stay aligned instead of jumping back to column 0."""
|
|
287
|
+
console.print(Padding(text, (0, 1, 0, 2)), style=style)
|
|
288
|
+
|
|
289
|
+
|
|
278
290
|
def print_section(title: str, subtitle: str = ""):
|
|
279
291
|
console.print()
|
|
280
|
-
console.print(Rule(f"[bold yellow]
|
|
292
|
+
console.print(Rule(f"[bold yellow]{title}[/bold yellow]", style="yellow dim"))
|
|
281
293
|
if subtitle:
|
|
282
|
-
|
|
294
|
+
note(f"[dim]{subtitle}[/dim]")
|
|
283
295
|
console.print()
|
|
284
296
|
|
|
285
297
|
|
|
@@ -287,6 +299,91 @@ def status_icon(ok: bool) -> str:
|
|
|
287
299
|
return "[bold green]✓[/bold green]" if ok else "[bold red]✗[/bold red]"
|
|
288
300
|
|
|
289
301
|
|
|
302
|
+
def is_narrow() -> bool:
|
|
303
|
+
"""True on phone-sized terminals (Termux portrait is ~45 columns)."""
|
|
304
|
+
return console.width < 72
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def make_progress(transient: bool = False, percent: bool = False) -> Progress:
|
|
308
|
+
"""One-line-per-task progress display that never wraps.
|
|
309
|
+
|
|
310
|
+
The description column takes whatever width is left and is cut with "…"
|
|
311
|
+
instead of pushing the bar/time onto a second line on narrow screens."""
|
|
312
|
+
cols = [
|
|
313
|
+
SpinnerColumn(),
|
|
314
|
+
TextColumn(
|
|
315
|
+
"{task.description}",
|
|
316
|
+
table_column=Column(ratio=1, no_wrap=True, overflow="ellipsis"),
|
|
317
|
+
),
|
|
318
|
+
BarColumn(bar_width=10 if is_narrow() else 24),
|
|
319
|
+
]
|
|
320
|
+
if percent:
|
|
321
|
+
cols.append(TaskProgressColumn())
|
|
322
|
+
cols.append(TimeElapsedColumn())
|
|
323
|
+
return Progress(*cols, console=console, expand=True, transient=transient)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def fmt_elapsed(seconds: float) -> str:
|
|
327
|
+
seconds = int(seconds)
|
|
328
|
+
return f"{seconds // 3600}:{seconds % 3600 // 60:02d}:{seconds % 60:02d}"
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _backup_date(b: dict) -> str:
|
|
332
|
+
return str(b.get("date", "—"))[:16].replace("T", " ")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _backup_label(b: dict) -> str:
|
|
336
|
+
label = b.get("label", "") or ""
|
|
337
|
+
return "" if label == b.get("name") else label
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _backup_size(b: dict) -> int:
|
|
341
|
+
return sum(v.get("size", 0) for v in (b.get("files") or {}).values())
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def print_backup_list(backups: list, title: str = "Available Backups"):
|
|
345
|
+
"""Numbered backup list. Table on wide terminals, 2-line cards on phones."""
|
|
346
|
+
if is_narrow():
|
|
347
|
+
console.print(f" [bold yellow]{title}[/bold yellow]\n")
|
|
348
|
+
for i, b in enumerate(backups, 1):
|
|
349
|
+
console.print(f" [bold cyan]{i:>2}[/bold cyan] [bold white]{escape(str(b.get('name', '—')))}[/bold white]")
|
|
350
|
+
bits = [f"[green]{_backup_date(b)}[/green]"]
|
|
351
|
+
if b.get("packages"):
|
|
352
|
+
bits.append(f"[cyan]{len(b['packages'])} pkgs[/cyan]")
|
|
353
|
+
if _backup_size(b):
|
|
354
|
+
bits.append(f"[blue]{human_size(_backup_size(b))}[/blue]")
|
|
355
|
+
if _backup_label(b):
|
|
356
|
+
bits.append(f"[yellow]{escape(_backup_label(b))}[/yellow]")
|
|
357
|
+
console.print(" " + " [dim]·[/dim] ".join(bits))
|
|
358
|
+
console.print()
|
|
359
|
+
return
|
|
360
|
+
|
|
361
|
+
table = Table(
|
|
362
|
+
box=box.ROUNDED,
|
|
363
|
+
title=f"[bold yellow]{title}[/bold yellow]",
|
|
364
|
+
show_header=True,
|
|
365
|
+
header_style="bold cyan",
|
|
366
|
+
padding=(0, 1),
|
|
367
|
+
)
|
|
368
|
+
table.add_column("#", style="dim", width=3, justify="right")
|
|
369
|
+
table.add_column("Name", style="bold white", no_wrap=True)
|
|
370
|
+
table.add_column("Date", style="green", no_wrap=True)
|
|
371
|
+
table.add_column("Pkgs", style="cyan", justify="right")
|
|
372
|
+
table.add_column("Size", style="blue", justify="right")
|
|
373
|
+
table.add_column("Label", style="yellow")
|
|
374
|
+
for i, b in enumerate(backups, 1):
|
|
375
|
+
table.add_row(
|
|
376
|
+
str(i),
|
|
377
|
+
escape(str(b.get("name", "—"))),
|
|
378
|
+
_backup_date(b),
|
|
379
|
+
str(len(b.get("packages", []))) if b.get("packages") else "—",
|
|
380
|
+
human_size(_backup_size(b)) if _backup_size(b) else "—",
|
|
381
|
+
escape(_backup_label(b)) or "—",
|
|
382
|
+
)
|
|
383
|
+
console.print(table)
|
|
384
|
+
console.print()
|
|
385
|
+
|
|
386
|
+
|
|
290
387
|
def human_size(size_bytes: int) -> str:
|
|
291
388
|
size_bytes = int(size_bytes)
|
|
292
389
|
for unit in ("B", "KB", "MB", "GB"):
|
|
@@ -320,27 +417,30 @@ def get_installed_packages() -> list[str]:
|
|
|
320
417
|
return []
|
|
321
418
|
|
|
322
419
|
|
|
323
|
-
def install_packages(pkg_list: list[str], console: Console):
|
|
420
|
+
def install_packages(pkg_list: list[str], console: Console) -> list[str]:
|
|
421
|
+
"""Reinstall packages one by one. Returns the names that failed."""
|
|
324
422
|
if not pkg_list:
|
|
325
423
|
console.print(" [yellow]No packages to install.[/yellow]")
|
|
326
|
-
return
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
) as progress:
|
|
334
|
-
task = progress.add_task("[cyan]Installing packages…", total=len(pkg_list))
|
|
335
|
-
for pkg in pkg_list:
|
|
424
|
+
return []
|
|
425
|
+
failed: list[str] = []
|
|
426
|
+
total = len(pkg_list)
|
|
427
|
+
with make_progress(transient=True, percent=True) as progress:
|
|
428
|
+
task = progress.add_task("[cyan]Installing…", total=total)
|
|
429
|
+
for i, pkg in enumerate(pkg_list, 1):
|
|
430
|
+
progress.update(task, description=f"[cyan]{i}/{total} {escape(pkg)}")
|
|
336
431
|
try:
|
|
337
432
|
subprocess.run(
|
|
338
433
|
["pkg", "install", "-y", pkg],
|
|
339
434
|
capture_output=True, check=True
|
|
340
435
|
)
|
|
341
436
|
except Exception:
|
|
342
|
-
|
|
437
|
+
failed.append(pkg)
|
|
343
438
|
progress.advance(task)
|
|
439
|
+
console.print(f" {status_icon(True)} Installed [bold green]{total - len(failed)}[/bold green] of {total} packages")
|
|
440
|
+
if failed:
|
|
441
|
+
console.print(f" [yellow]⚠ {len(failed)} package(s) could not be installed (see log).[/yellow]")
|
|
442
|
+
log("WARNING", "Packages failed to install: " + ", ".join(failed))
|
|
443
|
+
return failed
|
|
344
444
|
|
|
345
445
|
|
|
346
446
|
def create_archive(
|
|
@@ -918,15 +1018,20 @@ class GitHubStorage:
|
|
|
918
1018
|
for chunk in chunks:
|
|
919
1019
|
if chunk.name in existing_assets:
|
|
920
1020
|
continue
|
|
1021
|
+
progress.update(task, total=None, completed=0,
|
|
1022
|
+
description=f"[cyan]Uploading {escape(chunk.name)}")
|
|
921
1023
|
asset_task = progress.add_task(
|
|
922
1024
|
f"[cyan]{chunk.name}...", total=chunk.stat().st_size
|
|
923
1025
|
)
|
|
924
|
-
|
|
925
|
-
|
|
1026
|
+
try:
|
|
1027
|
+
self._upload_one_asset(release_id, chunk, asset_task, progress)
|
|
1028
|
+
finally:
|
|
1029
|
+
progress.remove_task(asset_task)
|
|
926
1030
|
finally:
|
|
927
1031
|
shutil.rmtree(tmp_split, ignore_errors=True)
|
|
928
1032
|
|
|
929
|
-
progress.update(task,
|
|
1033
|
+
progress.update(task, total=1, completed=1,
|
|
1034
|
+
description="[green]Uploaded to GitHub Releases ✓")
|
|
930
1035
|
return release_url
|
|
931
1036
|
|
|
932
1037
|
def list_backups(self) -> list[dict]:
|
|
@@ -952,7 +1057,7 @@ class GitHubStorage:
|
|
|
952
1057
|
backups.append(manifest or {
|
|
953
1058
|
"name": tag,
|
|
954
1059
|
"date": rel.get("created_at", ""),
|
|
955
|
-
"label":
|
|
1060
|
+
"label": "",
|
|
956
1061
|
})
|
|
957
1062
|
return backups
|
|
958
1063
|
|
|
@@ -964,34 +1069,51 @@ class GitHubStorage:
|
|
|
964
1069
|
assets = sorted(release.get("assets", []), key=lambda a: a["name"])
|
|
965
1070
|
dest.mkdir(parents=True, exist_ok=True)
|
|
966
1071
|
|
|
967
|
-
|
|
1072
|
+
# One overall task (bytes) instead of one row per part: with ~25 parts the
|
|
1073
|
+
# old per-file rows were taller than the screen and the display fell apart.
|
|
1074
|
+
n_files = len(assets)
|
|
1075
|
+
total_bytes = sum(a.get("size", 0) for a in assets) or 1
|
|
1076
|
+
task = progress.add_task("[cyan]Downloading…", total=total_bytes)
|
|
1077
|
+
done_bytes = 0
|
|
968
1078
|
|
|
969
|
-
for asset in assets:
|
|
1079
|
+
for n, asset in enumerate(assets, 1):
|
|
970
1080
|
url = self._asset_url(asset["id"])
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1081
|
+
name = asset["name"]
|
|
1082
|
+
out = dest / name
|
|
1083
|
+
tag = f"{n}/{n_files}"
|
|
1084
|
+
shown = re.sub(r"\.tar\.(gz|bz2|xz)", "", name) if is_narrow() else name
|
|
974
1085
|
last_err = None
|
|
975
1086
|
for attempt in range(8):
|
|
1087
|
+
got = 0
|
|
976
1088
|
try:
|
|
977
1089
|
req = urllib.request.Request(url, headers=self._asset_headers())
|
|
978
|
-
with urllib.request.urlopen(req, timeout=120) as r:
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1090
|
+
with urllib.request.urlopen(req, timeout=120) as r, open(out, "wb") as fh:
|
|
1091
|
+
while True:
|
|
1092
|
+
block = r.read(1 << 18)
|
|
1093
|
+
if not block:
|
|
1094
|
+
break
|
|
1095
|
+
fh.write(block)
|
|
1096
|
+
got += len(block)
|
|
1097
|
+
progress.update(
|
|
1098
|
+
task, completed=min(done_bytes + got, total_bytes),
|
|
1099
|
+
description=f"[cyan]{tag} {escape(shown)}",
|
|
1100
|
+
)
|
|
1101
|
+
done_bytes += got
|
|
983
1102
|
last_err = None
|
|
984
1103
|
break
|
|
985
1104
|
except Exception as e:
|
|
1105
|
+
if getattr(e, "errno", None) == errno.ENOSPC:
|
|
1106
|
+
raise
|
|
986
1107
|
last_err = e
|
|
987
|
-
progress.update(
|
|
988
|
-
|
|
1108
|
+
progress.update(
|
|
1109
|
+
task, completed=min(done_bytes, total_bytes),
|
|
1110
|
+
description=f"[yellow]{tag} retry {attempt+1}/8",
|
|
1111
|
+
)
|
|
989
1112
|
_time.sleep(15 * (attempt + 1))
|
|
990
1113
|
if last_err:
|
|
991
1114
|
raise RuntimeError(
|
|
992
|
-
f"Failed to download {
|
|
1115
|
+
f"Failed to download {name} after 8 attempts: {last_err}"
|
|
993
1116
|
)
|
|
994
|
-
progress.advance(dl_task)
|
|
995
1117
|
|
|
996
1118
|
chunk_re = _re.compile(r"^(.+)\.part(\d{4})$")
|
|
997
1119
|
groups: dict = {}
|
|
@@ -1000,23 +1122,20 @@ class GitHubStorage:
|
|
|
1000
1122
|
if m:
|
|
1001
1123
|
groups.setdefault(m.group(1), []).append(f)
|
|
1002
1124
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
progress.update(assemble_task, description="[green]Chunks reassembled")
|
|
1018
|
-
|
|
1019
|
-
progress.update(dl_task, description="[green]Downloaded from GitHub")
|
|
1125
|
+
for original_name, parts in groups.items():
|
|
1126
|
+
parts.sort(key=lambda p: p.name)
|
|
1127
|
+
group_total = sum(p.stat().st_size for p in parts) or 1
|
|
1128
|
+
progress.update(task, completed=0, total=group_total,
|
|
1129
|
+
description=f"[cyan]Joining {escape(original_name)}")
|
|
1130
|
+
out_file = dest / original_name
|
|
1131
|
+
with open(out_file, "wb") as fout:
|
|
1132
|
+
for part in parts:
|
|
1133
|
+
with open(part, "rb") as fin:
|
|
1134
|
+
shutil.copyfileobj(fin, fout, 1 << 20)
|
|
1135
|
+
progress.advance(task, part.stat().st_size)
|
|
1136
|
+
part.unlink()
|
|
1137
|
+
|
|
1138
|
+
progress.update(task, description="[green]Downloaded ✓")
|
|
1020
1139
|
|
|
1021
1140
|
def delete_old(self, max_keep: int):
|
|
1022
1141
|
releases = [
|
|
@@ -1223,15 +1342,7 @@ def cmd_backup(cfg: dict, label: str = ""):
|
|
|
1223
1342
|
("Archiving & uploading directories…" if streaming else "Archiving directories…"))
|
|
1224
1343
|
console.print()
|
|
1225
1344
|
|
|
1226
|
-
with
|
|
1227
|
-
SpinnerColumn(),
|
|
1228
|
-
TextColumn(" {task.description}"),
|
|
1229
|
-
BarColumn(bar_width=30),
|
|
1230
|
-
TextColumn("[dim]{task.percentage:>3.0f}%"),
|
|
1231
|
-
TimeElapsedColumn(),
|
|
1232
|
-
console=console,
|
|
1233
|
-
expand=False,
|
|
1234
|
-
) as progress:
|
|
1345
|
+
with make_progress() as progress:
|
|
1235
1346
|
archive_items = [
|
|
1236
1347
|
("home", "Home directory (~)", TERMUX_FILES),
|
|
1237
1348
|
("usr_etc", "Termux config (/usr/etc)", TERMUX_HOME / "etc"),
|
|
@@ -1292,13 +1403,7 @@ def cmd_backup(cfg: dict, label: str = ""):
|
|
|
1292
1403
|
|
|
1293
1404
|
location = ""
|
|
1294
1405
|
upload_error = None
|
|
1295
|
-
with
|
|
1296
|
-
SpinnerColumn(),
|
|
1297
|
-
TextColumn(" {task.description}"),
|
|
1298
|
-
BarColumn(bar_width=30),
|
|
1299
|
-
TimeElapsedColumn(),
|
|
1300
|
-
console=console,
|
|
1301
|
-
) as progress:
|
|
1406
|
+
with make_progress() as progress:
|
|
1302
1407
|
try:
|
|
1303
1408
|
location = storage.upload(tmp_dir, backup_name, progress)
|
|
1304
1409
|
storage.delete_old(cfg.get("max_backups", 5))
|
|
@@ -1331,15 +1436,15 @@ def cmd_backup(cfg: dict, label: str = ""):
|
|
|
1331
1436
|
console.print()
|
|
1332
1437
|
console.print(Panel(
|
|
1333
1438
|
f"[bold green]✓ Backup completed successfully![/bold green]\n\n"
|
|
1334
|
-
f"
|
|
1335
|
-
f"
|
|
1336
|
-
f"
|
|
1337
|
-
f"
|
|
1338
|
-
f"
|
|
1339
|
-
f"
|
|
1340
|
-
title="[bold yellow]
|
|
1439
|
+
f"[dim]Name [/dim] [white]{escape(backup_name)}[/white]\n"
|
|
1440
|
+
f"[dim]Date [/dim] [white]{meta['date'][:19].replace('T', ' ')}[/white]\n"
|
|
1441
|
+
f"[dim]Packages[/dim] [white]{len(pkgs)}[/white]\n"
|
|
1442
|
+
f"[dim]Size [/dim] [white]{human_size(total_size)}[/white]\n"
|
|
1443
|
+
f"[dim]Storage [/dim] [white]{cfg['storage'].upper()}[/white]\n"
|
|
1444
|
+
f"[dim]Location[/dim] [white]{escape(short_path(location))}[/white]",
|
|
1445
|
+
title="[bold yellow]Backup Summary[/bold yellow]",
|
|
1341
1446
|
border_style="green",
|
|
1342
|
-
padding=(
|
|
1447
|
+
padding=(0, 2),
|
|
1343
1448
|
))
|
|
1344
1449
|
log("INFO", f"Backup completed: {backup_name} ({human_size(total_size)})")
|
|
1345
1450
|
|
|
@@ -1357,32 +1462,7 @@ def cmd_restore(cfg: dict, backup_name: str = ""):
|
|
|
1357
1462
|
return
|
|
1358
1463
|
|
|
1359
1464
|
if not backup_name:
|
|
1360
|
-
|
|
1361
|
-
box=box.ROUNDED,
|
|
1362
|
-
title="[bold yellow]Available Backups[/bold yellow]",
|
|
1363
|
-
show_header=True,
|
|
1364
|
-
header_style="bold cyan",
|
|
1365
|
-
padding=(0, 1),
|
|
1366
|
-
)
|
|
1367
|
-
table.add_column("#", style="dim", width=4)
|
|
1368
|
-
table.add_column("Name", style="bold white", min_width=30)
|
|
1369
|
-
table.add_column("Date", style="green")
|
|
1370
|
-
table.add_column("Label", style="yellow")
|
|
1371
|
-
table.add_column("Packages", style="cyan", justify="right")
|
|
1372
|
-
table.add_column("Storage", style="blue")
|
|
1373
|
-
|
|
1374
|
-
for i, b in enumerate(backups, 1):
|
|
1375
|
-
table.add_row(
|
|
1376
|
-
str(i),
|
|
1377
|
-
b.get("name", "—"),
|
|
1378
|
-
b.get("date", "—")[:19].replace("T", " "),
|
|
1379
|
-
b.get("label", "") or "—",
|
|
1380
|
-
str(len(b.get("packages", []))),
|
|
1381
|
-
b.get("storage", cfg["storage"]).upper(),
|
|
1382
|
-
)
|
|
1383
|
-
|
|
1384
|
-
console.print(table)
|
|
1385
|
-
console.print()
|
|
1465
|
+
print_backup_list(backups)
|
|
1386
1466
|
|
|
1387
1467
|
choice = Prompt.ask(" [bold]Enter backup number or name[/bold]", default="1")
|
|
1388
1468
|
try:
|
|
@@ -1405,20 +1485,22 @@ def cmd_restore(cfg: dict, backup_name: str = ""):
|
|
|
1405
1485
|
|
|
1406
1486
|
console.print()
|
|
1407
1487
|
console.print(" [bold]Step 1/4[/bold] Downloading backup…")
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
TextColumn(" {task.description}"),
|
|
1411
|
-
BarColumn(bar_width=30),
|
|
1412
|
-
TimeElapsedColumn(),
|
|
1413
|
-
console=console,
|
|
1414
|
-
) as progress:
|
|
1488
|
+
t0 = time.monotonic()
|
|
1489
|
+
with make_progress(transient=True, percent=True) as progress:
|
|
1415
1490
|
try:
|
|
1416
1491
|
storage.download(backup_name, tmp_dir, progress)
|
|
1417
1492
|
except Exception as e:
|
|
1493
|
+
progress.stop()
|
|
1418
1494
|
console.print(f" [red]✗ Download failed: {escape(str(e))}[/red]")
|
|
1419
1495
|
log("ERROR", f"Download failed: {e}")
|
|
1420
1496
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
|
1421
1497
|
return
|
|
1498
|
+
dl_files = [f for f in tmp_dir.iterdir() if f.is_file()]
|
|
1499
|
+
console.print(
|
|
1500
|
+
f" {status_icon(True)} Downloaded {len(dl_files)} files "
|
|
1501
|
+
f"[dim]({human_size(sum(f.stat().st_size for f in dl_files))}, "
|
|
1502
|
+
f"{fmt_elapsed(time.monotonic() - t0)})[/dim]"
|
|
1503
|
+
)
|
|
1422
1504
|
|
|
1423
1505
|
manifest = read_manifest(tmp_dir)
|
|
1424
1506
|
if not manifest:
|
|
@@ -1438,7 +1520,7 @@ def cmd_restore(cfg: dict, backup_name: str = ""):
|
|
|
1438
1520
|
cs = sha256(archive)
|
|
1439
1521
|
ok = cs == info.get("checksum", cs)
|
|
1440
1522
|
icon = status_icon(ok)
|
|
1441
|
-
console.print(f" {icon} {info['archive']} [dim]{cs[:
|
|
1523
|
+
console.print(f" {icon} {info['archive']} [dim]{cs[:12]}…[/dim]")
|
|
1442
1524
|
if not ok:
|
|
1443
1525
|
all_ok = False
|
|
1444
1526
|
|
|
@@ -1449,30 +1531,25 @@ def cmd_restore(cfg: dict, backup_name: str = ""):
|
|
|
1449
1531
|
|
|
1450
1532
|
console.print()
|
|
1451
1533
|
console.print(Panel(
|
|
1452
|
-
f" [
|
|
1453
|
-
f"
|
|
1454
|
-
f"
|
|
1455
|
-
f"
|
|
1456
|
-
f"
|
|
1457
|
-
title="[bold yellow]
|
|
1534
|
+
f"[dim]Backup [/dim] [white]{escape(backup_name)}[/white]\n"
|
|
1535
|
+
f"[dim]Date [/dim] [white]{manifest.get('date', '—')[:19].replace('T', ' ')}[/white]\n"
|
|
1536
|
+
f"[dim]Packages[/dim] [white]{len(manifest.get('packages', []))}[/white]\n"
|
|
1537
|
+
f"[dim]Archives[/dim] [white]{len(manifest.get('files', {}))}[/white] "
|
|
1538
|
+
f"[dim]({human_size(_backup_size(manifest))})[/dim]",
|
|
1539
|
+
title="[bold yellow]Restore Preview[/bold yellow]",
|
|
1458
1540
|
border_style="yellow",
|
|
1459
|
-
padding=(
|
|
1541
|
+
padding=(0, 2),
|
|
1460
1542
|
))
|
|
1543
|
+
console.print(" [yellow]⚠ This will overwrite existing files.[/yellow]")
|
|
1461
1544
|
|
|
1462
|
-
if not Confirm.ask("
|
|
1545
|
+
if not Confirm.ask(" [bold yellow]Proceed with restore?[/bold yellow]"):
|
|
1463
1546
|
console.print(" [dim]Restore cancelled.[/dim]")
|
|
1464
1547
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
|
1465
1548
|
return
|
|
1466
1549
|
|
|
1467
1550
|
console.print()
|
|
1468
1551
|
console.print(" [bold]Step 3/4[/bold] Extracting archives…")
|
|
1469
|
-
with
|
|
1470
|
-
SpinnerColumn(),
|
|
1471
|
-
TextColumn(" {task.description}"),
|
|
1472
|
-
BarColumn(bar_width=30),
|
|
1473
|
-
TimeElapsedColumn(),
|
|
1474
|
-
console=console,
|
|
1475
|
-
) as progress:
|
|
1552
|
+
with make_progress() as progress:
|
|
1476
1553
|
# Build the set of destinations this app is actually willing to restore into.
|
|
1477
1554
|
# Manifest-supplied "source" values are attacker-controlled backup content
|
|
1478
1555
|
# and must never be trusted as an extraction root — only used to double
|
|
@@ -1511,11 +1588,11 @@ def cmd_restore(cfg: dict, backup_name: str = ""):
|
|
|
1511
1588
|
|
|
1512
1589
|
console.print()
|
|
1513
1590
|
console.print(Panel(
|
|
1514
|
-
"[bold green]✓ Restore completed successfully![/bold green]\n
|
|
1515
|
-
"
|
|
1516
|
-
title="[bold yellow]
|
|
1591
|
+
"[bold green]✓ Restore completed successfully![/bold green]\n"
|
|
1592
|
+
"Please restart Termux for all changes to take effect.",
|
|
1593
|
+
title="[bold yellow]Restore Summary[/bold yellow]",
|
|
1517
1594
|
border_style="green",
|
|
1518
|
-
padding=(
|
|
1595
|
+
padding=(0, 2),
|
|
1519
1596
|
))
|
|
1520
1597
|
log("INFO", f"Restore completed from: {backup_name}")
|
|
1521
1598
|
|
|
@@ -1534,17 +1611,17 @@ def cmd_list(cfg: dict):
|
|
|
1534
1611
|
|
|
1535
1612
|
for i, b in enumerate(backups, 1):
|
|
1536
1613
|
tbl = Table(
|
|
1537
|
-
box=box.ROUNDED,
|
|
1614
|
+
box=None if is_narrow() else box.ROUNDED,
|
|
1538
1615
|
show_header=False,
|
|
1539
|
-
padding=(0,
|
|
1616
|
+
padding=(0, 1),
|
|
1540
1617
|
title=f"[bold white]Backup #{i}[/bold white]",
|
|
1541
1618
|
)
|
|
1542
|
-
tbl.add_column("Key", style="dim cyan", min_width=
|
|
1619
|
+
tbl.add_column("Key", style="dim cyan", min_width=12)
|
|
1543
1620
|
tbl.add_column("Value", style="bold white")
|
|
1544
1621
|
|
|
1545
|
-
tbl.add_row("Name", b.get("name", "—"))
|
|
1622
|
+
tbl.add_row("Name", escape(str(b.get("name", "—"))))
|
|
1546
1623
|
tbl.add_row("Date", b.get("date", "—")[:19].replace("T", " "))
|
|
1547
|
-
tbl.add_row("Label", b
|
|
1624
|
+
tbl.add_row("Label", escape(_backup_label(b)) or "—")
|
|
1548
1625
|
tbl.add_row("Packages", str(len(b.get("packages", []))))
|
|
1549
1626
|
tbl.add_row("Files", str(len(b.get("files", {}))))
|
|
1550
1627
|
tbl.add_row("Version", b.get("version", "—"))
|
|
@@ -1569,28 +1646,7 @@ def cmd_delete(cfg: dict, backup_name: str = ""):
|
|
|
1569
1646
|
console.print(" [yellow]No backups found.[/yellow]")
|
|
1570
1647
|
return
|
|
1571
1648
|
|
|
1572
|
-
|
|
1573
|
-
box=box.ROUNDED,
|
|
1574
|
-
title="[bold yellow]Available Backups[/bold yellow]",
|
|
1575
|
-
show_header=True,
|
|
1576
|
-
header_style="bold cyan",
|
|
1577
|
-
padding=(0, 1),
|
|
1578
|
-
)
|
|
1579
|
-
table.add_column("#", style="dim", width=4)
|
|
1580
|
-
table.add_column("Name", style="bold white", min_width=30)
|
|
1581
|
-
table.add_column("Date", style="green")
|
|
1582
|
-
table.add_column("Label", style="yellow")
|
|
1583
|
-
|
|
1584
|
-
for i, b in enumerate(backups, 1):
|
|
1585
|
-
table.add_row(
|
|
1586
|
-
str(i),
|
|
1587
|
-
b.get("name", "—"),
|
|
1588
|
-
b.get("date", "—")[:19].replace("T", " "),
|
|
1589
|
-
b.get("label", "") or "—",
|
|
1590
|
-
)
|
|
1591
|
-
|
|
1592
|
-
console.print(table)
|
|
1593
|
-
console.print()
|
|
1649
|
+
print_backup_list(backups)
|
|
1594
1650
|
|
|
1595
1651
|
if not backup_name:
|
|
1596
1652
|
choice = Prompt.ask(" [bold]Enter backup number or name to delete[/bold]")
|
|
@@ -1624,9 +1680,9 @@ def cmd_setup():
|
|
|
1624
1680
|
cfg = load_config()
|
|
1625
1681
|
|
|
1626
1682
|
console.print(" Choose your [bold]storage backend[/bold]:\n")
|
|
1627
|
-
console.print(" [bold cyan][1][/bold cyan] Local storage
|
|
1628
|
-
console.print(" [bold cyan][2][/bold cyan] Google Drive
|
|
1629
|
-
console.print(" [bold cyan][3][/bold cyan] GitHub
|
|
1683
|
+
console.print(" [bold cyan][1][/bold cyan] Local storage [dim]on device[/dim]")
|
|
1684
|
+
console.print(" [bold cyan][2][/bold cyan] Google Drive [dim]via rclone[/dim]")
|
|
1685
|
+
console.print(" [bold cyan][3][/bold cyan] GitHub [dim]private repo[/dim] [bold yellow]★ Recommended[/bold yellow]")
|
|
1630
1686
|
console.print()
|
|
1631
1687
|
|
|
1632
1688
|
choice = Prompt.ask(" Storage", choices=["1", "2", "3"], default="3")
|
|
@@ -1654,21 +1710,23 @@ def cmd_setup():
|
|
|
1654
1710
|
|
|
1655
1711
|
elif cfg["storage"] == "github":
|
|
1656
1712
|
console.print()
|
|
1657
|
-
|
|
1658
|
-
"
|
|
1713
|
+
note(
|
|
1714
|
+
"[dim]Create a [bold]private repository[/bold] on GitHub and generate a"
|
|
1659
1715
|
" Personal Access Token with [white]repo[/white] scope.[/dim]"
|
|
1660
1716
|
)
|
|
1661
|
-
console.print(" [dim]Token
|
|
1717
|
+
console.print(" [dim]Token page:[/dim]")
|
|
1718
|
+
console.print(" [white]https://github.com/settings/tokens[/white]", soft_wrap=True)
|
|
1662
1719
|
console.print()
|
|
1663
1720
|
|
|
1664
1721
|
existing_token = cfg.get("github_token", "")
|
|
1665
1722
|
if existing_token:
|
|
1666
|
-
|
|
1723
|
+
note("[dim]A token is already saved. Press Enter to keep it, or paste a new one.[/dim]")
|
|
1667
1724
|
while True:
|
|
1668
1725
|
val = Prompt.ask(
|
|
1669
|
-
" GitHub
|
|
1726
|
+
" GitHub token",
|
|
1670
1727
|
default=existing_token,
|
|
1671
1728
|
password=True,
|
|
1729
|
+
show_default=False, # never print a saved token back to the screen
|
|
1672
1730
|
).strip()
|
|
1673
1731
|
if val:
|
|
1674
1732
|
cfg["github_token"] = val
|
|
@@ -1677,7 +1735,9 @@ def cmd_setup():
|
|
|
1677
1735
|
|
|
1678
1736
|
while True:
|
|
1679
1737
|
val = Prompt.ask(
|
|
1680
|
-
" GitHub repo (owner/repo)",
|
|
1738
|
+
" GitHub repo [dim](owner/repo)[/dim]",
|
|
1739
|
+
default=cfg.get("github_repo", ""),
|
|
1740
|
+
show_default=bool(cfg.get("github_repo", "")),
|
|
1681
1741
|
).strip()
|
|
1682
1742
|
if not val:
|
|
1683
1743
|
console.print(" [red]✗ Repo cannot be empty. Enter in format: username/repo-name[/red]")
|
|
@@ -1693,8 +1753,9 @@ def cmd_setup():
|
|
|
1693
1753
|
)
|
|
1694
1754
|
|
|
1695
1755
|
console.print()
|
|
1756
|
+
console.print(" [dim]Compression: gz = fast · bz2 = balanced · xz = best[/dim]")
|
|
1696
1757
|
cfg["compression"] = Prompt.ask(
|
|
1697
|
-
" Compression
|
|
1758
|
+
" Compression",
|
|
1698
1759
|
choices=["gz", "bz2", "xz"], default=cfg.get("compression", "gz")
|
|
1699
1760
|
)
|
|
1700
1761
|
while True:
|
|
@@ -1706,11 +1767,16 @@ def cmd_setup():
|
|
|
1706
1767
|
|
|
1707
1768
|
console.print()
|
|
1708
1769
|
current_patterns = cfg.get("exclude_patterns", [])
|
|
1709
|
-
preview = ", ".join(current_patterns[:
|
|
1710
|
-
|
|
1770
|
+
preview = ", ".join(current_patterns[:4])
|
|
1771
|
+
if len(current_patterns) > 4:
|
|
1772
|
+
preview += f" … +{len(current_patterns) - 4} more"
|
|
1773
|
+
note(f"[dim]Exclude patterns ({len(current_patterns)}): {escape(preview)}[/dim]")
|
|
1711
1774
|
if Confirm.ask(" Customise exclude patterns?", default=False):
|
|
1712
|
-
console.print(
|
|
1713
|
-
|
|
1775
|
+
console.print()
|
|
1776
|
+
console.print(Padding(escape(", ".join(current_patterns)), (0, 0, 0, 4)), style="dim")
|
|
1777
|
+
console.print()
|
|
1778
|
+
note("[dim]Type the new list separated by commas. Press Enter to keep the list above.[/dim]")
|
|
1779
|
+
raw = Prompt.ask(" Patterns", default="", show_default=False)
|
|
1714
1780
|
if raw.strip():
|
|
1715
1781
|
cfg["exclude_patterns"] = [p.strip() for p in raw.split(",") if p.strip()]
|
|
1716
1782
|
|
|
@@ -1718,9 +1784,10 @@ def cmd_setup():
|
|
|
1718
1784
|
console.print()
|
|
1719
1785
|
console.print(Panel(
|
|
1720
1786
|
f"[bold green]✓ Configuration saved![/bold green]\n\n"
|
|
1721
|
-
f"
|
|
1722
|
-
f"
|
|
1723
|
-
|
|
1787
|
+
f"[dim]Storage[/dim] [white]{cfg['storage'].upper()}[/white]\n"
|
|
1788
|
+
f"[dim]Config [/dim] [white]{escape(short_path(CONFIG_FILE))}[/white]",
|
|
1789
|
+
title="[bold yellow]Setup Summary[/bold yellow]",
|
|
1790
|
+
border_style="green", padding=(0, 2)
|
|
1724
1791
|
))
|
|
1725
1792
|
log("INFO", f"Setup complete. Storage: {cfg['storage']}")
|
|
1726
1793
|
|
|
File without changes
|
|
File without changes
|