Skip to content

Commit

Permalink
- Add the experimental ability to skip certain settings on backup and…
Browse files Browse the repository at this point in the history
… restore.

- Add the ability to skip deleting some items when restoring, particularly existing worksapces.
- Add the ability to use a Map instead of Hints when calling Backup/Restore. This makes it easier to add new parameters.
  • Loading branch information
Devon Tucker authored and aaime committed Apr 25, 2018
1 parent 5a4ceaa commit 9c642a1
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 111 deletions.
13 changes: 13 additions & 0 deletions doc/en/user/source/community/backuprestore/usagerest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ Available options are:
#. ``BK_PARAM_PASSWORDS``: Whether outgoing store passwords should be parameterized in the backup. With this option set
all store passwords will be replaced with a token that looks like `${workspaceName:storeName.passwd.encryptedValue}`

#. ``BK_SKIP_SECURITY``: _Experimental_. This will exclude security settings from the backup.

#. ``BK_SKIP_SETTINGS``: _Experimental_. This will attempt to exclude most global settings from the backup, as well as
security settings.

Also an optional ``Filter`` can be passed to restrict the scope of the restore operation to a list of workspaces.

For example ::
Expand Down Expand Up @@ -202,6 +207,14 @@ Available Options are:

BK_PASSWORD_TOKENS=${workspace:store1.passwd.encryptedValye}=foo,${workspace:store2.passwd.encryptedValue}=bar

#. ``BK_SKIP_SECURITY``: _Experimental_. This will exclude security settings from the restore. Default: `false`.

#. ``BK_SKIP_SETTINGS``: _Experimental_. This will attempt to exclude most global settings from the backup, as well as
security settings. Default: `false`

#. ``BK_PURGE_RESOURCES``: _Experimental_. This will skip deleting incoming resources where possible. In particular,
existing workspaces will not be deleted during the restore. Default: `true`

Also an optional ``Filter`` can be passed to restict the scope of the restore operation to a list of workspaces.

For example ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -67,6 +68,14 @@ public class Backup extends JobExecutionListenerSupport

public static final String PARAM_PASSWORD_TOKENS = "BK_PASSWORD_TOKENS";

public static final String PARAM_SKIP_SETTINGS = "BK_SKIP_SETTINGS";

public static final String PARAM_SKIP_SECURITY_SETTINGS = "BK_SKIP_SECURITY";

public static final String PARAM_PURGE_RESOURCES = "BK_PURGE_RESOURCES";

public static final String PARAM_SKIP_GWC = "BK_SKIP_GWC";

static Logger LOGGER = Logging.getLogger(Backup.class);

/* Job Parameters Keys **/
Expand Down Expand Up @@ -321,13 +330,31 @@ protected String getItemName(XStreamPersister xp, Class clazz) {
return xp.getClassAliasingMapper().serializedClass(clazz);
}

public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
final boolean overwrite, final Filter filter, final Map<String,String> params) throws IOException {

JobParametersBuilder builder = new JobParametersBuilder();
params.forEach(builder::addString);

return runBackupAsync(archiveFile, overwrite, filter, builder);
}


public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
final boolean overwrite, final Filter filter, final Hints hints) throws IOException {

JobParametersBuilder builder = new JobParametersBuilder();
parseParams(hints, builder);
return runBackupAsync(archiveFile, overwrite, filter, builder);
}

/**
* @return
* @throws IOException
*
*/
public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
final boolean overwrite, final Filter filter, final Hints params) throws IOException {
final boolean overwrite, final Filter filter, final JobParametersBuilder paramsBuilder) throws IOException {
// Check if archiveFile exists
if (archiveFile.file().exists()) {
if (!overwrite && FileUtils.sizeOf(archiveFile.file()) > 0) {
Expand Down Expand Up @@ -356,9 +383,6 @@ public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
// Write flat files into a temporary folder
Resource tmpDir = BackupUtils.geoServerTmpDir(getGeoServerDataDirectory());

// Fill Job Parameters
JobParametersBuilder paramsBuilder = new JobParametersBuilder();

if (filter != null) {
paramsBuilder.addString("filter", ECQL.toCQL(filter));
}
Expand All @@ -369,7 +393,7 @@ public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
BackupUtils.getArchiveURLProtocol(tmpDir) + tmpDir.path())
.addLong(PARAM_TIME, System.currentTimeMillis());

parseParams(params, paramsBuilder);
// parseParams(params, paramsBuilder);

JobParameters jobParameters = paramsBuilder.toJobParameters();

Expand Down Expand Up @@ -411,6 +435,14 @@ public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
}
}

