forked from third-party-mirrors/zfs_autobackup
Merge remote-tracking branch 'remotes/mariusvw/feature/ssh-config'
This commit is contained in:
commit
dfd38985d1
32
README.md
32
README.md
@ -17,6 +17,7 @@
|
|||||||
* More robust error handling.
|
* More robust error handling.
|
||||||
* Prepared for future enhanchements.
|
* Prepared for future enhanchements.
|
||||||
* Supports raw backups for encryption.
|
* Supports raw backups for encryption.
|
||||||
|
* Custom SSH client config.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
@ -228,7 +229,8 @@ Here you find all the options:
|
|||||||
|
|
||||||
```console
|
```console
|
||||||
[root@server ~]# zfs-autobackup --help
|
[root@server ~]# zfs-autobackup --help
|
||||||
usage: zfs-autobackup [-h] [--ssh-source SSH_SOURCE] [--ssh-target SSH_TARGET]
|
usage: zfs-autobackup [-h] [--ssh-config SSH_CONFIG]
|
||||||
|
[--ssh-source SSH_SOURCE] [--ssh-target SSH_TARGET]
|
||||||
[--keep-source KEEP_SOURCE] [--keep-target KEEP_TARGET]
|
[--keep-source KEEP_SOURCE] [--keep-target KEEP_TARGET]
|
||||||
[--no-snapshot] [--allow-empty] [--ignore-replicated]
|
[--no-snapshot] [--allow-empty] [--ignore-replicated]
|
||||||
[--no-holds] [--resume] [--strip-path STRIP_PATH]
|
[--no-holds] [--resume] [--strip-path STRIP_PATH]
|
||||||
@ -250,6 +252,8 @@ positional arguments:
|
|||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
--ssh-config SSH_COFNIG
|
||||||
|
Custom SSH client config
|
||||||
--ssh-source SSH_SOURCE
|
--ssh-source SSH_SOURCE
|
||||||
Source host to get backup from. (user@hostname)
|
Source host to get backup from. (user@hostname)
|
||||||
Default None.
|
Default None.
|
||||||
@ -327,6 +331,32 @@ Host *
|
|||||||
ControlPersist 3600
|
ControlPersist 3600
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or more advanced
|
||||||
|
```console
|
||||||
|
Host *
|
||||||
|
StrictHostKeyChecking yes
|
||||||
|
UpdateHostKeys ask
|
||||||
|
GSSAPIAuthentication no
|
||||||
|
ForwardAgent no
|
||||||
|
HashKnownHosts no
|
||||||
|
CheckHostIP yes
|
||||||
|
ConnectionAttempts 3
|
||||||
|
ExitOnForwardFailure yes
|
||||||
|
Compression yes
|
||||||
|
ServerAliveCountMax 4
|
||||||
|
ServerAliveInterval 5
|
||||||
|
TCPKeepAlive yes
|
||||||
|
ControlMaster auto
|
||||||
|
ControlPath ~/.ssh/control-master-%r@%h:%p
|
||||||
|
ControlPersist 3600
|
||||||
|
AddKeysToAgent no
|
||||||
|
IdentityFile ~/.ssh/id_ed25519-backup
|
||||||
|
IdentityFile ~/.ssh/id_rsa-backup
|
||||||
|
User root
|
||||||
|
SendEnv LANG LC_*
|
||||||
|
LogLevel INFO
|
||||||
|
```
|
||||||
|
|
||||||
This will make all your ssh connections persistent and greatly speed up zfs-autobackup for jobs with short intervals.
|
This will make all your ssh connections persistent and greatly speed up zfs-autobackup for jobs with short intervals.
|
||||||
|
|
||||||
Thanks @mariusvw :)
|
Thanks @mariusvw :)
|
||||||
|
@ -306,12 +306,14 @@ class ExecuteNode:
|
|||||||
"""an endpoint to execute local or remote commands via ssh"""
|
"""an endpoint to execute local or remote commands via ssh"""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, ssh_to=None, readonly=False, debug_output=False):
|
def __init__(self, ssh_config=None, ssh_to=None, readonly=False, debug_output=False):
|
||||||
"""ssh_to: server you want to ssh to. none means local
|
"""ssh_config: custom ssh config
|
||||||
|
ssh_to: server you want to ssh to. none means local
|
||||||
readonly: only execute commands that dont make any changes (usefull for testing-runs)
|
readonly: only execute commands that dont make any changes (usefull for testing-runs)
|
||||||
debug_output: show output and exit codes of commands in debugging output.
|
debug_output: show output and exit codes of commands in debugging output.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.ssh_config=ssh_config
|
||||||
self.ssh_to=ssh_to
|
self.ssh_to=ssh_to
|
||||||
self.readonly=readonly
|
self.readonly=readonly
|
||||||
self.debug_output=debug_output
|
self.debug_output=debug_output
|
||||||
@ -356,7 +358,12 @@ class ExecuteNode:
|
|||||||
|
|
||||||
#use ssh?
|
#use ssh?
|
||||||
if self.ssh_to != None:
|
if self.ssh_to != None:
|
||||||
encoded_cmd.extend(["ssh".encode('utf-8'), self.ssh_to.encode('utf-8')])
|
encoded_cmd.append("ssh".encode('utf-8'))
|
||||||
|
|
||||||
|
if self.ssh_config != None:
|
||||||
|
encoded_cmd.extend(["-F".encode('utf-8'), self.ssh_config.encode('utf-8')])
|
||||||
|
|
||||||
|
encoded_cmd.append(self.ssh_to.encode('utf-8'))
|
||||||
|
|
||||||
#make sure the command gets all the data in utf8 format:
|
#make sure the command gets all the data in utf8 format:
|
||||||
#(this is neccesary if LC_ALL=en_US.utf8 is not set in the environment)
|
#(this is neccesary if LC_ALL=en_US.utf8 is not set in the environment)
|
||||||
@ -1188,7 +1195,7 @@ class ZfsDataset():
|
|||||||
class ZfsNode(ExecuteNode):
|
class ZfsNode(ExecuteNode):
|
||||||
"""a node that contains zfs datasets. implements global (systemwide/pool wide) zfs commands"""
|
"""a node that contains zfs datasets. implements global (systemwide/pool wide) zfs commands"""
|
||||||
|
|
||||||
def __init__(self, backup_name, zfs_autobackup, ssh_to=None, readonly=False, description="", debug_output=False, thinner=Thinner()):
|
def __init__(self, backup_name, zfs_autobackup, ssh_config=None, ssh_to=None, readonly=False, description="", debug_output=False, thinner=Thinner()):
|
||||||
self.backup_name=backup_name
|
self.backup_name=backup_name
|
||||||
if not description:
|
if not description:
|
||||||
self.description=ssh_to
|
self.description=ssh_to
|
||||||
@ -1197,6 +1204,9 @@ class ZfsNode(ExecuteNode):
|
|||||||
|
|
||||||
self.zfs_autobackup=zfs_autobackup #for logging
|
self.zfs_autobackup=zfs_autobackup #for logging
|
||||||
|
|
||||||
|
if ssh_config:
|
||||||
|
self.verbose("Using custom SSH config: {}".format(ssh_config))
|
||||||
|
|
||||||
if ssh_to:
|
if ssh_to:
|
||||||
self.verbose("Datasets on: {}".format(ssh_to))
|
self.verbose("Datasets on: {}".format(ssh_to))
|
||||||
else:
|
else:
|
||||||
@ -1212,7 +1222,7 @@ class ZfsNode(ExecuteNode):
|
|||||||
self.thinner=thinner
|
self.thinner=thinner
|
||||||
|
|
||||||
|
|
||||||
ExecuteNode.__init__(self, ssh_to=ssh_to, readonly=readonly, debug_output=debug_output)
|
ExecuteNode.__init__(self, ssh_config=ssh_config, ssh_to=ssh_to, readonly=readonly, debug_output=debug_output)
|
||||||
|
|
||||||
|
|
||||||
def reset_progress(self):
|
def reset_progress(self):
|
||||||
@ -1377,6 +1387,7 @@ class ZfsAutobackup:
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description=HEADER,
|
description=HEADER,
|
||||||
epilog='When a filesystem fails, zfs_backup will continue and report the number of failures at that end. Also the exit code will indicate the number of failures.')
|
epilog='When a filesystem fails, zfs_backup will continue and report the number of failures at that end. Also the exit code will indicate the number of failures.')
|
||||||
|
parser.add_argument('--ssh-config', default=None, help='Custom ssh client config')
|
||||||
parser.add_argument('--ssh-source', default=None, help='Source host to get backup from. (user@hostname) Default %(default)s.')
|
parser.add_argument('--ssh-source', default=None, help='Source host to get backup from. (user@hostname) Default %(default)s.')
|
||||||
parser.add_argument('--ssh-target', default=None, help='Target host to push backup to. (user@hostname) Default %(default)s.')
|
parser.add_argument('--ssh-target', default=None, help='Target host to push backup to. (user@hostname) Default %(default)s.')
|
||||||
parser.add_argument('--keep-source', type=str, default="10,1d1w,1w1m,1m1y", help='Thinning schedule for old source snapshots. Default: %(default)s')
|
parser.add_argument('--keep-source', type=str, default="10,1d1w,1w1m,1m1y", help='Thinning schedule for old source snapshots. Default: %(default)s')
|
||||||
@ -1453,14 +1464,14 @@ class ZfsAutobackup:
|
|||||||
|
|
||||||
description="[Source]"
|
description="[Source]"
|
||||||
source_thinner=Thinner(self.args.keep_source)
|
source_thinner=Thinner(self.args.keep_source)
|
||||||
source_node=ZfsNode(self.args.backup_name, self, ssh_to=self.args.ssh_source, readonly=self.args.test, debug_output=self.args.debug_output, description=description, thinner=source_thinner)
|
source_node=ZfsNode(self.args.backup_name, self, ssh_config=self.args.ssh_config, ssh_to=self.args.ssh_source, readonly=self.args.test, debug_output=self.args.debug_output, description=description, thinner=source_thinner)
|
||||||
source_node.verbose("Send all datasets that have 'autobackup:{}=true' or 'autobackup:{}=child'".format(self.args.backup_name, self.args.backup_name))
|
source_node.verbose("Send all datasets that have 'autobackup:{}=true' or 'autobackup:{}=child'".format(self.args.backup_name, self.args.backup_name))
|
||||||
|
|
||||||
self.verbose("")
|
self.verbose("")
|
||||||
|
|
||||||
description="[Target]"
|
description="[Target]"
|
||||||
target_thinner=Thinner(self.args.keep_target)
|
target_thinner=Thinner(self.args.keep_target)
|
||||||
target_node=ZfsNode(self.args.backup_name, self, ssh_to=self.args.ssh_target, readonly=self.args.test, debug_output=self.args.debug_output, description=description, thinner=target_thinner)
|
target_node=ZfsNode(self.args.backup_name, self, ssh_config=self.args.ssh_config, ssh_to=self.args.ssh_target, readonly=self.args.test, debug_output=self.args.debug_output, description=description, thinner=target_thinner)
|
||||||
target_node.verbose("Receive datasets under: {}".format(self.args.target_path))
|
target_node.verbose("Receive datasets under: {}".format(self.args.target_path))
|
||||||
|
|
||||||
self.set_title("Selecting")
|
self.set_title("Selecting")
|
||||||
@ -1547,5 +1558,3 @@ class ZfsAutobackup:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
zfs_autobackup=ZfsAutobackup()
|
zfs_autobackup=ZfsAutobackup()
|
||||||
sys.exit(zfs_autobackup.run())
|
sys.exit(zfs_autobackup.run())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user