aboutsummaryrefslogtreecommitdiff
path: root/tools/cru-py/crupest/backup.py
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-11-11 01:12:29 +0800
committerYuqian Yang <crupest@crupest.life>2025-01-20 22:34:18 +0800
commit5c76a1257b4a058bf919af3e31cc9461a39c2f33 (patch)
treecb32f0c22e5438a0ed9de4b29f58d0b7f142a58d /tools/cru-py/crupest/backup.py
parent12e1272508ba0b5909069319007d677c1c76e355 (diff)
downloadcrupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.tar.gz
crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.tar.bz2
crupest-5c76a1257b4a058bf919af3e31cc9461a39c2f33.zip
HALF WORK: 2024.1.20 - 2
Diffstat (limited to 'tools/cru-py/crupest/backup.py')
-rw-r--r--tools/cru-py/crupest/backup.py41
1 files changed, 0 insertions, 41 deletions
diff --git a/tools/cru-py/crupest/backup.py b/tools/cru-py/crupest/backup.py
deleted file mode 100644
index 7921d0d..0000000
--- a/tools/cru-py/crupest/backup.py
+++ /dev/null
@@ -1,41 +0,0 @@
-from .path import *
-from rich.prompt import Prompt, Confirm
-from urllib.request import urlretrieve
-import subprocess
-from datetime import datetime
-
-
-def backup_restore(http_url_or_path, /, console):
- url = http_url_or_path
- if len(url) == 0:
- raise Exception("You specify an empty url. Abort.")
- if url.startswith("http://") or url.startswith("https://"):
- download_path = os.path.join(tmp_dir, "data.tar.xz")
- if os.path.exists(download_path):
- to_remove = Confirm.ask(
- f"I want to download to [cyan]{download_path}[/]. However, there is a file already there. Do you want to remove it first", default=False, console=console)
- if to_remove:
- os.remove(download_path)
- else:
- raise Exception(
- "Aborted! Please check the file and try again.")
- urlretrieve(url, download_path)
- url = download_path
- subprocess.run(["sudo", "tar", "-xJf", url, "-C", project_dir], check=True)
-
-
-def backup_backup(path, /, console):
- ensure_backup_dir()
- now = datetime.utcnow().isoformat(timespec="seconds") + "Z"
- if path is None:
- path = Prompt.ask(
- "You don't specify the path to backup to. Please specify one. http and https are NOT supported", console=console, default=os.path.join(backup_dir, now + ".tar.xz"))
- if len(path) == 0:
- raise Exception("You specify an empty path. Abort!")
- if os.path.exists(path):
- raise Exception(
- "A file is already there. Please remove it first. Abort!")
- subprocess.run(
- ["sudo", "tar", "-cJf", path, "data", "-C", project_dir],
- check=True
- )