Compare commits
2
Commits
4.0.0
..
dd779d242b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd779d242b
|
||
|
|
22a3e8d60f
|
@@ -172,6 +172,12 @@ Permission denied to access the output directory
|
|||||||
.TP
|
.TP
|
||||||
.B 4
|
.B 4
|
||||||
rsync error (rsync returned a non-zero value)
|
rsync error (rsync returned a non-zero value)
|
||||||
|
.TP
|
||||||
|
.B 5
|
||||||
|
SSH connection failed
|
||||||
|
.TP
|
||||||
|
.B 6
|
||||||
|
Bad configuration file
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR rsync (1)
|
.BR rsync (1)
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
|
|||||||
@@ -29,11 +29,16 @@ from getpass import getpass
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import paramiko
|
|
||||||
from paramiko import RSAKey, Ed25519Key, ECDSAKey, DSSKey
|
|
||||||
|
|
||||||
warnings.filterwarnings('error')
|
warnings.filterwarnings('error')
|
||||||
|
|
||||||
|
try:
|
||||||
|
raise ImportError
|
||||||
|
import paramiko
|
||||||
|
from paramiko import RSAKey, Ed25519Key, ECDSAKey, DSSKey
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from systemd import journal
|
from systemd import journal
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -181,7 +186,7 @@ class Backup:
|
|||||||
self._ssh = self._ssh_connect()
|
self._ssh = self._ssh_connect()
|
||||||
|
|
||||||
if self._ssh is None:
|
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')
|
_, 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._remote:
|
||||||
if self._ssh is None:
|
if self._ssh is None:
|
||||||
logger.critical('SSH connection to server failed')
|
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')
|
_, 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')
|
output = stdout.read().decode('utf-8').strip().split('\n')
|
||||||
@@ -311,7 +316,11 @@ class Backup:
|
|||||||
logger.info('No previous backups available')
|
logger.info('No previous backups available')
|
||||||
|
|
||||||
def _ssh_connect(self):
|
def _ssh_connect(self):
|
||||||
|
try:
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
|
except NameError:
|
||||||
|
logger.error('Install paramiko for ssh support')
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ssh.load_host_keys(filename=f'{homedir}/.ssh/known_hosts')
|
ssh.load_host_keys(filename=f'{homedir}/.ssh/known_hosts')
|
||||||
@@ -597,7 +606,15 @@ def _expand_inputs(inputs):
|
|||||||
|
|
||||||
|
|
||||||
def _read_config(config_file):
|
def _read_config(config_file):
|
||||||
config_args = {}
|
config_args = {'inputs': None,
|
||||||
|
'output': None,
|
||||||
|
'exclude': None,
|
||||||
|
'keep': -1,
|
||||||
|
'host': None,
|
||||||
|
'username': None,
|
||||||
|
'ssh_keyfile': None,
|
||||||
|
'remote_sudo': False,
|
||||||
|
'numeric_ids': False}
|
||||||
|
|
||||||
if not os.path.isfile(config_file):
|
if not os.path.isfile(config_file):
|
||||||
logger.warning('Config file %s does not exist', config_file)
|
logger.warning('Config file %s does not exist', config_file)
|
||||||
@@ -709,7 +726,7 @@ def simple_backup():
|
|||||||
config_args = _read_config(args.config)
|
config_args = _read_config(args.config)
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
||||||
logger.critical('Bad configuration file')
|
logger.critical('Bad configuration file')
|
||||||
sys.exit(1)
|
sys.exit(6)
|
||||||
|
|
||||||
inputs = args.inputs if args.inputs is not None else config_args['inputs']
|
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']
|
output = args.output if args.output is not None else config_args['output']
|
||||||
|
|||||||
Reference in New Issue
Block a user