|
@@ -8,6 +8,7 @@ import sys
|
|
|
import time
|
|
|
import yaml
|
|
|
|
|
|
+from datetime import datetime
|
|
|
from glob import glob
|
|
|
from slugify import slugify
|
|
|
|
|
@@ -185,7 +186,7 @@ class Job(object):
|
|
|
if not os.path.exists(path):
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
|
|
- self._logfile = open(self.logpath, 'w')
|
|
|
+ self._logfile = open(self.logpath, 'w' if Backup.truncateLogs else 'a')
|
|
|
|
|
|
return self._logfile
|
|
|
|
|
@@ -265,8 +266,8 @@ class Job(object):
|
|
|
return self._post
|
|
|
|
|
|
def log(self, text):
|
|
|
- text = '[Backup {0} Job #{1}] {2}\n'.format(
|
|
|
- self._backup.name, self.index, text)
|
|
|
+ text = '[{0}] (Backup {1} Job #{2}) {3}\n'.format(
|
|
|
+ datetime.now().isoformat(), self._backup.name, self.index, text)
|
|
|
print(text, end='')
|
|
|
self._backup.logfile.write(text)
|
|
|
self._backup.logfile.flush()
|
|
@@ -291,7 +292,10 @@ class Job(object):
|
|
|
raise StateException('Invalid state to start {}'.format(self))
|
|
|
|
|
|
args = self.args
|
|
|
- self.logfile.write(' '.join([shlex.quote(x) for x in args]) + '\n')
|
|
|
+ self.logfile.write(
|
|
|
+ "[{0}] {1} &\n".format(
|
|
|
+ datetime.now().isoformat(),
|
|
|
+ ' '.join([shlex.quote(x) for x in args])))
|
|
|
self.logfile.flush()
|
|
|
self._process = subprocess.Popen(
|
|
|
args, stdout=self.logfile, stderr=subprocess.STDOUT,
|
|
@@ -321,6 +325,7 @@ class Backup(object):
|
|
|
instances = {}
|
|
|
_queue = []
|
|
|
logTransitions = False
|
|
|
+ truncateLogs = True
|
|
|
engine = 'rdiff-backup'
|
|
|
logdir = '/var/log/backup.d'
|
|
|
BLOCKED = 0
|
|
@@ -416,12 +421,13 @@ class Backup(object):
|
|
|
if not os.path.exists(path):
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
|
|
- self._logfile = open(self.logpath, 'w+')
|
|
|
+ self._logfile = open(self.logpath, 'w' if Backup.truncateLogs else 'a')
|
|
|
|
|
|
return self._logfile
|
|
|
|
|
|
def log(self, text):
|
|
|
- text = '[Backup {0}] {1}\n'.format(self.name, text)
|
|
|
+ text = '[{0}] (Backup {1}) {2}\n'.format(
|
|
|
+ datetime.now().isoformat(), self.name, text)
|
|
|
print(text, end='')
|
|
|
self.logfile.write(text)
|
|
|
self.logfile.flush()
|
|
@@ -596,6 +602,7 @@ def main(args):
|
|
|
Backup.verbosity = config()['verbosity']
|
|
|
|
|
|
Backup.logTransitions = Job.logTransitions = True
|
|
|
+ Backup.truncateLogs = "truncateLogs" in config() and config["truncateLogs"]
|
|
|
Backup.load(sources().keys())
|
|
|
Backup.start()
|
|
|
Backup.wait()
|