One may now choose where Zope log files lie in the backup script.

This commit is contained in:
Gaetan Delannay 2010-04-14 15:00:21 +02:00
parent e97782d05a
commit ae4bfc9970

View file

@ -78,9 +78,15 @@ class ZodbBackuper:
if os.path.exists(self.logsBackupFolder): if os.path.exists(self.logsBackupFolder):
# Ok, we can make the backup of the log files. # Ok, we can make the backup of the log files.
# Get the folder where logs lie # Get the folder where logs lie
logsFolder = self.options.logsFolder
d = os.path.dirname d = os.path.dirname
j = os.path.join j = os.path.join
if not logsFolder:
logsFolder = j(d(d(self.storageLocation)), 'log') logsFolder = j(d(d(self.storageLocation)), 'log')
if not os.path.isdir(logsFolder):
w('Cannot backup log files because folder "%s" does not ' \
'exist. Try using option "-g".' % logsFolder)
return
for logFileName in os.listdir(logsFolder): for logFileName in os.listdir(logsFolder):
if logFileName.endswith('.log'): if logFileName.endswith('.log'):
backupTime = DateTime().strftime('%Y_%m_%d_%H_%M') backupTime = DateTime().strftime('%Y_%m_%d_%H_%M')
@ -225,6 +231,9 @@ class ZodbBackupScript:
# Check backupFolder # Check backupFolder
if not os.path.isdir(args[1]): if not os.path.isdir(args[1]):
raise BackupError('"%s" does not exist or is not a folder.'%args[1]) raise BackupError('"%s" does not exist or is not a folder.'%args[1])
# Check logs folder
if options.logsFolder and not os.path.isdir(options.logsFolder):
raise BackupError('"%s" is not a folder.' % options.logsFolder)
# Try to create a file in this folder to check if we have write # Try to create a file in this folder to check if we have write
# access in it. # access in it.
fileName = '%s/%s.tmp' % (args[1], str(time.time())) fileName = '%s/%s.tmp' % (args[1], str(time.time()))
@ -290,11 +299,20 @@ class ZodbBackupScript:
help="Folder used by OO for producing temp " \ help="Folder used by OO for producing temp " \
"files. Defaults to /tmp.", "files. Defaults to /tmp.",
default='/tmp', metavar="TEMP", type='string') default='/tmp', metavar="TEMP", type='string')
optParser.add_option("-g", "--logsFolder",dest="logsFolder",
help="Folder where Zope log files are " \
"(typically: event.log and Z2.log). If no " \
"folder is provided, we will consider to " \
"work on a standard Zope instance and " \
"decide that the log folder is, from " \
"'storageLocation', located at ../log",
metavar="LOGSFOLDER", type='string')
optParser.add_option("-b", "--logsBackupFolder",dest="logsBackupFolder", optParser.add_option("-b", "--logsBackupFolder",dest="logsBackupFolder",
help="Folder where backups of log files " \ help="Folder where backups of log files " \
"(event.log and Z2.log) will be stored.", "(event.log and Z2.log) will be stored.",
default='./logsbackup', metavar="LOGSBACKUPFOLDER", default='./logsbackup', metavar="LOGSBACKUPFOLDER",
type='string') type='string')
optParser.add_option("-u", "--user", dest="zopeUser", optParser.add_option("-u", "--user", dest="zopeUser",
help="User and group that must own Data.fs. " \ help="User and group that must own Data.fs. " \
"Defaults to zope:www-data. If " \ "Defaults to zope:www-data. If " \
@ -330,9 +348,8 @@ class ZodbBackupScript:
backuper = ZodbBackuper(args[0], args[1], options) backuper = ZodbBackuper(args[0], args[1], options)
backuper.run() backuper.run()
except BackupError, be: except BackupError, be:
sys.stderr.write(str(be)) sys.stderr.write(str(be) + '\nRun the script without any ' \
sys.stderr.write('\n') 'argument for getting help.\n')
optParser.print_help()
sys.exit(ERROR_CODE) sys.exit(ERROR_CODE)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------