mirror of
https://codeberg.org/Mo8it/dotfiles.git
synced 2024-12-04 23:40:32 +00:00
Use last snapshot
This commit is contained in:
parent
278af2f184
commit
d5d5c2e8d7
1 changed files with 33 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from getpass import getpass
|
||||
from os import environ
|
||||
|
@ -18,9 +19,9 @@ def decorated_print(str: str):
|
|||
|
||||
def write_home_visible_includes():
|
||||
home_visible_content = set(
|
||||
run(
|
||||
"fd -d 1 '.*' ~", check=True, stdout=subprocess.PIPE, text=True
|
||||
).stdout.split()
|
||||
run("fd -d 1 '.*' ~", check=True, stdout=subprocess.PIPE, text=True)
|
||||
.stdout.strip()
|
||||
.split()
|
||||
)
|
||||
|
||||
home_visible_excludes = []
|
||||
|
@ -67,6 +68,18 @@ def mounted_backup_drive():
|
|||
return mounted_drives_path / mounted_backup_drives[ind]
|
||||
|
||||
|
||||
def get_parent_snapshot(env):
|
||||
snapshots_json = run(
|
||||
"restic snapshots -q --latest 1 --json",
|
||||
env=env,
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
).stdout.strip()
|
||||
|
||||
return json.loads(snapshots_json)[-1]["id"]
|
||||
|
||||
|
||||
def pre_backup():
|
||||
password = getpass("Restic repo password: ")
|
||||
|
||||
|
@ -94,20 +107,31 @@ def pre_backup():
|
|||
env = environ.copy()
|
||||
env["RESTIC_REPOSITORY"] = repo
|
||||
env["RESTIC_PASSWORD"] = password
|
||||
env["RESTIC_COMPRESSION"] = "auto"
|
||||
|
||||
if init_repo:
|
||||
run("restic init", env=env, check=True)
|
||||
parent_snapshot = None
|
||||
else:
|
||||
parent_snapshot = get_parent_snapshot(env)
|
||||
|
||||
return env
|
||||
decorated_print(f"Parent snapshot: {parent_snapshot}")
|
||||
|
||||
return env, parent_snapshot
|
||||
|
||||
|
||||
def backup(env):
|
||||
def backup(env, parent_snapshot):
|
||||
home_visible_includes = CONFIG_PATH / "home_visible_includes.txt"
|
||||
includes = CONFIG_PATH / "includes.txt"
|
||||
excludes = CONFIG_PATH / "excludes.txt"
|
||||
|
||||
if parent_snapshot is not None:
|
||||
parent_arg = "--parent " + parent_snapshot
|
||||
else:
|
||||
parent_arg = ""
|
||||
|
||||
run(
|
||||
f"restic backup -v --files-from {home_visible_includes} --files-from {includes} --exclude-file {excludes}",
|
||||
f"restic backup -v {parent_arg} --files-from {home_visible_includes} --files-from {includes} --exclude-file {excludes}",
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
|
@ -120,9 +144,9 @@ def post_backup(env):
|
|||
|
||||
|
||||
def main():
|
||||
env = pre_backup()
|
||||
env, parent_snapshot = pre_backup()
|
||||
|
||||
backup(env)
|
||||
backup(env, parent_snapshot)
|
||||
|
||||
post_backup(env)
|
||||
|
||||
|
|
Loading…
Reference in a new issue