Add configurable sudo for OS call backups
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 6 Nov 2013 13:34:17 +0000 (13:34 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 6 Nov 2013 13:34:17 +0000 (13:34 +0000)
https://www.argeo.org/bugzilla/show_bug.cgi?id=192

git-svn-id: https://svn.argeo.org/commons/trunk@6591 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/OsCallBackup.java

index 89071b18a8f594ac13c88cb5e51c8fc8c5989139..816157cfd4a2be750eb7dc0db7f2292afd60cf08 100644 (file)
@@ -45,6 +45,9 @@ public class OsCallBackup extends AbstractAtomicBackup {
 
        private Map<String, String> environment = new HashMap<String, String>();
 
+       /** Name of the sudo user, root if "", not sudo if null */
+       private String sudo = null;
+
        public OsCallBackup() {
        }
 
@@ -59,7 +62,17 @@ public class OsCallBackup extends AbstractAtomicBackup {
 
        @Override
        public void writeBackup(FileObject targetFo) {
-               CommandLine commandLine = CommandLine.parse(command, variables);
+               String commandToUse = command;
+
+               // sudo
+               if (sudo != null) {
+                       if (sudo.equals(""))
+                               commandToUse = "sudo " + commandToUse;
+                       else
+                               commandToUse = "sudo -u " + sudo + " " + commandToUse;
+               }
+
+               CommandLine commandLine = CommandLine.parse(commandToUse, variables);
                ByteArrayOutputStream errBos = new ByteArrayOutputStream();
                if (log.isTraceEnabled())
                        log.trace(commandLine.toString());
@@ -115,4 +128,8 @@ public class OsCallBackup extends AbstractAtomicBackup {
                this.executor = executor;
        }
 
+       public void setSudo(String sudo) {
+               this.sudo = sudo;
+       }
+
 }