summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2010-04-10 22:58:42 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2010-04-10 22:58:42 +0000
commitc424dce517be537bd154565bca5e3a87ddb8c406 (patch)
tree245d3631e108f46a7347bec53dedec273f8d3f40 /src
parent91f6b2e29d8fb354e6c93b987d99488f6bb69235 (diff)
Made db_plain backup its databases
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2882 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/core/db_plain.cpp47
-rw-r--r--src/log.c4
2 files changed, 47 insertions, 4 deletions
diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp
index ca10a3a03..d461fd282 100644
--- a/src/core/db_plain.cpp
+++ b/src/core/db_plain.cpp
@@ -514,6 +514,10 @@ void WriteMetadata(const std::string &key, const std::string &data)
class DBPlain : public Module
{
+ /* Day the last backup was on */
+ int LastDay;
+ /* Backup file names */
+ std::list<std::string> Backups;
public:
DBPlain(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
@@ -525,6 +529,47 @@ class DBPlain : public Module
ModuleManager::Attach(i, this, 6);
OnReload(true);
+
+ LastDay = 0;
+ }
+
+ ~DBPlain()
+ {
+ }
+
+ void BackupDatabase()
+ {
+ time_t now = time(NULL);
+ tm *tm = localtime(&now);
+
+ if (tm->tm_mday != LastDay)
+ {
+ LastDay = tm->tm_mday;
+ char *newname = new char[DatabaseFile.length() + 30];
+ snprintf(newname, DatabaseFile.length() + 30, "backups/%s.%d%d%d", DatabaseFile.c_str(), tm->tm_year, tm->tm_mon, tm->tm_mday);
+
+ if (rename(DatabaseFile.c_str(), newname) != 0)
+ {
+ ircdproto->SendGlobops(findbot(Config.s_OperServ), "Unable to backup database!");
+ Alog() << "Unable to back up database!";
+
+ if (!Config.NoBackupOkay)
+ quitting = 1;
+
+ return;
+ }
+
+ Backups.push_back(newname);
+
+ delete [] newname;
+
+ unsigned KeepBackups = Config.KeepBackups;
+ if (KeepBackups && Backups.size() > KeepBackups)
+ {
+ DeleteFile(Backups.front().c_str());
+ Backups.pop_front();
+ }
+ }
}
void OnReload(bool)
@@ -842,6 +887,8 @@ class DBPlain : public Module
EventReturn OnSaveDatabase()
{
+ BackupDatabase();
+
db.open(DatabaseFile.c_str(), std::ios_base::out | std::ios_base::trunc);
if (!db.is_open())
diff --git a/src/log.c b/src/log.c
index 41472e7ad..00094079f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -58,11 +58,7 @@ static void remove_log()
/* removed if from here cause get_logchan is always 1 */
get_logname(name, sizeof(name), &tm);
-#ifndef _WIN32
- unlink(name);
-#else
DeleteFile(name);
-#endif
}
/*************************************************************************/