mirror of
https://github.com/znc/znc.git
synced 2026-04-30 10:34:16 +02:00
Backup znc.conf when upgrading ZNC.
Now ZNC saves its version to znc.conf. When ZNC tries to load znc.conf, it compares stored version with running one. If the stored version is older, make a backup.
This commit is contained in:
1
User.cpp
1
User.cpp
@@ -338,7 +338,6 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
|
||||
}
|
||||
|
||||
if (pNetwork) {
|
||||
CZNC::Get().BackupConfigOnce();
|
||||
CUtils::PrintMessage("NOTICE: Found deprecated config, upgrading to a network");
|
||||
|
||||
if (!pNetwork->ParseConfig(pConfig, sError, true)) {
|
||||
|
||||
17
znc.cpp
17
znc.cpp
@@ -433,6 +433,7 @@ bool CZNC::WriteConfig() {
|
||||
config.AddKeyValuePair("MaxBufferSize", CString(m_uiMaxBufferSize));
|
||||
config.AddKeyValuePair("SSLCertFile", CString(m_sSSLCertFile));
|
||||
config.AddKeyValuePair("ProtectWebSessions", CString(m_bProtectWebSessions));
|
||||
config.AddKeyValuePair("Version", CString(VERSION, 3));
|
||||
|
||||
for (size_t l = 0; l < m_vpListeners.size(); l++) {
|
||||
CListener* pListener = m_vpListeners[l];
|
||||
@@ -984,8 +985,7 @@ size_t CZNC::FilterUncommonModules(set<CModInfo>& ssModules) {
|
||||
return uNrRemoved;
|
||||
}
|
||||
|
||||
void CZNC::BackupConfigOnce()
|
||||
{
|
||||
void CZNC::BackupConfigOnce(const CString& sSuffix) {
|
||||
static bool didBackup = false;
|
||||
if (didBackup)
|
||||
return;
|
||||
@@ -993,7 +993,7 @@ void CZNC::BackupConfigOnce()
|
||||
|
||||
CUtils::PrintAction("Creating a config backup");
|
||||
|
||||
CString sBackup = CDir::ChangeDir(m_sConfigFile, "../znc.conf.backup");
|
||||
CString sBackup = CDir::ChangeDir(m_sConfigFile, "../znc.conf." + sSuffix);
|
||||
if (CFile::Copy(m_sConfigFile, sBackup))
|
||||
CUtils::PrintStatus(true, sBackup);
|
||||
else
|
||||
@@ -1085,6 +1085,17 @@ bool CZNC::DoRehash(CString& sError)
|
||||
}
|
||||
CUtils::PrintStatus(true);
|
||||
|
||||
CString sSavedVersion;
|
||||
config.FindStringEntry("version", sSavedVersion);
|
||||
double fSavedVersion = sSavedVersion.ToDouble();
|
||||
if (fSavedVersion < VERSION) {
|
||||
if (sSavedVersion.empty()) {
|
||||
sSavedVersion = "< 0.203";
|
||||
}
|
||||
CUtils::PrintMessage("Found old config from ZNC " + sSavedVersion + ". Saving a backup of it.");
|
||||
BackupConfigOnce("pre-" + CString(VERSION, 3));
|
||||
}
|
||||
|
||||
m_vsBindHosts.clear();
|
||||
m_vsMotd.clear();
|
||||
|
||||
|
||||
2
znc.h
2
znc.h
@@ -51,7 +51,7 @@ public:
|
||||
bool WriteConfig();
|
||||
bool ParseConfig(const CString& sConfig);
|
||||
bool RehashConfig(CString& sError);
|
||||
void BackupConfigOnce();
|
||||
void BackupConfigOnce(const CString& sSuffix);
|
||||
static CString GetVersion();
|
||||
static CString GetTag(bool bIncludeVersion = true);
|
||||
CString GetUptime() const;
|
||||
|
||||
Reference in New Issue
Block a user