Make 'if_modified' flag work, don't start 'fswatch' unless needed

master
root 4 years ago
parent 3d704831a1
commit 1c93fb57b0
  1. 6
      README.md
  2. 36
      src/zasd.py
  3. 1
      src/zasd/config.py

@ -20,4 +20,8 @@ using similar syntax for something else, you may need to change
the `separator` setting in `zasd.conf.py`. the `separator` setting in `zasd.conf.py`.
**DISCLAIMER:** This program is still in beta. Use at your own **DISCLAIMER:** This program is still in beta. Use at your own
risk. It works fine on my system, but your mileage may vary. risk. It works fine on my system, but your mileage may vary.
## Requirements
* `apscheduler`

@ -199,7 +199,7 @@ async def snapshot_creation_task(schedule, fs):
serial = make_snapshot_serial() serial = make_snapshot_serial()
recursive = schedule['recursive'] recursive = schedule['recursive']
if get_fs_flag(fs, tag): if not schedule['if_modified'] or get_fs_flag(fs, tag):
# Clear tag-modified flags for this tag on filesystem # Clear tag-modified flags for this tag on filesystem
clear_fs_flag(fs, tag) clear_fs_flag(fs, tag)
@ -239,13 +239,21 @@ def snapshot_matches_tag(snapshot, tag):
# Get tag of snapshot # Get tag of snapshot
def get_snapshot_tag(snapshot): def get_snapshot_tag(snapshot):
(tag, serial) = get_snapshot_fields(snapshot) fields = get_snapshot_fields(snapshot)
return tag if len(fields) == 2:
(tag, serial) = fields
return tag
else:
return ''
# Get serial number of snapshot # Get serial number of snapshot
def get_snapshot_serial(snapshot): def get_snapshot_serial(snapshot):
(tag, serial) = get_snapshot_fields(snapshot) fields = get_snapshot_fields(snapshot)
return serial if len(fields) == 2:
(tag, serial) = fields
return serial
else:
return ''
# Get tuple of fields in snapshot name # Get tuple of fields in snapshot name
def get_snapshot_fields(snapshot): def get_snapshot_fields(snapshot):
@ -302,18 +310,24 @@ def load_snapshot_schedules():
async def main_task(): async def main_task():
global config, event_loop, scheduler, fs_listeners global config, event_loop, scheduler, fs_listeners
scheduler = AsyncIOPriorityScheduler( scheduler = AsyncIOPriorityScheduler(
event_loop = event_loop, event_loop = event_loop,
executors = {'default': AsyncIOPriorityExecutor()}) executors = {'default': AsyncIOPriorityExecutor()})
monitor = False
for schedule in get_schedules():
if schedule['if_modified']:
monitor = True
# Watch file system mountpoints # Watch file system mountpoints
fs_listeners = dict() if monitor:
for fs in zfs_get_filesystems(): logger.info('Starting file system watcher')
await event_loop.subprocess_exec( fs_listeners = dict()
lambda: FSWatchProtocol(fs), config['fswatch_path'], '-o', fs['mountpoint'], stdout=PIPE) for fs in zfs_get_filesystems():
await event_loop.subprocess_exec(
lambda: FSWatchProtocol(fs), config['fswatch_path'], '-o', fs['mountpoint'], stdout=PIPE)
load_snapshot_schedules() load_snapshot_schedules()
scheduler.start() scheduler.start()

@ -44,6 +44,7 @@ DEFAULT_CONFIG = {
'disabled': False, 'disabled': False,
'filesystems': ['tank'], 'filesystems': ['tank'],
'recursive': True, 'recursive': True,
'if_modified': False,
'tag': 'zasd', 'tag': 'zasd',
'trigger': IntervalTrigger(hours=12), 'trigger': IntervalTrigger(hours=12),
'priority': 1, 'priority': 1,

Loading…
Cancel
Save