Compare commits

..

No commits in common. "master" and "v0.3.0" have entirely different histories.

3 changed files with 13 additions and 34 deletions

View File

@ -5,7 +5,6 @@ import os
import re import re
import logging import logging
import logging.handlers import logging.handlers
import stat
import subprocess import subprocess
import sys import sys
@ -259,7 +258,7 @@ def weed_snapshots(fslist, snapshots, config, failed_snapshots):
continue continue
if source_fs not in snapshots: if source_fs not in snapshots:
continue continue
if not conf['weed_enable'] or conf['weed_enable'].lower() in ('false', 'no'): if not conf['weed_enable']:
continue continue
kwargs = {k: int(v) for k, v in conf.items() if k in [ kwargs = {k: int(v) for k, v in conf.items() if k in [
@ -289,8 +288,7 @@ def weed_snapshots(fslist, snapshots, config, failed_snapshots):
def main(): def main():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(['/usr/local/etc/zsnapper.ini', '/etc/zsnapper.ini']) config.read('/etc/zsnapper.ini')
ret = RET_CODES['SUCCESS'] ret = RET_CODES['SUCCESS']
log = logging.getLogger(LOGGER) log = logging.getLogger(LOGGER)
@ -369,9 +367,9 @@ def main():
try: try:
if remote in remote_snapshots: if remote in remote_snapshots:
remote_snapshots[remote] = zsnaplib.get_snapshots(zfs_cmd) remote_snapshots[remote] = zsnaplib.get_snapshots(zfs_cmd)
except zsnaplib.ZFSSnapshotError as e: except zsnaplib.ZFSSnapshotError:
del remote_snapshots[remote] del remote_snapshots[remote]
log.warning("Could not refresh snapshots on {}: {}".format(remote, e)) log.warning("Could not refresh snapshots on {}".format(remote))
snapshots = zsnaplib.get_snapshots(local_zfs_cmd) snapshots = zsnaplib.get_snapshots(local_zfs_cmd)
failed_send = send_snapshots(fslist, snapshots, config) failed_send = send_snapshots(fslist, snapshots, config)
@ -405,22 +403,9 @@ if __name__ == '__main__':
handler.setLevel(logging.WARNING) handler.setLevel(logging.WARNING)
log.addHandler(handler) log.addHandler(handler)
handler = None handler = logging.handlers.SysLogHandler(address='/dev/log')
for logsocket in ('/var/run/log', '/dev/log'):
try:
mode = os.stat(logsocket).st_mode
except FileNotFoundError:
continue
if stat.S_ISSOCK(mode):
handler = logging.handlers.SysLogHandler(address=logsocket)
formatter = logging.Formatter(fmt='zsnapper[%(process)s] %(message)s') formatter = logging.Formatter(fmt='zsnapper[%(process)s] %(message)s')
handler.setFormatter(formatter) handler.setFormatter(formatter)
handler.setLevel(logging.INFO) handler.setLevel(logging.INFO)
log.addHandler(handler) log.addHandler(handler)
break
if not handler:
log.warning('No syslog socket found, will not log to syslog')
sys.exit(main()) sys.exit(main())

View File

@ -6,7 +6,7 @@ try:
except ImportError: except ImportError:
from distutils import setup from distutils import setup
version = '0.3.4' version = '0.3'
setup( setup(
name='zsnapper', name='zsnapper',

View File

@ -6,7 +6,6 @@ import sys
time_format='%Y-%m-%d_%H%M' time_format='%Y-%m-%d_%H%M'
re_snapshot = re.compile(r'^(.*)@([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{4})$') re_snapshot = re.compile(r'^(.*)@([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{4})$')
re_err_ok = re.compile(r"cannot create snapshot '[^']+': dataset already exists")
logger = 'zsnapper' logger = 'zsnapper'
class ZFSSnapshotError(Exception): class ZFSSnapshotError(Exception):
@ -34,12 +33,7 @@ def do_zfs_command(args, zfs_cmd, pipecmd=None):
(out, err) = ctrl_proc.communicate() (out, err) = ctrl_proc.communicate()
# check if we try to create a snapshot that already exists. This can happen if ctrl_proc.returncode != 0:
# if the script is run every minute and it takes more time than that to
# create all snapshots
if ctrl_proc.returncode == 1 and re.match(re_err_ok, err.decode('utf-8')):
pass
elif ctrl_proc.returncode != 0:
raise ZFSSnapshotError('Failed to execute {}: {}'.format(cmd, err)) raise ZFSSnapshotError('Failed to execute {}: {}'.format(cmd, err))
return out return out
@ -83,7 +77,7 @@ def get_filesystems(zfs_cmd):
for row in out.splitlines(): for row in out.splitlines():
row = row.decode('UTF-8') row = row.decode('UTF-8')
ret.add(row.split('\t')[0]) ret.add(row.split()[0])
return ret return ret
@ -93,7 +87,7 @@ def get_snapshots(zfs_cmd):
snapshots = {} snapshots = {}
for row in out.splitlines(): for row in out.splitlines():
row = row.decode('UTF-8').split('\t')[0] row = row.decode('UTF-8').split()[0]
res = re_snapshot.match(row) res = re_snapshot.match(row)
if res: if res:
d = datetime.datetime.strptime(res.group(2), time_format) d = datetime.datetime.strptime(res.group(2), time_format)