summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-15 11:57:37 +0200
committerSimon Rettberg2014-10-15 11:57:37 +0200
commit42a03358b7902e55bda4c70e9e88940245204a1d (patch)
tree7ce52c43b32a70fe5477eb474ad3e945c31d205b /src
parentAdd missing setStatusObject call (diff)
downloadtmlite-bwlp-42a03358b7902e55bda4c70e9e88940245204a1d.tar.gz
tmlite-bwlp-42a03358b7902e55bda4c70e9e88940245204a1d.tar.xz
tmlite-bwlp-42a03358b7902e55bda4c70e9e88940245204a1d.zip
New task: BackupRestore
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java b/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java
new file mode 100644
index 0000000..c2f20c6
--- /dev/null
+++ b/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java
@@ -0,0 +1,86 @@
+package org.openslx.taskmanager.tasks;
+
+import org.openslx.satserver.util.Constants;
+import org.openslx.taskmanager.api.SystemCommandTask;
+
+import com.google.gson.annotations.Expose;
+
+public class BackupRestore extends SystemCommandTask
+{
+ @Expose
+ private String mode;
+ @Expose
+ private String backupFile;
+
+ private Output status = new Output();
+
+ @Override
+ protected boolean initTask()
+ {
+ this.setStatusObject( this.status );
+ if ( mode == null ) {
+ status.addMessage( "Mode given." );
+ return false;
+ }
+ if ( !mode.equals( "backup" ) && !mode.equals( "restore" ) ) {
+ status.addMessage( "Invalid mode: " + mode );
+ return false;
+ }
+ if ( mode.equals( "restore" ) && backupFile == null ) {
+ status.addMessage( "No backup file given to restore!" );
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected String[] initCommandLine()
+ {
+ if ( backupFile == null )
+ backupFile = "ignored";
+ return new String[] {
+ "/usr/bin/sudo",
+ "-n",
+ "-u", "root", Constants.BASEDIR + "/scripts/system-" + mode,
+ backupFile
+ };
+ }
+
+ @Override
+ protected boolean processEnded( int exitCode )
+ {
+ return exitCode == 0 && ( mode.equals( "restore" ) || status.backupFile != null );
+ }
+
+ @Override
+ protected void processStdOut( String line )
+ {
+ if ( line.startsWith( "Location: " ) ) {
+ status.backupFile = line.substring( 10 );
+ } else {
+ status.addMessage( line );
+ }
+ }
+
+ @Override
+ protected void processStdErr( String line )
+ {
+ status.addMessage( line );
+ }
+
+ class Output
+ {
+ private String messages = null;
+ public String backupFile = null;
+
+ private void addMessage( String str )
+ {
+ if ( messages == null ) {
+ messages = str;
+ } else {
+ messages += "\n" + str;
+ }
+ }
+ }
+
+}