summaryrefslogtreecommitdiff
path: root/hosts/vidhar
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-02-17 12:34:06 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2022-02-17 12:34:06 +0100
commit81b87724da3216817057d6febdf8036bf7dfca65 (patch)
tree4a31bd2f1d867b21034c686ab78d3e0b3e4ff7db /hosts/vidhar
parent2f113f1d7d71007cb6b80ffce75bba5af55de767 (diff)
downloadnixos-81b87724da3216817057d6febdf8036bf7dfca65.tar
nixos-81b87724da3216817057d6febdf8036bf7dfca65.tar.gz
nixos-81b87724da3216817057d6febdf8036bf7dfca65.tar.bz2
nixos-81b87724da3216817057d6febdf8036bf7dfca65.tar.xz
nixos-81b87724da3216817057d6febdf8036bf7dfca65.zip
vidhar: ...
Diffstat (limited to 'hosts/vidhar')
-rwxr-xr-xhosts/vidhar/borg/copy.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/hosts/vidhar/borg/copy.py b/hosts/vidhar/borg/copy.py
index b99e301a..af876d99 100755
--- a/hosts/vidhar/borg/copy.py
+++ b/hosts/vidhar/borg/copy.py
@@ -31,8 +31,14 @@ parser.add_argument('source', metavar='REPO_OR_ARCHIVE')
31parser.add_argument('target', metavar='REPO_OR_ARCHIVE') 31parser.add_argument('target', metavar='REPO_OR_ARCHIVE')
32args = parser.parse_args() 32args = parser.parse_args()
33 33
34halo_args = {
35 stream: sys.stderr,
36 enabled: not sys.stderr.isatty(),
37 spinner: 'arc'
38}
39
34def read_repo(path): 40def read_repo(path):
35 with Halo(text=f'Listing {path}', spinner='arc') as sp: 41 with Halo(text=f'Listing {path}', **halo_args) as sp:
36 res = None 42 res = None
37 with subprocess.Popen(['borg', 'list', '--info', '--lock-wait', '120', '--json', path], stdout=subprocess.PIPE) as proc: 43 with subprocess.Popen(['borg', 'list', '--info', '--lock-wait', '120', '--json', path], stdout=subprocess.PIPE) as proc:
38 res = json.load(proc.stdout)['archives'] 44 res = json.load(proc.stdout)['archives']
@@ -58,7 +64,7 @@ class ToSync:
58 64
59def copy_archive(src_repo_path, dst_repo_path, entry): 65def copy_archive(src_repo_path, dst_repo_path, entry):
60 cache_suffix = None 66 cache_suffix = None
61 with Halo(text=f'Determine archive parameters', spinner='arc') as sp: 67 with Halo(text=f'Determine archive parameters', **halo_args) as sp:
62 match = re.compile('^(.*)-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.(checkpoint|recreate)(\.[0-9]+)?)?').fullmatch(entry['name']) 68 match = re.compile('^(.*)-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.(checkpoint|recreate)(\.[0-9]+)?)?').fullmatch(entry['name'])
63 if match: 69 if match:
64 repo_id = None 70 repo_id = None
@@ -91,7 +97,7 @@ def copy_archive(src_repo_path, dst_repo_path, entry):
91 os.chdir('/') 97 os.chdir('/')
92 dir = pathlib.Path('/borg') 98 dir = pathlib.Path('/borg')
93 dir.mkdir(parents=True,exist_ok=True) 99 dir.mkdir(parents=True,exist_ok=True)
94 with Halo(text=f'Determine size', spinner='arc') as sp: 100 with Halo(text=f'Determine size', **halo_args) as sp:
95 total_size = None 101 total_size = None
96 total_files = None 102 total_files = None
97 with subprocess.Popen(['borg', 'info', '--info', '--json', '--lock-wait', '120', f'{src_repo_path}::{entry["name"]}'], stdout=subprocess.PIPE, text=True) as proc: 103 with subprocess.Popen(['borg', 'info', '--info', '--json', '--lock-wait', '120', f'{src_repo_path}::{entry["name"]}'], stdout=subprocess.PIPE, text=True) as proc:
@@ -101,7 +107,7 @@ def copy_archive(src_repo_path, dst_repo_path, entry):
101 sp.succeed(f'{total_files} files, {naturalsize(total_size, binary=True)}') 107 sp.succeed(f'{total_files} files, {naturalsize(total_size, binary=True)}')
102 # print(f'Mounting to {dir}', file=stderr) 108 # print(f'Mounting to {dir}', file=stderr)
103 with subprocess.Popen(['borg', 'mount', '--foreground', '--progress', '--lock-wait', '120', f'{src_repo_path}::{entry["name"]}', dir]) as mount_proc: 109 with subprocess.Popen(['borg', 'mount', '--foreground', '--progress', '--lock-wait', '120', f'{src_repo_path}::{entry["name"]}', dir]) as mount_proc:
104 with Halo(text='Waiting for mount', spinner='arc') as sp: 110 with Halo(text='Waiting for mount', **halo_args) as sp:
105 wait_start = datetime.now() 111 wait_start = datetime.now()
106 while True: 112 while True:
107 ret = subprocess.run(['mountpoint', '-q', dir]) 113 ret = subprocess.run(['mountpoint', '-q', dir])