Catch error when backend cannot be created

This commit is contained in:
Orsiris de Jong 2023-04-12 08:47:44 +02:00
parent f58af9c3e2
commit d58400de62
5 changed files with 23 additions and 8 deletions

View file

@ -403,10 +403,13 @@ This is free software, and you are welcome to redistribute it under certain cond
if args.dry_run:
dry_run = True
npbackup_runner = NPBackupRunner(config_dict=config_dict)
npbackup_runner.dry_run = dry_run
npbackup_runner.verbose = _VERBOSE
logger.info("Backend: {}".format(npbackup_runner.backend_version))
try:
npbackup_runner = NPBackupRunner(config_dict=config_dict)
npbackup_runner.dry_run = dry_run
npbackup_runner.verbose = _VERBOSE
logger.info("Backend: {}".format(npbackup_runner.backend_version))
except ValueError:
logger.critical("Cannot create backend")
if args.check:
if npbackup_runner.check_recent_backups():

View file

@ -124,7 +124,8 @@ class NPBackupRunner:
self.is_ready = False
# Create an instance of restic wrapper
self.create_restic_runner()
if not self.create_restic_runner():
raise ValueError("Cannot create backend runner")
# Configure that instance
self.apply_config_to_restic_runner()
@ -219,7 +220,7 @@ class NPBackupRunner:
can_run = False
self.is_ready = can_run
if not can_run:
return
return None
self.restic_runner = ResticRunner(
repository=repository,
password=password,
@ -385,6 +386,7 @@ class NPBackupRunner:
# Preflight checks
try:
paths = self.config_dict["backup"]["paths"]
paths = [path.strip() for path in paths]
except KeyError:
logger.error("No backup paths defined.")
return False
@ -393,6 +395,10 @@ class NPBackupRunner:
try:
if not isinstance(paths, list):
paths = [paths]
for path in paths:
if path == self.config_dict["repo"]["repository"]:
logger.critical("Rayan error 40: You cannot backup destination in destination path. No inception allowed !")
return False
except KeyError:
logger.error("No backup source path given.")
return False

View file

@ -145,7 +145,11 @@ def get_gui_data(config_dict: dict) -> Tuple[bool, List[str]]:
except KeyError:
sg.Popup(_t("main_gui.repository_not_configured"))
return None, None
runner = NPBackupRunner(config_dict=config_dict)
try:
runner = NPBackupRunner(config_dict=config_dict)
except ValueError:
sg.Popup(_t("config_gui.no_runner"))
return None, None
if not runner.has_binary:
sg.Popup(_t("config_gui.no_binary"))
return None, None

View file

@ -47,7 +47,8 @@ en:
environment_variables: Environment variables
format_equals: Format variable=value
np_binary: Cannot find backup backend. Please install restic binary from restic.net
no_runner: Cannot connect to backend. Please see logs
no_binary: Cannot find backup backend. Please install restic binary from restic.net
configuration_saved: Configuration saved
cannot_save_configuration: Could not save configuration. See logs for further info

View file

@ -47,6 +47,7 @@ fr:
environment_variables: Variables d'environnement
format_equals: Format variable=valeur
no_runner: Impossible de se connecter au backend. Verifier les logs
no_binary: Impossible de trouver le coeur de sauvegarde. Merci d'installer le binaire restic depuis restic.net
configuration_saved: Configuration sauvegardée