diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java b/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java index 32a5beb..7c05b91 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java +++ b/src/main/java/org/openslx/taskmanager/tasks/BackupRestore.java @@ -1,7 +1,9 @@ package org.openslx.taskmanager.tasks; +import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.openslx.satserver.util.Constants; @@ -19,6 +21,10 @@ public class BackupRestore extends SystemCommandTask private boolean restoreOpenslx; @Expose private boolean restoreDozmod; + @Expose + private String password; + @Expose + private String destination; private Output status = new Output(); @@ -29,15 +35,15 @@ public class BackupRestore extends SystemCommandTask { this.setStatusObject( this.status ); if ( mode == null ) { - status.addMessage( "Mode given." ); + status.addMessage( "No mode given." ); return false; } - if ( !mode.equals( "backup" ) && !mode.equals( "restore" ) ) { + if ( !mode.equals( "backup" ) && !mode.equals( "restore" ) && !mode.equals( "test" ) ) { status.addMessage( "Invalid mode: " + mode ); return false; } - if ( mode.equals( "restore" ) && backupFile == null ) { - status.addMessage( "No backup file given to restore!" ); + if ( backupFile == null && ( mode.equals( "restore" ) || mode.equals( "test" ) ) ) { + status.addMessage( "No backup file given to restore/test!" ); return false; } this.timeoutSeconds = 180; @@ -56,8 +62,9 @@ public class BackupRestore extends SystemCommandTask args.add( "-n" ); args.add( "-u" ); args.add( "root" ); - args.add( Constants.BASEDIR + "/scripts/system-" + mode ); if ( mode.equals( "restore" ) ) { + // Restore + args.add( Constants.BASEDIR + "/scripts/system-restore" ); if ( backupFile != null ) { args.add( backupFile ); } @@ -67,15 +74,54 @@ public class BackupRestore extends SystemCommandTask if ( restoreOpenslx ) { args.add( "openslx" ); } + args.add( "--restore" ); + if ( password != null ) { + args.add( "--decrypt" ); + args.add( "TM_PW_ENV_VAR" ); + } + } else if ( mode.equals( "test" ) ) { + // Test archive encryption / archive format + args.add( Constants.BASEDIR + "/scripts/system-restore" ); + args.add( backupFile ); + args.add( "--test" ); + if ( password != null ) { + args.add( "--decrypt" ); + args.add( "TM_PW_ENV_VAR" ); + } + } else { + // Backup + args.add( Constants.BASEDIR + "/scripts/system-backup" ); + if ( password != null ) { + args.add( "--encrypt" ); + args.add( "TM_PW_ENV_VAR" ); + } + if ( destination != null ) { + args.add( "--destination" ); + args.add( destination ); + } } return args.toArray( new String[ args.size() ] ); } @Override + protected void initEnvironment( Map<String, String> environment ) + { + if ( password != null ) { + environment.put( "TM_PW_ENV_VAR", password ); + } + } + + @Override protected boolean processEnded( int exitCode ) { + if ( backupFile != null ) { + try { + new File( backupFile ).delete(); + } catch ( Exception e ) { + } + } isRunning.set( false ); - return exitCode == 0 && ( mode.equals( "restore" ) || status.backupFile != null ); + return exitCode == 0 && ( mode.equals( "test" ) || mode.equals( "restore" ) || status.backupFile != null ); } @Override |