X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fbackup%2FAbstractAtomicBackup.java;fp=org.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fbackup%2FAbstractAtomicBackup.java;h=0000000000000000000000000000000000000000;hb=79bc665d4b1eeccb7416279750bc60a138c81988;hp=53972e503a29531d9030bfe0e1fe149b89f386f0;hpb=f00611ca313420ab96d44889577b46f31c2dcb35;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.server.core/src/main/java/org/argeo/server/backup/AbstractAtomicBackup.java b/org.argeo.server.core/src/main/java/org/argeo/server/backup/AbstractAtomicBackup.java deleted file mode 100644 index 53972e503..000000000 --- a/org.argeo.server.core/src/main/java/org/argeo/server/backup/AbstractAtomicBackup.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 org.apache.commons.vfs.FileObject; -import org.apache.commons.vfs.FileSystemManager; -import org.apache.commons.vfs.FileSystemOptions; -import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder; -import org.argeo.ArgeoException; - -/** - * Simplify atomic backups implementation, especially by managing VFS. - */ -public abstract class AbstractAtomicBackup implements AtomicBackup { - private String name; - private String compression = "bz2"; - - protected abstract void writeBackup(FileObject targetFo); - - public AbstractAtomicBackup() { - } - - public AbstractAtomicBackup(String name) { - this.name = name; - } - - public void init() { - if (name == null) - throw new ArgeoException("Atomic backup name must be set"); - } - - public void destroy() { - - } - - @Override - public String backup(FileSystemManager fileSystemManager, - String backupsBase, BackupContext backupContext, - FileSystemOptions opts) { - if (name == null) - throw new ArgeoException("Atomic backup name must be set"); - - FileObject targetFo = null; - try { - if (backupsBase.startsWith("sftp:")) - SftpFileSystemConfigBuilder.getInstance() - .setStrictHostKeyChecking(opts, "no"); - if (compression == null || compression.equals("none")) - targetFo = fileSystemManager.resolveFile(backupsBase + '/' - + backupContext.getRelativeFolder() + '/' + name, opts); - else if (compression.equals("bz2")) - targetFo = fileSystemManager.resolveFile("bz2:" + backupsBase - + '/' + backupContext.getRelativeFolder() + '/' + name - + ".bz2" + "!" + name, opts); - else if (compression.equals("gz")) - targetFo = fileSystemManager.resolveFile("gz:" + backupsBase - + '/' + backupContext.getRelativeFolder() + '/' + name - + ".gz" + "!" + name, opts); - else - throw new ArgeoException("Unsupported compression " - + compression); - - writeBackup(targetFo); - - return targetFo.toString(); - } catch (Exception e) { - throw new ArgeoException("Cannot backup " + name + " to " - + targetFo, e); - } finally { - BackupUtils.closeFOQuietly(targetFo); - } - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setCompression(String compression) { - this.compression = compression; - } -}