Author: frm
Date: Fri Feb  2 10:54:31 2018
New Revision: 1822943

URL: http://svn.apache.org/viewvc?rev=1822943&view=rev
Log:
OAK-7237 - Let the bakcup and restore commands properly propagate errors

The backup and restore commands should always return with a non-zero return
code in case of error. Moreover, error messages and stack traces should always
be printed on the standard error.

Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RestoreCommand.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Backup.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Restore.java

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java?rev=1822943&r1=1822942&r2=1822943&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java
 Fri Feb  2 10:54:31 2018
@@ -39,11 +39,12 @@ class BackupCommand implements Command {
         File source = new File(options.nonOptionArguments().get(0).toString());
         File target = new File(options.nonOptionArguments().get(1).toString());
 
-        Backup.builder()
-                .withSource(source)
-                .withTarget(target)
-                .build()
-                .run();
+        int statusCode = Backup.builder()
+            .withSource(source)
+            .withTarget(target)
+            .build()
+            .run();
+        System.exit(statusCode);
     }
 
 }
\ No newline at end of file

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RestoreCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RestoreCommand.java?rev=1822943&r1=1822942&r2=1822943&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RestoreCommand.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/RestoreCommand.java
 Fri Feb  2 10:54:31 2018
@@ -39,11 +39,12 @@ class RestoreCommand implements Command
         File target = new File(options.nonOptionArguments().get(0).toString());
         File source = new File(options.nonOptionArguments().get(1).toString());
 
-        Restore.builder()
-                .withSource(source)
-                .withTarget(target)
-                .build()
-                .run();
+        int statusCode = Restore.builder()
+            .withSource(source)
+            .withTarget(target)
+            .build()
+            .run();
+        System.exit(statusCode);
     }
 
 }
\ No newline at end of file

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Backup.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Backup.java?rev=1822943&r1=1822942&r2=1822943&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Backup.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Backup.java
 Fri Feb  2 10:54:31 2018
@@ -32,7 +32,7 @@ import org.apache.jackrabbit.oak.segment
 /**
  * Perform a backup of a segment store into a specified folder.
  */
-public class Backup implements Runnable {
+public class Backup {
 
     /**
      * Create a builder for the {@link Backup} command.
@@ -103,7 +103,7 @@ public class Backup implements Runnable
          *
          * @return an instance of {@link Runnable}.
          */
-        public Runnable build() {
+        public Backup build() {
             checkNotNull(source);
             checkNotNull(target);
             return new Backup(this);
@@ -126,12 +126,13 @@ public class Backup implements Runnable
         this.fileStoreBackup = builder.fileStoreBackup;
     }
 
-    @Override
-    public void run() {
+    public int run() {
         try (ReadOnlyFileStore fs = newFileStore()) {
             fileStoreBackup.backup(fs.getReader(), fs.getRevisions(), target);
+            return 0;
         } catch (Exception e) {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
+            return 1;
         }
     }
 

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Restore.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Restore.java?rev=1822943&r1=1822942&r2=1822943&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Restore.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Restore.java
 Fri Feb  2 10:54:31 2018
@@ -27,7 +27,7 @@ import org.apache.jackrabbit.oak.backup.
 /**
  * Restore a backup of a segment store into an existing segment store.
  */
-public class Restore implements Runnable {
+public class Restore {
 
     /**
      * Create a builder for the {@link Restore} command.
@@ -80,7 +80,7 @@ public class Restore implements Runnable
          *
          * @return an instance of {@link Runnable}.
          */
-        public Runnable build() {
+        public Restore build() {
             checkNotNull(source);
             checkNotNull(target);
             return new Restore(this);
@@ -100,12 +100,13 @@ public class Restore implements Runnable
         this.fileStoreRestore = builder.fileStoreRestore;
     }
 
-    @Override
-    public void run() {
+    public int run() {
         try {
             fileStoreRestore.restore(source, target);
+            return 0;
         } catch (Exception e) {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
+            return 1;
         }
     }
 


Reply via email to