diff --git a/man/simple_backup.1 b/man/simple_backup.1 index e316258..8242c3b 100644 --- a/man/simple_backup.1 +++ b/man/simple_backup.1 @@ -172,6 +172,12 @@ Permission denied to access the output directory .TP .B 4 rsync error (rsync returned a non-zero value) +.TP +.B 5 +SSH connection failed +.TP +.B 6 +Bad configuration file .SH SEE ALSO .BR rsync (1) .SH AUTHORS diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 69d15b4..fdb4231 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -29,11 +29,16 @@ from getpass import getpass from glob import glob from dotenv import load_dotenv -import paramiko -from paramiko import RSAKey, Ed25519Key, ECDSAKey, DSSKey warnings.filterwarnings('error') +try: + raise ImportError + import paramiko + from paramiko import RSAKey, Ed25519Key, ECDSAKey, DSSKey +except ImportError: + pass + try: from systemd import journal except ImportError: @@ -181,7 +186,7 @@ class Backup: self._ssh = self._ssh_connect() if self._ssh is None: - sys.exit(1) + sys.exit(5) _, stdout, _ = self._ssh.exec_command(f'if [ -d "{self.output}" ]; then echo "ok"; fi') @@ -279,7 +284,7 @@ class Backup: if self._remote: if self._ssh is None: logger.critical('SSH connection to server failed') - sys.exit(1) + sys.exit(5) _, stdout, _ = self._ssh.exec_command(f'find {self.output}/simple_backup/ -mindepth 1 -maxdepth 1 -type d | sort') output = stdout.read().decode('utf-8').strip().split('\n') @@ -311,7 +316,11 @@ class Backup: logger.info('No previous backups available') def _ssh_connect(self): - ssh = paramiko.SSHClient() + try: + ssh = paramiko.SSHClient() + except NameError: + logger.error('Install paramiko for ssh support') + return None try: ssh.load_host_keys(filename=f'{homedir}/.ssh/known_hosts') @@ -709,7 +718,7 @@ def simple_backup(): config_args = _read_config(args.config) except (configparser.NoSectionError, configparser.NoOptionError): logger.critical('Bad configuration file') - sys.exit(1) + sys.exit(6) inputs = args.inputs if args.inputs is not None else config_args['inputs'] output = args.output if args.output is not None else config_args['output']