Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
328d1649ce | |||
5588780887 | |||
b0758a6b8b | |||
1290623456 | |||
2a91a41ede | |||
46eed410f0 | |||
2340a2f601 | |||
bc055a8dfa | |||
97530e624a | |||
d1d9c3ca15 |
25
bin/zsnapper
25
bin/zsnapper
@ -5,6 +5,7 @@ import os
|
||||
import re
|
||||
import logging
|
||||
import logging.handlers
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@ -258,7 +259,7 @@ def weed_snapshots(fslist, snapshots, config, failed_snapshots):
|
||||
continue
|
||||
if source_fs not in snapshots:
|
||||
continue
|
||||
if not conf['weed_enable']:
|
||||
if not conf['weed_enable'] or conf['weed_enable'].lower() in ('false', 'no'):
|
||||
continue
|
||||
|
||||
kwargs = {k: int(v) for k, v in conf.items() if k in [
|
||||
@ -288,7 +289,8 @@ def weed_snapshots(fslist, snapshots, config, failed_snapshots):
|
||||
|
||||
def main():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('/etc/zsnapper.ini')
|
||||
config.read(['/usr/local/etc/zsnapper.ini', '/etc/zsnapper.ini'])
|
||||
|
||||
ret = RET_CODES['SUCCESS']
|
||||
log = logging.getLogger(LOGGER)
|
||||
|
||||
@ -367,9 +369,9 @@ def main():
|
||||
try:
|
||||
if remote in remote_snapshots:
|
||||
remote_snapshots[remote] = zsnaplib.get_snapshots(zfs_cmd)
|
||||
except zsnaplib.ZFSSnapshotError:
|
||||
except zsnaplib.ZFSSnapshotError as e:
|
||||
del remote_snapshots[remote]
|
||||
log.warning("Could not refresh snapshots on {}".format(remote))
|
||||
log.warning("Could not refresh snapshots on {}: {}".format(remote, e))
|
||||
snapshots = zsnaplib.get_snapshots(local_zfs_cmd)
|
||||
|
||||
failed_send = send_snapshots(fslist, snapshots, config)
|
||||
@ -403,9 +405,22 @@ if __name__ == '__main__':
|
||||
handler.setLevel(logging.WARNING)
|
||||
log.addHandler(handler)
|
||||
|
||||
handler = logging.handlers.SysLogHandler(address='/dev/log')
|
||||
handler = None
|
||||
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')
|
||||
handler.setFormatter(formatter)
|
||||
handler.setLevel(logging.INFO)
|
||||
log.addHandler(handler)
|
||||
break
|
||||
|
||||
if not handler:
|
||||
log.warning('No syslog socket found, will not log to syslog')
|
||||
|
||||
sys.exit(main())
|
||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ try:
|
||||
except ImportError:
|
||||
from distutils import setup
|
||||
|
||||
version = '0.3.1'
|
||||
version = '0.3.4'
|
||||
|
||||
setup(
|
||||
name='zsnapper',
|
||||
|
@ -37,7 +37,7 @@ def do_zfs_command(args, zfs_cmd, pipecmd=None):
|
||||
# check if we try to create a snapshot that already exists. This can happen
|
||||
# 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):
|
||||
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))
|
||||
@ -83,7 +83,7 @@ def get_filesystems(zfs_cmd):
|
||||
|
||||
for row in out.splitlines():
|
||||
row = row.decode('UTF-8')
|
||||
ret.add(row.split()[0])
|
||||
ret.add(row.split('\t')[0])
|
||||
return ret
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ def get_snapshots(zfs_cmd):
|
||||
snapshots = {}
|
||||
|
||||
for row in out.splitlines():
|
||||
row = row.decode('UTF-8').split()[0]
|
||||
row = row.decode('UTF-8').split('\t')[0]
|
||||
res = re_snapshot.match(row)
|
||||
if res:
|
||||
d = datetime.datetime.strptime(res.group(2), time_format)
|
||||
|
Loading…
Reference in New Issue
Block a user