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('snapshot', '--snapshot', '-s', envvar='SNAPSHOT', default='latest')
|
||||||
@click.option('path', '--path', '-p', envvar='INCLUDE_PATH')
|
@click.option('path', '--path', '-p', envvar='INCLUDE_PATH')
|
||||||
def ls(snapshot, 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)
|
results = list_files(snapshot, path)
|
||||||
for r in results:
|
for r in results:
|
||||||
if r.get('path'):
|
if r.get('path'):
|
||||||
@ -419,12 +425,6 @@ def ls(snapshot, path):
|
|||||||
|
|
||||||
def list_files(snapshot, path):
|
def list_files(snapshot, path):
|
||||||
cmd = restic.cat.base_command() + ['ls']
|
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)
|
cmd.append(snapshot)
|
||||||
if path:
|
if path:
|
||||||
cmd.append(path)
|
cmd.append(path)
|
||||||
@ -451,6 +451,12 @@ def list_files(snapshot, path):
|
|||||||
@click.option('secrets', '--secrets', '-c', is_flag=True, envvar='SECRETS')
|
@click.option('secrets', '--secrets', '-c', is_flag=True, envvar='SECRETS')
|
||||||
def download(snapshot, path, volumes, secrets):
|
def download(snapshot, path, volumes, secrets):
|
||||||
file_dumps = []
|
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]):
|
if not any([path, volumes, secrets]):
|
||||||
volumes = secrets = True
|
volumes = secrets = True
|
||||||
if path:
|
if path:
|
||||||
@ -515,12 +521,6 @@ def get_formatted_size(file_path):
|
|||||||
|
|
||||||
def dump(snapshot, path):
|
def dump(snapshot, path):
|
||||||
cmd = restic.cat.base_command() + ['dump']
|
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]
|
cmd = cmd + [snapshot, path]
|
||||||
print(f"Dumping {path} from snapshot '{snapshot}'")
|
print(f"Dumping {path} from snapshot '{snapshot}'")
|
||||||
output = subprocess.run(cmd, capture_output=True)
|
output = subprocess.run(cmd, capture_output=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user