summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-11-16 23:12:16 +0000
committerChris Wilson <chris+github@qwirx.com>2014-11-16 23:12:16 +0000
commit521c70553125b6da53c65a60e36fcc18aec36565 (patch)
treedc41c006f1c4ac7f40f98be7f1ef318c13e5d15f
parent258e57eaecfe85356181706d70141a2563d22737 (diff)
Add option to truncate log file at start of every backup.
Prevents backup log files from becoming too large.
-rw-r--r--bin/bbackupd/BackupDaemon.cpp2
-rw-r--r--lib/common/Logging.cpp9
-rw-r--r--lib/common/Logging.h8
-rw-r--r--lib/server/Daemon.cpp3
-rw-r--r--lib/server/Daemon.h8
5 files changed, 24 insertions, 6 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 832ff314..79482e21 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -1690,6 +1690,8 @@ void BackupDaemon::CleanupVssBackupComponents()
void BackupDaemon::OnBackupStart()
{
+ ResetLogFile();
+
// Touch a file to record times in filesystem
TouchFileInWorkingDir("last_sync_start");
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp
index 97209104..ce8afcbb 100644
--- a/lib/common/Logging.cpp
+++ b/lib/common/Logging.cpp
@@ -565,7 +565,7 @@ bool HideSpecificExceptionGuard::IsHidden(int type, int subtype)
// --------------------------------------------------------------------------
std::string Logging::OptionParser::GetOptionString()
{
- return "PqQt:TUvVW:";
+ return "NPqQt:TUvVW:";
}
// --------------------------------------------------------------------------
@@ -583,6 +583,12 @@ int Logging::OptionParser::ProcessOption(signed int option)
{
switch(option)
{
+ case 'N':
+ {
+ mTruncateLogFile = true;
+ }
+ break;
+
case 'P':
{
Console::SetShowPID(true);
@@ -692,6 +698,7 @@ int Logging::OptionParser::ProcessOption(signed int option)
std::string Logging::OptionParser::GetUsageString()
{
return
+ " -N Truncate log file at startup and on backup start\n"
" -P Show process ID (PID) in console output\n"
" -q Run more quietly, reduce verbosity level by one, can repeat\n"
" -Q Run at minimum verbosity, log nothing to console and system\n"
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index ff557430..ce78413e 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -467,13 +467,15 @@ class Logging
Log::INFO
#endif
)
- : mCurrentLevel(InitialLevel)
+ : mCurrentLevel(InitialLevel),
+ mTruncateLogFile(false)
{ }
static std::string GetOptionString();
int ProcessOption(signed int option);
static std::string GetUsageString();
int mCurrentLevel; // need an int to do math with
+ bool mTruncateLogFile;
Log::Level GetCurrentLevel()
{
return (Log::Level) mCurrentLevel;
@@ -489,9 +491,9 @@ class FileLogger : public Logger
: mLogFile("") { /* do not call */ }
public:
- FileLogger(const std::string& rFileName, Log::Level Level)
+ FileLogger(const std::string& rFileName, Log::Level Level, bool append)
: Logger(Level),
- mLogFile(rFileName, O_WRONLY | O_CREAT | O_APPEND)
+ mLogFile(rFileName, O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC))
{ }
virtual bool Log(Log::Level Level, const std::string& rFile,
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp
index 346440fe..31a641e0 100644
--- a/lib/server/Daemon.cpp
+++ b/lib/server/Daemon.cpp
@@ -313,7 +313,8 @@ int Daemon::ProcessOptions(int argc, const char *argv[])
if (mLogFileLevel != Log::INVALID)
{
mapLogFileLogger.reset(
- new FileLogger(mLogFile, mLogFileLevel));
+ new FileLogger(mLogFile, mLogFileLevel,
+ !mLogLevel.mTruncateLogFile));
}
return 0;
diff --git a/lib/server/Daemon.h b/lib/server/Daemon.h
index 923053c6..d95ac0c8 100644
--- a/lib/server/Daemon.h
+++ b/lib/server/Daemon.h
@@ -85,7 +85,13 @@ protected:
bool IsSingleProcess() { return mSingleProcess; }
virtual std::string GetOptionString();
virtual int ProcessOption(signed int option);
-
+ void ResetLogFile()
+ {
+ mapLogFileLogger.reset(
+ new FileLogger(mLogFile, mLogFileLevel,
+ !mLogLevel.mTruncateLogFile));
+ }
+
private:
static void SignalHandler(int sigraised);
box_time_t GetConfigFileModifiedTime() const;