feat: add retry option
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
faa7ae3dd1
commit
f730c70bfe
28
backupbot.py
28
backupbot.py
|
@ -91,12 +91,13 @@ def export_secrets():
|
|||
|
||||
|
||||
@cli.command()
|
||||
def create():
|
||||
@click.option('retries', '--retries', '-r', envvar='RETRIES', default=1)
|
||||
def create(retries):
|
||||
pre_commands, post_commands, backup_paths, apps = get_backup_cmds()
|
||||
copy_secrets(apps)
|
||||
backup_paths.append(SECRET_PATH)
|
||||
run_commands(pre_commands)
|
||||
backup_volumes(backup_paths, apps)
|
||||
backup_volumes(backup_paths, apps, int(retries))
|
||||
run_commands(post_commands)
|
||||
|
||||
|
||||
|
@ -180,15 +181,20 @@ def run_commands(commands):
|
|||
logger.info(result.output.decode())
|
||||
|
||||
|
||||
def backup_volumes(backup_paths, apps, dry_run=False):
|
||||
try:
|
||||
result = restic.backup(backup_paths, dry_run=dry_run, tags=apps)
|
||||
logger.summary("backup finished", extra=result)
|
||||
except ResticFailedError as error:
|
||||
logger.error(
|
||||
f"Backup failed for {apps}. Could not Backup these paths: {backup_paths}")
|
||||
logger.error(error, exc_info=True)
|
||||
exit(1)
|
||||
def backup_volumes(backup_paths, apps, retries, dry_run=False):
|
||||
while True:
|
||||
try:
|
||||
result = restic.backup(backup_paths, dry_run=dry_run, tags=apps)
|
||||
logger.summary("backup finished", extra=result)
|
||||
return
|
||||
except ResticFailedError as error:
|
||||
logger.error(
|
||||
f"Backup failed for {apps}. Could not Backup these paths: {backup_paths}")
|
||||
logger.error(error, exc_info=True)
|
||||
if retries > 0:
|
||||
retries -= 1
|
||||
else:
|
||||
exit(1)
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
|
Loading…
Reference in New Issue