Testing log directory backup
authorAdam Chlipala <adamc@hcoop.net>
Sat, 17 Nov 2007 16:48:41 +0000 (16:48 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sat, 17 Nov 2007 16:48:41 +0000 (16:48 +0000)
configDefault/apache.cfg
configDefault/apache.csg
src/plugins/apache.sml
src/slave.sig
src/slave.sml

index d7f90c3..7f6648a 100644 (file)
@@ -37,4 +37,10 @@ fun logDirOf version1 user =
                       user,
                       "/apache/log"]
 
+fun backupLogDirOf version1 =
+    if version1 then
+       "/afs/hcoop.net/common/etc/domtool/backup/apache/"
+    else
+       "/afs/hcoop.net/common/etc/domtool/backup/apache2/"
+
 end
index cd0fbb7..6e20dbd 100644 (file)
@@ -19,5 +19,6 @@ signature APACHE_CONFIG = sig
     val        public_html : string
 
     val logDirOf : bool -> string -> string
+    val backupLogDirOf : bool -> string
 
 end
index be0e4f2..1f0fe83 100644 (file)
@@ -275,17 +275,21 @@ val () = Slave.registerFileHandler (fn fs =>
                                                           vhostsChanged := true;
                                                           case #action fs of
                                                               Slave.Delete =>
-                                                              (if !logDeleted then
-                                                                   ()
-                                                               else
-                                                                   (ignore (OS.Process.system (down ()));
-                                                                    logDeleted := true);
-                                                               ignore (OS.Process.system (Config.rm
-                                                                                          ^ " -rf "
-                                                                                          ^ realVhostFile));
-                                                               ignore (OS.Process.system (Config.rm
-                                                                                          ^ " -rf "
-                                                                                          ^ realLogDir oldUser)))
+                                                              let
+                                                                  val ldir = realLogDir oldUser
+                                                              in
+                                                                  if !logDeleted then
+                                                                      ()
+                                                                  else
+                                                                      (ignore (OS.Process.system (down ()));
+                                                                       logDeleted := true);
+                                                                  ignore (OS.Process.system (Config.rm
+                                                                                             ^ " -rf "
+                                                                                             ^ realVhostFile));
+                                                                  Slave.moveDirCreate {from = ldir,
+                                                                                       to = Config.Apache.backupLogDirOf
+                                                                                                (isVersion1 (Slave.hostname ()))}
+                                                              end
                                                             | Slave.Add =>
                                                               let
                                                                   val rld = realLogDir user
@@ -298,7 +302,9 @@ val () = Slave.registerFileHandler (fn fs =>
                                                                   if Posix.FileSys.access (rld, []) then
                                                                       ()
                                                                   else
-                                                                      Slave.mkDirAll rld
+                                                                      Slave.moveDirCreate {from = Config.Apache.backupLogDirOf
+                                                                                                      (isVersion1 (Slave.hostname ())),
+                                                                                           to = rld}
                                                               end
                                                               
                                                             | _ =>
index 1a11e51..86c64fd 100644 (file)
@@ -73,4 +73,7 @@ signature SLAVE = sig
 
     val remove : ''a list * ''a -> ''a list
     val removeDups : ''a list -> ''a list
+
+    val copyDirCreate : { from : string, to : string } -> unit
+    val moveDirCreate : { from : string, to : string } -> unit
 end
index a20f6db..7a507fa 100644 (file)
@@ -209,4 +209,18 @@ fun removeDups ls = List.foldr (fn (x, ls) =>
                                   else
                                       x :: ls) [] ls
 
+fun copyDirCreate {from, to} =
+    (mkDirAll to;
+     if Posix.FileSys.access (from, []) then
+        ignore (OS.Process.system ("cp -r " ^ from ^ " " ^ to))
+     else
+        ())
+
+fun moveDirCreate {from, to} =
+    (mkDirAll to;
+     if Posix.FileSys.access (from, []) then
+        ignore (OS.Process.system ("mv " ^ from ^ " " ^ to))
+     else
+        ())
+
 end