diff options
Diffstat (limited to 'hosts/vidhar')
-rwxr-xr-x | hosts/vidhar/borg/copy.py | 14 |
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') | |||
31 | parser.add_argument('target', metavar='REPO_OR_ARCHIVE') | 31 | parser.add_argument('target', metavar='REPO_OR_ARCHIVE') |
32 | args = parser.parse_args() | 32 | args = parser.parse_args() |
33 | 33 | ||
34 | halo_args = { | ||
35 | stream: sys.stderr, | ||
36 | enabled: not sys.stderr.isatty(), | ||
37 | spinner: 'arc' | ||
38 | } | ||
39 | |||
34 | def read_repo(path): | 40 | def 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 | ||
59 | def copy_archive(src_repo_path, dst_repo_path, entry): | 65 | def 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]) |