X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fbackup%2FOsCallBackup.java;h=816157cfd4a2be750eb7dc0db7f2292afd60cf08;hb=2e8d5eea45604d0f4686d54986be1ce6307aefdb;hp=989c29a6872ddebda58f78fd307ff0459aac89a2;hpb=a49ea54cef01bfd8b57aa235e3d69ae5ed243147;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/OsCallBackup.java b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/OsCallBackup.java index 989c29a68..816157cfd 100644 --- a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/OsCallBackup.java +++ b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/OsCallBackup.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.server.backup; import java.io.ByteArrayOutputStream; @@ -28,6 +43,11 @@ public class OsCallBackup extends AbstractAtomicBackup { private Map variables = new HashMap(); private Executor executor = new DefaultExecutor(); + private Map environment = new HashMap(); + + /** Name of the sudo user, root if "", not sudo if null */ + private String sudo = null; + public OsCallBackup() { } @@ -42,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()); @@ -54,7 +84,7 @@ public class OsCallBackup extends AbstractAtomicBackup { ExecuteStreamHandler streamHandler = new PumpStreamHandler( targetContent.getOutputStream(), errBos); executor.setStreamHandler(streamHandler); - executor.execute(commandLine); + executor.execute(commandLine, environment); } catch (ExecuteException e) { byte[] err = errBos.toByteArray(); String errStr = new String(err); @@ -78,6 +108,14 @@ public class OsCallBackup extends AbstractAtomicBackup { return command; } + /** + * A reference to the environment variables that will be passed to the + * process. Empty by default. + */ + protected Map getEnvironment() { + return environment; + } + protected Map getVariables() { return variables; } @@ -90,4 +128,8 @@ public class OsCallBackup extends AbstractAtomicBackup { this.executor = executor; } + public void setSudo(String sudo) { + this.sudo = sudo; + } + }