Improve logical backup.
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 27 Jan 2020 09:26:13 +0000 (10:26 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 27 Jan 2020 09:26:13 +0000 (10:26 +0100)
org.argeo.maintenance/bnd.bnd
org.argeo.maintenance/src/org/argeo/maintenance/backup/LogicalBackup.java
org.argeo.maintenance/src/org/argeo/maintenance/internal/Activator.java

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f0c70aa4586ae5afffb3cfce8226d9fca83bdc28 100644 (file)
@@ -0,0 +1 @@
+Bundle-Activator: org.argeo.maintenance.internal.Activator
index d1b31b3ecabb16b435524cc7313f6325ce0ff4b2..6d1016a06d0ec88865783e2b4b1cd4dcc1bee629 100644 (file)
@@ -37,7 +37,13 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.xml.sax.SAXException;
 
-public class LogicalBackup {
+/**
+ * Performs a backup of the data based only on programmatic interfaces. Useful
+ * for migration or live backup. Physical backups of the underlying file
+ * systems, databases, LDAP servers, etc. should be performed for disaster
+ * recovery.
+ */
+public class LogicalBackup implements Runnable {
        private final static Log log = LogFactory.getLog(LogicalBackup.class);
 
        public final static String WORKSPACES_BASE = "workspaces/";
@@ -48,13 +54,6 @@ public class LogicalBackup {
        private final ZipOutputStream zout;
        private final Path basePath;
 
-       public LogicalBackup(BundleContext bundleContext, Repository repository, ZipOutputStream zout) {
-               this.repository = repository;
-               this.zout = zout;
-               this.basePath = null;
-               this.bundleContext = bundleContext;
-       }
-
        public LogicalBackup(BundleContext bundleContext, Repository repository, Path basePath) {
                this.repository = repository;
                this.zout = null;
@@ -62,6 +61,25 @@ public class LogicalBackup {
                this.bundleContext = bundleContext;
        }
 
+//     public LogicalBackup(BundleContext bundleContext, Repository repository, ZipOutputStream zout) {
+//     this.repository = repository;
+//     this.zout = zout;
+//     this.basePath = null;
+//     this.bundleContext = bundleContext;
+//}
+
+       @Override
+       public void run() {
+               try {
+                       log.info("Start logical backup to " + basePath);
+                       perform();
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       throw new IllegalStateException("Logical backup failed", e);
+               }
+
+       }
+
        public void perform() throws RepositoryException, IOException {
                for (Bundle bundle : bundleContext.getBundles()) {
                        String relativePath = OSGI_BASE + "boot/" + bundle.getSymbolicName() + ".jar";
index 92534b25014761e70d587181783deaf02aaff0b5..ef40ab3a34e0c015a10540ad49bd7ac4c0ee4544 100644 (file)
@@ -13,15 +13,11 @@ public class Activator implements BundleActivator {
 
        @Override
        public void start(BundleContext context) throws Exception {
-               try {
-                       Repository repository = context.getService(context.getServiceReference(Repository.class));
-                       Path basePath = Paths.get(System.getProperty("user.dir"), "backup");
-                       LogicalBackup backup = new LogicalBackup(context, repository, basePath);
-                       backup.perform();
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-
+               // Start backup
+               Repository repository = context.getService(context.getServiceReference(Repository.class));
+               Path basePath = Paths.get(System.getProperty("user.dir"), "backup");
+               LogicalBackup backup = new LogicalBackup(context, repository, basePath);
+               backup.run();
        }
 
        @Override