summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes1
-rw-r--r--include/extern.h2
-rw-r--r--src/datafiles.c60
-rw-r--r--src/modules/hs_request.c16
-rw-r--r--src/modules/os_info.c15
-rw-r--r--version.log6
6 files changed, 99 insertions, 1 deletions
diff --git a/Changes b/Changes
index 5ee0c2712..6873f981a 100644
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@ Anope Version S V N
Provided by Anope Dev. <dev@anope.org> - 2006
09/10 A Added SASET AUTOOP to NickServ to match SET AUTOOP. [#588]
09/11 A Added detection in install.js for the latest PlatformSDK. [#596]
+09/29 A Ability for modules to backup their databases. [#604]
08/09 F Fixed port checking when using command line switches. [#575]
08/14 F Fixed db_mysql_query for better robustness. [#585]
08/27 F Fixed mod_current_module being incorrect resulting in segfault. [#593]
diff --git a/include/extern.h b/include/extern.h
index 5e2940c99..3f5da4853 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -853,6 +853,8 @@ E void modules_core_init(int number, char **list);
E void modules_unload_all(boolean fini, boolean unload_proto); /* Read warnings near function source */
E void moduleCallBackRun(void);
E void moduleCleanStruct(ModuleData **moduleData);
+E void ModuleDatabaseBackup(char *dbname);
+E void ModuleRemoveBackups(char *dbname);
/**** news.c ****/
diff --git a/src/datafiles.c b/src/datafiles.c
index 117f2c32e..60434a28f 100644
--- a/src/datafiles.c
+++ b/src/datafiles.c
@@ -711,3 +711,63 @@ void backup_databases(void)
send_event(EVENT_DB_BACKUP, 1, EVENT_STOP);
}
}
+
+/*************************************************************************/
+
+void ModuleDatabaseBackup(char *dbname)
+{
+
+ time_t t;
+ struct tm tm;
+
+ if (!KeepBackups) {
+ return;
+ }
+
+ time(&t);
+ tm = *localtime(&t);
+
+ if (!curday) {
+ curday = tm.tm_yday;
+ return;
+ }
+
+ if (curday != tm.tm_yday) {
+
+ char ext[9];
+
+ if (debug) {
+ alog("Module Database Backing up %s", dbname);
+ }
+ ModuleRemoveBackups(dbname);
+ curday = tm.tm_yday;
+ strftime(ext, sizeof(ext), "%Y%m%d", &tm);
+ rename_database(dbname, ext);
+ }
+}
+
+/*************************************************************************/
+
+void ModuleRemoveBackups(char *dbname)
+{
+ char ext[9];
+ char path[PATH_MAX];
+
+ time_t t;
+ struct tm tm;
+
+ time(&t);
+ t -= (60 * 60 * 24 * KeepBackups);
+ tm = *localtime(&t);
+ strftime(ext, sizeof(ext), "%Y%m%d", &tm);
+
+ snprintf(path, sizeof(path), "backups/%s.%s", dbname, ext);
+#ifndef _WIN32
+ unlink(path);
+#else
+ DeleteFile(path);
+#endif
+}
+
+/*************************************************************************/
+
diff --git a/src/modules/hs_request.c b/src/modules/hs_request.c
index 0494a08c9..38ec0e04d 100644
--- a/src/modules/hs_request.c
+++ b/src/modules/hs_request.c
@@ -76,6 +76,7 @@ int ns_do_drop(User * u);
void hsreq_save_db(void);
void hsreq_load_db(void);
int hsreqevt_db_saving(int argc, char **argv);
+int hsreqevt_db_backup(int argc, char **argv);
void my_load_config(void);
void my_add_languages(void);
@@ -117,6 +118,9 @@ int AnopeInit(int argc, char **argv)
hook = createEventHook(EVENT_DB_SAVING, hsreqevt_db_saving);
moduleAddEventHook(hook);
+ hook = createEventHook(EVENT_DB_BACKUP, hsreqevt_db_backup);
+ moduleAddEventHook(hook);
+
moduleSetHostHelp(hs_help);
moduleAddAuthor(AUTHOR);
moduleAddVersion(VERSION);
@@ -680,6 +684,18 @@ int hsreqevt_db_saving(int argc, char **argv)
return MOD_CONT;
}
+int hsreqevt_db_backup(int argc, char **argv)
+{
+ if ((argc >= 1) && (stricmp(argv[0], EVENT_START) == 0)) {
+ if (HSRequestDBName)
+ ModuleDatabaseBackup(HSRequestDBName);
+ else
+ ModuleDatabaseBackup(HSREQ_DEFAULT_DBNAME);
+ }
+
+ return MOD_CONT;
+}
+
void my_load_config(void)
{
int i;
diff --git a/src/modules/os_info.c b/src/modules/os_info.c
index e1af20d8c..9f2d3aa05 100644
--- a/src/modules/os_info.c
+++ b/src/modules/os_info.c
@@ -55,6 +55,7 @@ void m_AddLanguages(void);
int mLoadData(void);
int mSaveData(int argc, char **argv);
+int mBackupData(int argc, char **argv);
int mLoadConfig();
int mEventReload(int argc, char **argv);
@@ -99,6 +100,9 @@ int AnopeInit(int argc, char **argv)
hook = createEventHook(EVENT_DB_SAVING, mSaveData);
status = moduleAddEventHook(hook);
+ hook = createEventHook(EVENT_DB_BACKUP, mBackupData);
+ status = moduleAddEventHook(hook);
+
hook = createEventHook(EVENT_RELOAD, mEventReload);
status = moduleAddEventHook(hook);
@@ -450,6 +454,17 @@ int mSaveData(int argc, char **argv)
}
/**
+ * Backup our databases using the commands provided by Anope
+ * @return MOD_CONT
+ **/
+int mBackupData(int argc, char **argv)
+{
+ ModuleDatabaseBackup(OSInfoDBName);
+
+ return MOD_CONT;
+}
+
+/**
* Load the configuration directives from Services configuration file.
* @return 0 for success
**/
diff --git a/version.log b/version.log
index 470cd7e0f..cf6e22336 100644
--- a/version.log
+++ b/version.log
@@ -9,10 +9,14 @@ VERSION_MAJOR="1"
VERSION_MINOR="7"
VERSION_PATCH="15"
VERSION_EXTRA="-svn"
-VERSION_BUILD="1161"
+VERSION_BUILD="1162"
# $Log$
#
+# BUILD : 1.7.15 (1162)
+# BUGS : 604
+# NOTES : Added functions to let modules backup their own databases and added this functionality to the bundled modules
+#
# BUILD : 1.7.15 (1161)
# BUGS : 606
# NOTES : Fixed Makefile.win32 to fix a typo and `nmake clean` (it now uses spotless)