diff --git a/README.md b/README.md index a18075b..da29cb8 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +risk. It works fine on my system, but your mileage may vary. + +## Requirements + +* `apscheduler` diff --git a/src/zasd.py b/src/zasd.py index 39d386e..f3ea775 100644 --- a/src/zasd.py +++ b/src/zasd.py @@ -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() diff --git a/src/zasd/config.py b/src/zasd/config.py index 332aa01..1a21f8a 100644 --- a/src/zasd/config.py +++ b/src/zasd/config.py @@ -44,6 +44,7 @@ DEFAULT_CONFIG = { 'disabled': False, 'filesystems': ['tank'], 'recursive': True, + 'if_modified': False, 'tag': 'zasd', 'trigger': IntervalTrigger(hours=12), 'priority': 1,