diff --git a/man/simple_backup.1 b/man/simple_backup.1 index c3a9a46..77b1d68 100644 --- a/man/simple_backup.1 +++ b/man/simple_backup.1 @@ -207,7 +207,7 @@ rsync error (rsync returned a value other than 0 or 24). SSH connection failed. .TP .B 6 -Bad configuration file. +Bad configuration file or options (for example, only one of SSH host and SSH user specified). .SH SEE ALSO .BR rsync (1) .SH AUTHORS diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index ca810a4..78a56be 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -806,15 +806,10 @@ def _read_config(config_file, user: Optional[str] = None): config_args['keep'] = keep - try: - ssh_host = config.get('server', 'ssh_host') - ssh_user = config.get('server', 'ssh_user') - except (configparser.NoSectionError, configparser.NoOptionError): - ssh_host = None - ssh_user = None - - config_args['ssh_host'] = ssh_host - config_args['ssh_user'] = ssh_user + # Read host and user separately, so that a missing one is reported instead of silently + # disabling remote backup. Empty values count as not set + config_args['ssh_host'] = config.get('server', 'ssh_host', fallback='').strip() or None + config_args['ssh_user'] = config.get('server', 'ssh_user', fallback='').strip() or None try: ssh_keyfile = config.get('server', 'ssh_keyfile') @@ -947,6 +942,11 @@ def simple_backup() -> int: ssh_host = args.ssh_host if args.ssh_host is not None else config_args['ssh_host'] ssh_user = args.ssh_user if args.ssh_user is not None else config_args['ssh_user'] + if (ssh_host is None) != (ssh_user is None): + logger.critical('Both SSH host and SSH user are needed for remote backup') + + return 6 + if args.output is not None: output = args.output else: