refactor: move latest snapshot checking
This commit is contained in:
parent
4a49c4a7f0
commit
f8cfcef029
24
backupbot.py
24
backupbot.py
@ -411,6 +411,12 @@ def snapshots():
|
||||
@click.option('snapshot', '--snapshot', '-s', envvar='SNAPSHOT', default='latest')
|
||||
@click.option('path', '--path', '-p', envvar='INCLUDE_PATH')
|
||||
def ls(snapshot, path):
|
||||
if snapshot == 'latest':
|
||||
latest_snapshot = get_snapshots('latest')
|
||||
if not latest_snapshot:
|
||||
logger.error(f"There is no latest snapshot for {SERVICE}")
|
||||
exit(1)
|
||||
snapshot = latest_snapshot[0]['short_id']
|
||||
results = list_files(snapshot, path)
|
||||
for r in results:
|
||||
if r.get('path'):
|
||||
@ -419,12 +425,6 @@ def ls(snapshot, path):
|
||||
|
||||
def list_files(snapshot, path):
|
||||
cmd = restic.cat.base_command() + ['ls']
|
||||
if snapshot == 'latest':
|
||||
latest_snapshot = get_snapshots('latest')
|
||||
if not latest_snapshot:
|
||||
logger.error(f"There is no latest snapshot for {SERVICE}")
|
||||
exit(1)
|
||||
snapshot = latest_snapshot[0]['short_id']
|
||||
cmd.append(snapshot)
|
||||
if path:
|
||||
cmd.append(path)
|
||||
@ -451,6 +451,12 @@ def list_files(snapshot, path):
|
||||
@click.option('secrets', '--secrets', '-c', is_flag=True, envvar='SECRETS')
|
||||
def download(snapshot, path, volumes, secrets):
|
||||
file_dumps = []
|
||||
if snapshot == 'latest':
|
||||
latest_snapshot = get_snapshots('latest')
|
||||
if not latest_snapshot:
|
||||
logger.error(f"There is no latest snapshot for {SERVICE}")
|
||||
exit(1)
|
||||
snapshot = latest_snapshot[0]['short_id']
|
||||
if not any([path, volumes, secrets]):
|
||||
volumes = secrets = True
|
||||
if path:
|
||||
@ -515,12 +521,6 @@ def get_formatted_size(file_path):
|
||||
|
||||
def dump(snapshot, path):
|
||||
cmd = restic.cat.base_command() + ['dump']
|
||||
if snapshot == 'latest':
|
||||
latest_snapshot = get_snapshots('latest')
|
||||
if not latest_snapshot:
|
||||
logger.error(f"There is no latest snapshot for {SERVICE}")
|
||||
exit(1)
|
||||
snapshot = latest_snapshot[0]['short_id']
|
||||
cmd = cmd + [snapshot, path]
|
||||
print(f"Dumping {path} from snapshot '{snapshot}'")
|
||||
output = subprocess.run(cmd, capture_output=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user