Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 57 lines (42 sloc) 1.33 KB
#!/usr/bin/env python
"""Invoke rrsync on a rotated dir maintained by rrotate.
"""
import os
import sys
from subprocess import call
LOGFILE = '/var/log/rrsync.log'
if os.path.exists(LOGFILE):
logfile = open(LOGFILE, 'a')
else:
logfile = sys.stderr
def main():
# look for the dir as 1st or 2nd argument
args = sys.argv[1:]
for i, arg in enumerate(args[:2]):
if not arg.startswith('-'):
dir = arg
break
else:
assert False
here = os.path.dirname(os.path.abspath(sys.argv[0]))
cmd = os.environ.get('SSH_ORIGINAL_COMMAND')
if not cmd:
print >>sys.stderr, "this script should run via ssh"
return 1
cmd = cmd.split()[0]
if cmd == 'rrlinks':
if 0 != call([os.path.join(here, 'rrlinks'), dir], stderr=logfile):
print >>sys.stderr, "error running rrlinks"
return 1
elif cmd == 'rsync':
if 0 != call([os.path.join(here, 'rrsync')] + args):
print >>sys.stderr, "error running rrsync"
return 1
elif cmd == 'rrrotate':
if 0 != call([os.path.join(here, 'rrrotate'), dir], stderr=logfile):
print >>sys.stderr, "error running rrrotate"
return 1
else:
print >>sys.stderr, "can't run this command:", cmd
if __name__ == '__main__':
sys.exit(main())