]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird.c
Tweak example SD plugin.
[bacula/bacula] / bacula / src / dird / dird.c
index 6eff0089d8548de9f73802bdb5be0315527527f5..9f1667fc2c15867210b29f6aa65eefd67b50f7a3 100644 (file)
@@ -53,6 +53,7 @@ extern int job_setattr(PyObject *self, char *attrname, PyObject *value);
 void terminate_dird(int sig);
 static bool check_resources();
 static void dir_sql_query(JCR *jcr, const char *cmd);
+static void cleanup_old_files();
   
 /* Exported subroutines */
 extern "C" void reload_config(int sig);
@@ -282,6 +283,8 @@ int main (int argc, char *argv[])
 
    drop(uid, gid, false);                    /* reduce privileges if requested */
 
+   cleanup_old_files();
+
    /* If we are in testing mode, we don't try to fix the catalog */
    cat_op mode=(test_config)?CHECK_CONNECTION:UPDATE_AND_FIX;
 
@@ -1120,3 +1123,32 @@ static bool check_catalog(cat_op mode)
    }
    return OK;
 }
+
+static void copy_base_name(POOLMEM *cleanup)
+{
+   int len = strlen(director->working_directory);
+#if defined(HAVE_WIN32)
+   pm_strcpy(cleanup, "del /q ");
+#else
+   pm_strcpy(cleanup, "/bin/rm -f ");
+#endif
+   pm_strcat(cleanup, director->working_directory);
+   if (len > 0 && !IsPathSeparator(director->working_directory[len-1])) {
+      pm_strcat(cleanup, "/");
+   }
+   pm_strcat(cleanup, my_name);
+}
+
+static void cleanup_old_files()
+{
+   POOLMEM *cleanup = get_pool_memory(PM_MESSAGE);
+   POOLMEM *results = get_pool_memory(PM_MESSAGE);
+   copy_base_name(cleanup);
+   pm_strcat(cleanup, "*.restore.*.bsr");
+   run_program(cleanup, 0, results);
+   copy_base_name(cleanup);
+   pm_strcat(cleanup, "*.mail");
+   run_program(cleanup, 0, results);
+   free_pool_memory(cleanup);
+   free_pool_memory(results);
+}