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`.
**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()
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_fs_flag(fs, tag)
@ -239,13 +239,21 @@ def snapshot_matches_tag(snapshot, tag):
# Get tag of snapshot
def get_snapshot_tag(snapshot):
(tag, serial) = get_snapshot_fields(snapshot)
return tag
fields = get_snapshot_fields(snapshot)
if len(fields) == 2:
(tag, serial) = fields
return tag
else:
return ''
# Get serial number of snapshot
def get_snapshot_serial(snapshot):
(tag, serial) = get_snapshot_fields(snapshot)
return serial
fields = get_snapshot_fields(snapshot)
if len(fields) == 2:
(tag, serial) = fields
return serial
else:
return ''
# Get tuple of fields in snapshot name
def get_snapshot_fields(snapshot):
@ -302,18 +310,24 @@ def load_snapshot_schedules():
async def main_task():
global config, event_loop, scheduler, fs_listeners
scheduler = AsyncIOPriorityScheduler(
event_loop = event_loop,
executors = {'default': AsyncIOPriorityExecutor()})
monitor = False
for schedule in get_schedules():
if schedule['if_modified']:
monitor = True
# Watch file system mountpoints
fs_listeners = dict()
for fs in zfs_get_filesystems():
await event_loop.subprocess_exec(
lambda: FSWatchProtocol(fs), config['fswatch_path'], '-o', fs['mountpoint'], stdout=PIPE)
if monitor:
logger.info('Starting file system watcher')
fs_listeners = dict()
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()
scheduler.start()

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

Loading…
Cancel
Save