mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-05-30 01:19:16 +03:00
Implement Issue #245 Snapshot exclude patterns
This commit is contained in:
parent
9e2476ac84
commit
67f6f37a8f
@ -1,4 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .CliBase import CliBase
|
from .CliBase import CliBase
|
||||||
@ -112,6 +113,14 @@ class ZfsAuto(CliBase):
|
|||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
|
||||||
|
def regex_argument_type(input_line):
|
||||||
|
"""Parses regex arguments into re.Pattern objects"""
|
||||||
|
try:
|
||||||
|
return re.compile(input_line)
|
||||||
|
except:
|
||||||
|
raise ValueError("Could not parse argument '{}' as a regular expression".format(input_line))
|
||||||
|
group.add_argument('--exclude-snapshot-pattern', action='append', default=[], type=regex_argument_type, help="Regular expression to match snapshots that will be ignored.")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def print_error_sources(self):
|
def print_error_sources(self):
|
||||||
|
@ -472,7 +472,8 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
snapshot_time_format=self.snapshot_time_format, hold_name=self.hold_name, logger=self,
|
snapshot_time_format=self.snapshot_time_format, hold_name=self.hold_name, logger=self,
|
||||||
ssh_config=self.args.ssh_config,
|
ssh_config=self.args.ssh_config,
|
||||||
ssh_to=self.args.ssh_source, readonly=self.args.test,
|
ssh_to=self.args.ssh_source, readonly=self.args.test,
|
||||||
debug_output=self.args.debug_output, description=description, thinner=source_thinner)
|
debug_output=self.args.debug_output, description=description, thinner=source_thinner,
|
||||||
|
exclude_snapshot_patterns=self.args.exclude_snapshot_pattern)
|
||||||
|
|
||||||
################# select source datasets
|
################# select source datasets
|
||||||
self.set_title("Selecting")
|
self.set_title("Selecting")
|
||||||
|
@ -235,7 +235,8 @@ class ZfsAutoverify(ZfsAuto):
|
|||||||
snapshot_time_format=self.snapshot_time_format, hold_name=self.hold_name, logger=self,
|
snapshot_time_format=self.snapshot_time_format, hold_name=self.hold_name, logger=self,
|
||||||
ssh_config=self.args.ssh_config,
|
ssh_config=self.args.ssh_config,
|
||||||
ssh_to=self.args.ssh_source, readonly=self.args.test,
|
ssh_to=self.args.ssh_source, readonly=self.args.test,
|
||||||
debug_output=self.args.debug_output, description=description)
|
debug_output=self.args.debug_output, description=description,
|
||||||
|
exclude_snapshot_patterns=self.args.exclude_snapshot_pattern)
|
||||||
|
|
||||||
################# select source datasets
|
################# select source datasets
|
||||||
self.set_title("Selecting")
|
self.set_title("Selecting")
|
||||||
|
@ -124,6 +124,20 @@ class ZfsDataset:
|
|||||||
def is_snapshot(self):
|
def is_snapshot(self):
|
||||||
"""true if this dataset is a snapshot"""
|
"""true if this dataset is a snapshot"""
|
||||||
return self.name.find("@") != -1
|
return self.name.find("@") != -1
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_excluded(self):
|
||||||
|
"""true if this dataset is a snapshot and matches the exclude pattern"""
|
||||||
|
if not self.is_snapshot:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
for pattern in self.zfs_node.exclude_snapshot_patterns:
|
||||||
|
if pattern.search(self.name) is not None:
|
||||||
|
self.debug("Excluded (path matches snapshot exclude pattern)")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def is_selected(self, value, source, inherited, exclude_received, exclude_paths, exclude_unchanged):
|
def is_selected(self, value, source, inherited, exclude_received, exclude_paths, exclude_unchanged):
|
||||||
"""determine if dataset should be selected for backup (called from
|
"""determine if dataset should be selected for backup (called from
|
||||||
@ -1171,7 +1185,7 @@ class ZfsDataset:
|
|||||||
target_snapshot = target_dataset.find_snapshot(source_snapshot) # still virtual
|
target_snapshot = target_dataset.find_snapshot(source_snapshot) # still virtual
|
||||||
|
|
||||||
# does target actually want it?
|
# does target actually want it?
|
||||||
if target_snapshot not in target_obsoletes:
|
if target_snapshot not in target_obsoletes and not source_snapshot.is_excluded:
|
||||||
|
|
||||||
# do the rollback, one time at first transfer
|
# do the rollback, one time at first transfer
|
||||||
if do_rollback:
|
if do_rollback:
|
||||||
|
@ -20,7 +20,7 @@ class ZfsNode(ExecuteNode):
|
|||||||
|
|
||||||
def __init__(self, logger, utc=False, snapshot_time_format="", hold_name="", ssh_config=None, ssh_to=None, readonly=False,
|
def __init__(self, logger, utc=False, snapshot_time_format="", hold_name="", ssh_config=None, ssh_to=None, readonly=False,
|
||||||
description="",
|
description="",
|
||||||
debug_output=False, thinner=None):
|
debug_output=False, thinner=None, exclude_snapshot_patterns=[]):
|
||||||
|
|
||||||
self.utc = utc
|
self.utc = utc
|
||||||
self.snapshot_time_format = snapshot_time_format
|
self.snapshot_time_format = snapshot_time_format
|
||||||
@ -30,6 +30,8 @@ class ZfsNode(ExecuteNode):
|
|||||||
|
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
|
||||||
|
self.exclude_snapshot_patterns = exclude_snapshot_patterns
|
||||||
|
|
||||||
if ssh_config:
|
if ssh_config:
|
||||||
self.verbose("Using custom SSH config: {}".format(ssh_config))
|
self.verbose("Using custom SSH config: {}".format(ssh_config))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user