1
0
Fork 0
mirror of https://codeberg.org/Mo8it/dotfiles.git synced 2024-10-17 20:52:40 +00:00

Ask to init restic repo if not found

This commit is contained in:
Mo 2022-06-30 20:53:34 +02:00
parent 9f80615cb8
commit c6d687367d

View file

@ -71,8 +71,15 @@ def pre_backup():
write_home_visible_includes()
repo = mounted_backup_drive() / "restic"
init_repo = False
if not repo.is_dir():
raise Exception(f"No repo found at {repo} !!")
decorated_print(f"No repo found at {repo} !!")
ans = input("Initialize repo? [Y/n]: ")
if ans.strip().lower() not in ("", "y"):
raise Exception("No repo to work with!")
else:
init_repo = True
with open(CONFIG_PATH / "pre_backup_scripts.txt") as f:
for line in f:
@ -86,6 +93,9 @@ def pre_backup():
env["RESTIC_REPOSITORY"] = repo
env["RESTIC_PASSWORD"] = password
if init_repo:
run("restic init", env=env, check=True)
return env
@ -95,7 +105,7 @@ def backup(env):
excludes = CONFIG_PATH / "excludes.txt"
run(
f"restic backup -vv --files-from {home_visible_includes} --files-from {includes} --exclude-file {excludes}",
f"restic backup -v --files-from {home_visible_includes} --files-from {includes} --exclude-file {excludes}",
env=env,
check=True,
)