public RestoreExecutionAdapter runRestoreAsync(final Resource archiveFile, final Filter filter,
final Map<String, String> params) throws IOException {

JobParametersBuilder paramsBuilder = new JobParametersBuilder();
params.forEach(paramsBuilder::addString);
return runRestoreAsync(archiveFile, filter, paramsBuilder);
}

/**
* @return
* @return
Expand All @@ -419,28 +451,32 @@ public BackupExecutionAdapter runBackupAsync(final Resource archiveFile,
*/
public RestoreExecutionAdapter runRestoreAsync(final Resource archiveFile, final Filter filter,
final Hints params) throws IOException {
// Extract archive into a temporary folder
Resource tmpDir = BackupUtils.geoServerTmpDir(getGeoServerDataDirectory());
BackupUtils.extractTo(archiveFile, tmpDir);

// Fill Job Parameters
JobParametersBuilder paramsBuilder = new JobParametersBuilder();
parseParams(params, paramsBuilder);

return runRestoreAsync(archiveFile, filter, paramsBuilder);
}

private RestoreExecutionAdapter runRestoreAsync(Resource archiveFile, Filter filter,
JobParametersBuilder paramsBuilder) throws IOException {

Resource tmpDir = BackupUtils.geoServerTmpDir(getGeoServerDataDirectory());
BackupUtils.extractTo(archiveFile, tmpDir);
RestoreExecutionAdapter restoreExecution;

if (filter != null) {
paramsBuilder.addString("filter", ECQL.toCQL(filter));
}

paramsBuilder
.addString(PARAM_JOB_NAME, RESTORE_JOB_NAME)
.addString(PARAM_INPUT_FILE_PATH,
BackupUtils.getArchiveURLProtocol(tmpDir) + tmpDir.path())
.addLong(PARAM_TIME, System.currentTimeMillis());

parseParams(params, paramsBuilder);
.addString(PARAM_JOB_NAME, RESTORE_JOB_NAME)
.addString(PARAM_INPUT_FILE_PATH,
BackupUtils.getArchiveURLProtocol(tmpDir) + tmpDir.path())
.addLong(PARAM_TIME, System.currentTimeMillis());

JobParameters jobParameters = paramsBuilder.toJobParameters();

RestoreExecutionAdapter restoreExecution;
try {
if (getRestoreRunningExecutions().isEmpty() && getBackupRunningExecutions().isEmpty()) {
synchronized (jobOperator) {
Expand Down Expand Up @@ -470,7 +506,6 @@ public RestoreExecutionAdapter runRestoreAsync(final Resource archiveFile, final
} catch (JobExecutionAlreadyRunningException | JobRestartException
| JobInstanceAlreadyCompleteException | JobParametersInvalidException e) {
throw new IOException("Could not start a new Restore Job Execution: ", e);
} finally {
}
}

Expand Down Expand Up @@ -611,6 +646,7 @@ private void parseParams(final Hints params, JobParametersBuilder paramsBuilder)
paramsBuilder.addString(k, (String)param.getValue());
break;
case PARAM_PARAMETERIZE_PASSWDS:
case PARAM_SKIP_SETTINGS:
case PARAM_CLEANUP_TEMP:
case PARAM_DRY_RUN_MODE:
case PARAM_BEST_EFFORT_MODE:
Expand Down

0 comments on commit 9c642a1

Please sign in to comment.