1 package org
.argeo
.slc
.backup
.vfs
;
3 import org
.apache
.commons
.vfs2
.FileObject
;
4 import org
.apache
.commons
.vfs2
.FileSystemManager
;
5 import org
.apache
.commons
.vfs2
.FileSystemOptions
;
6 import org
.apache
.commons
.vfs2
.provider
.sftp
.SftpFileSystemConfigBuilder
;
9 * Simplify atomic backups implementation, especially by managing VFS.
11 public abstract class AbstractAtomicBackup
implements AtomicBackup
{
13 private String compression
= "bz2";
15 protected abstract void writeBackup(FileObject targetFo
);
17 public AbstractAtomicBackup() {
20 public AbstractAtomicBackup(String name
) {
26 throw new MaintenanceException("Atomic backup name must be set");
29 public void destroy() {
34 public String
backup(FileSystemManager fileSystemManager
,
35 String backupsBase
, BackupContext backupContext
,
36 FileSystemOptions opts
) {
38 throw new MaintenanceException("Atomic backup name must be set");
40 FileObject targetFo
= null;
42 if (backupsBase
.startsWith("sftp:"))
43 SftpFileSystemConfigBuilder
.getInstance()
44 .setStrictHostKeyChecking(opts
, "no");
45 if (compression
== null || compression
.equals("none"))
46 targetFo
= fileSystemManager
.resolveFile(backupsBase
+ '/'
47 + backupContext
.getRelativeFolder() + '/' + name
, opts
);
48 else if (compression
.equals("bz2"))
49 targetFo
= fileSystemManager
.resolveFile("bz2:" + backupsBase
50 + '/' + backupContext
.getRelativeFolder() + '/' + name
51 + ".bz2" + "!" + name
, opts
);
52 else if (compression
.equals("gz"))
53 targetFo
= fileSystemManager
.resolveFile("gz:" + backupsBase
54 + '/' + backupContext
.getRelativeFolder() + '/' + name
55 + ".gz" + "!" + name
, opts
);
57 throw new MaintenanceException("Unsupported compression "
60 writeBackup(targetFo
);
62 return targetFo
.toString();
63 } catch (Exception e
) {
64 throw new MaintenanceException("Cannot backup " + name
+ " to "
67 BackupUtils
.closeFOQuietly(targetFo
);
71 public void setName(String name
) {
75 public String
getName() {
79 public void setCompression(String compression
) {
80 this.compression
= compression
;