Fail if only one of SSH host and SSH user is set
Remote backup needs both, but if only one was set the program silently ran a local backup instead, and a missing ssh_user in the config also dropped ssh_host. Exit with an error (code 6) instead.
This commit is contained in:
+1
-1
@@ -207,7 +207,7 @@ rsync error (rsync returned a value other than 0 or 24).
|
|||||||
SSH connection failed.
|
SSH connection failed.
|
||||||
.TP
|
.TP
|
||||||
.B 6
|
.B 6
|
||||||
Bad configuration file.
|
Bad configuration file or options (for example, only one of SSH host and SSH user specified).
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR rsync (1)
|
.BR rsync (1)
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
|
|||||||
@@ -806,15 +806,10 @@ def _read_config(config_file, user: Optional[str] = None):
|
|||||||
|
|
||||||
config_args['keep'] = keep
|
config_args['keep'] = keep
|
||||||
|
|
||||||
try:
|
# Read host and user separately, so that a missing one is reported instead of silently
|
||||||
ssh_host = config.get('server', 'ssh_host')
|
# disabling remote backup. Empty values count as not set
|
||||||
ssh_user = config.get('server', 'ssh_user')
|
config_args['ssh_host'] = config.get('server', 'ssh_host', fallback='').strip() or None
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
config_args['ssh_user'] = config.get('server', 'ssh_user', fallback='').strip() or None
|
||||||
ssh_host = None
|
|
||||||
ssh_user = None
|
|
||||||
|
|
||||||
config_args['ssh_host'] = ssh_host
|
|
||||||
config_args['ssh_user'] = ssh_user
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ssh_keyfile = config.get('server', 'ssh_keyfile')
|
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_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']
|
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:
|
if args.output is not None:
|
||||||
output = args.output
|
output = args.output
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user