Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions docs/_docs/snapshots/snapshots.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ Ignite ships the link:tools/control-script[Control Script] that supports snapsho

[source,shell]
----
#Create a cluster snapshot in the background:
control.(sh|bat) --snapshot create snapshot_name
# Create a cluster snapshot named "snapshot_09062021" in the background:
control.(sh|bat) --snapshot create snapshot_09062021

#Create a cluster snapshot (wait for the entire operation to complete):
control.(sh|bat) --snapshot create snapshot_name --sync
# Create a cluster snapshot named "snapshot_09062021" and wait for the entire operation to complete:
control.(sh|bat) --snapshot create snapshot_09062021 --sync

#Cancel a running snapshot:
control.(sh|bat) --snapshot cancel snapshot_name
# Create a cluster snapshot named "snapshot_09062021" in the "/tmp/ignite/snapshots" folder (the full path to the snapshot files will be /tmp/ignite/snapshots/snapshot_09062021):
control.(sh|bat) --snapshot create snapshot_09062021 -dest /tmp/ignite/snapshots

#Kill a running snapshot:
control.(sh|bat) --kill SNAPSHOT snapshot_name
# Cancel a running snapshot named "snapshot_09062021":
control.(sh|bat) --snapshot cancel snapshot_09062021

# Kill a running snapshot named "snapshot_09062021":
control.(sh|bat) --kill SNAPSHOT snapshot_09062021
----

=== Using JMX
Expand Down Expand Up @@ -225,6 +228,9 @@ control.(sh|bat) --snapshot restore snapshot_09062021 --start
# Start restoring all user-created cache groups from the snapshot "snapshot_09062021" and wait for the entire operation to complete.
control.(sh|bat) --snapshot restore snapshot_09062021 --start --sync

# Start restoring all user-created cache groups from the snapshot "snapshot_09062021" located in the "/tmp/ignite/snapshots" folder (the full path to the snapshot files should be /tmp/ignite/snapshots/snapshot_09062021):
control.(sh|bat) --snapshot restore snapshot_09062021 --src /tmp/ignite/snapshots

# Start restoring only "cache-group1" and "cache-group2" from the snapshot "snapshot_09062021" in the background.
control.(sh|bat) --snapshot restore snapshot_09062021 --start --groups cache-group1,cache-group2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@

package org.apache.ignite.internal.commandline.snapshot;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.apache.ignite.internal.commandline.CommandArgIterator;
import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
import org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.visor.snapshot.VisorSnapshotCheckTask;
import org.apache.ignite.internal.visor.snapshot.VisorSnapshotCheckTaskArg;

import static org.apache.ignite.internal.commandline.CommandList.SNAPSHOT;
import static org.apache.ignite.internal.commandline.CommandLogger.optional;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotCheckCommandOption.SOURCE;

/**
* Sub-command to check snapshot.
Expand All @@ -32,9 +40,44 @@ protected SnapshotCheckCommand() {
super("check", VisorSnapshotCheckTask.class);
}

/** {@inheritDoc} */
@Override public void parseArguments(CommandArgIterator argIter) {
String snpName = argIter.nextArg("Expected snapshot name.");
String snpPath = null;

while (argIter.hasNextSubArg()) {
String arg = argIter.nextArg(null);

SnapshotCheckCommandOption option = CommandArgUtils.of(arg, SnapshotCheckCommandOption.class);

if (option == null) {
throw new IllegalArgumentException("Invalid argument: " + arg + ". " +
"Possible options: " + F.concat(F.asList(SnapshotCheckCommandOption.values()), ", ") + '.');
}
else if (option == SOURCE) {
if (snpPath != null)
throw new IllegalArgumentException(SOURCE.argName() + " arg specified twice.");

String errMsg = "Expected path to the snapshot directory.";

if (CommandArgIterator.isCommandOrOption(argIter.peekNextArg()))
throw new IllegalArgumentException(errMsg);

snpPath = argIter.nextArg(errMsg);
}
}

cmdArg = new VisorSnapshotCheckTaskArg(snpName, snpPath);
}

/** {@inheritDoc} */
@Override public void printUsage(Logger log) {
usage(log, "Check snapshot:", SNAPSHOT, generalUsageOptions(), name(), SNAPSHOT_NAME_ARG);
Map<String, String> params = new LinkedHashMap<>(generalUsageOptions());

params.put(SOURCE.argName() + " " + SOURCE.arg(), SOURCE.description());

usage(log, "Check snapshot:", SNAPSHOT, params, name(), SNAPSHOT_NAME_ARG,
optional(SOURCE.argName(), SOURCE.arg()));
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.commandline.snapshot;

import org.apache.ignite.internal.commandline.argument.CommandArg;

/**
* Snapshot check command options.
*/
public enum SnapshotCheckCommandOption implements CommandArg {
/** Snapshot directory location. */
SOURCE("--src", "path", "Path to the directory where the snapshot files are located. If not specified, " +
"the default configured snapshot directory will be used.");

/** Name. */
private final String name;

/** Argument. */
private final String arg;

/** Description. */
private final String desc;

/**
* @param name Name.
* @param arg Argument.
* @param desc Description.
*/
SnapshotCheckCommandOption(String name, String arg, String desc) {
this.name = name;
this.arg = arg;
this.desc = desc;
}

/** {@inheritDoc} */
@Override public String argName() {
return name;
}

/** @return Argument. */
public String arg() {
return arg;
}

/** @return Description. */
public String description() {
return desc;
}

/** @return Argument name. */
@Override public String toString() {
return argName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static org.apache.ignite.internal.commandline.CommandList.SNAPSHOT;
import static org.apache.ignite.internal.commandline.CommandLogger.optional;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotCreateCommandOption.DESTINATION;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotCreateCommandOption.SYNC;

/**
Expand All @@ -42,6 +43,7 @@ protected SnapshotCreateCommand() {
/** {@inheritDoc} */
@Override public void parseArguments(CommandArgIterator argIter) {
String snpName = argIter.nextArg("Expected snapshot name.");
String snpPath = null;
boolean sync = false;

while (argIter.hasNextSubArg()) {
Expand All @@ -53,22 +55,37 @@ protected SnapshotCreateCommand() {
throw new IllegalArgumentException("Invalid argument: " + arg + ". " +
"Possible options: " + F.concat(F.asList(SnapshotCreateCommandOption.values()), ", ") + '.');
}
else if (option == DESTINATION) {
if (snpPath != null)
throw new IllegalArgumentException(DESTINATION.argName() + " arg specified twice.");

// The snapshot create command currently supports only one optional argument.
assert option == SYNC;
String errMsg = "Expected path to the snapshot directory.";

if (CommandArgIterator.isCommandOrOption(argIter.peekNextArg()))
throw new IllegalArgumentException(errMsg);

snpPath = argIter.nextArg(errMsg);
}
else if (option == SYNC) {
if (sync)
throw new IllegalArgumentException(SYNC.argName() + " arg specified twice.");

sync = true;
}

sync = true;
}

cmdArg = new VisorSnapshotCreateTaskArg(snpName, sync);
cmdArg = new VisorSnapshotCreateTaskArg(snpName, snpPath, sync);
}

/** {@inheritDoc} */
@Override public void printUsage(Logger log) {
Map<String, String> params = new LinkedHashMap<>(generalUsageOptions());

params.put(SYNC.optionName(), SYNC.description());
params.put(DESTINATION.argName() + " " + DESTINATION.arg(), DESTINATION.description());
params.put(SYNC.argName(), SYNC.description());

usage(log, "Create cluster snapshot:", SNAPSHOT, params, name(), SNAPSHOT_NAME_ARG, optional(SYNC.argName()));
usage(log, "Create cluster snapshot:", SNAPSHOT, params, name(), SNAPSHOT_NAME_ARG,
optional(DESTINATION.argName(), DESTINATION.arg()), optional(SYNC.argName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,51 @@
package org.apache.ignite.internal.commandline.snapshot;

import org.apache.ignite.internal.commandline.argument.CommandArg;
import org.jetbrains.annotations.Nullable;

/**
* Snapshot create command options.
*/
public enum SnapshotCreateCommandOption implements CommandArg {
/** Synchronous execution flag. */
SYNC("sync", "Run the operation synchronously, the command will wait for the entire operation to complete. " +
"Otherwise, it will be performed in the background, and the command will immediately return control.");
SYNC("--sync", null, "Run the operation synchronously, the command will wait for the entire operation to complete. " +
"Otherwise, it will be performed in the background, and the command will immediately return control."),

/** Option name. */
/** Snapshot directory path. */
DESTINATION("--dest", "path", "Path to the directory where the snapshot will be saved. If not specified, " +
"the default configured snapshot directory will be used.");

/** Name. */
private final String name;

/** Option description. */
/** Argument. */
private final String arg;

/** Description. */
private final String desc;

/**
* @param name Option name.
* @param desc Option description.
* @param name Name.
* @param arg Argument.
* @param desc Description.
*/
SnapshotCreateCommandOption(String name, String desc) {
SnapshotCreateCommandOption(String name, @Nullable String arg, String desc) {
this.name = name;
this.arg = arg;
this.desc = desc;
}

/** {@inheritDoc} */
@Override public String argName() {
return "--" + name;
return name;
}

/** @return Option name. */
public String optionName() {
return name;
/** @return Argument. */
public String arg() {
return arg;
}

/** @return Option description. */
/** @return Description. */
public String description() {
return desc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import static org.apache.ignite.internal.commandline.CommandList.SNAPSHOT;
import static org.apache.ignite.internal.commandline.CommandLogger.optional;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotRestoreCommandOption.GROUPS;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotRestoreCommandOption.SOURCE;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotRestoreCommandOption.SYNC;
import static org.apache.ignite.internal.commandline.snapshot.SnapshotSubcommands.RESTORE;
import static org.apache.ignite.internal.visor.snapshot.VisorSnapshotRestoreTaskAction.START;

/**
* Sub-command to restore snapshot.
Expand All @@ -58,13 +60,14 @@ protected SnapshotRestoreCommand() {
@Override public void parseArguments(CommandArgIterator argIter) {
String snpName = argIter.nextArg("Expected snapshot name.");
VisorSnapshotRestoreTaskAction restoreAction = parseAction(argIter);
String snpPath = null;
Set<String> grpNames = null;
boolean sync = false;

while (argIter.hasNextSubArg()) {
String arg = argIter.nextArg(null);

if (restoreAction != VisorSnapshotRestoreTaskAction.START) {
if (restoreAction != START) {
throw new IllegalArgumentException("Invalid argument: " + arg + ". " +
"Action \"--" + restoreAction.name().toLowerCase() + "\" does not support specified option.");
}
Expand All @@ -75,31 +78,50 @@ protected SnapshotRestoreCommand() {
throw new IllegalArgumentException("Invalid argument: " + arg + ". " +
"Possible options: " + F.concat(F.asList(SnapshotRestoreCommandOption.values()), ", ") + '.');
}
else if (option == SnapshotRestoreCommandOption.GROUPS) {
else if (option == GROUPS) {
if (grpNames != null)
throw new IllegalArgumentException(GROUPS.argName() + " arg specified twice.");

String argDesc = "a comma-separated list of cache group names.";

grpNames = argIter.nextStringSet(argDesc);

if (grpNames.isEmpty())
throw new IllegalArgumentException("Expected " + argDesc);
}
else if (option == SYNC)
else if (option == SOURCE) {
if (snpPath != null)
throw new IllegalArgumentException(SOURCE.argName() + " arg specified twice.");

String errMsg = "Expected path to the snapshot directory.";

if (CommandArgIterator.isCommandOrOption(argIter.peekNextArg()))
throw new IllegalArgumentException(errMsg);

snpPath = argIter.nextArg(errMsg);
}
else if (option == SYNC) {
if (sync)
throw new IllegalArgumentException(SYNC.argName() + " arg specified twice.");

sync = true;
}
}

cmdArg = new VisorSnapshotRestoreTaskArg(snpName, sync, restoreAction, grpNames);
cmdArg = new VisorSnapshotRestoreTaskArg(snpName, snpPath, sync, restoreAction, grpNames);
}

/** {@inheritDoc} */
@Override public void printUsage(Logger log) {
Map<String, String> params = generalUsageOptions();
Map<String, String> startParams = new LinkedHashMap<>(params);

startParams.put(GROUPS.optionName(), GROUPS.description());
startParams.put(SYNC.optionName(), SYNC.description());
startParams.put(GROUPS.argName() + " " + GROUPS.arg(), GROUPS.description());
startParams.put(SOURCE.argName() + " " + SOURCE.arg(), SOURCE.description());
startParams.put(SYNC.argName(), SYNC.description());

usage(log, "Restore snapshot:", SNAPSHOT, startParams, RESTORE.toString(), SNAPSHOT_NAME_ARG, "--start",
optional(GROUPS.argName(), GROUPS.optionName()), optional(SYNC.argName()));
optional(GROUPS.argName(), GROUPS.arg()), optional(SOURCE.argName(), SOURCE.arg()), optional(SYNC.argName()));
usage(log, "Snapshot restore operation status:", SNAPSHOT, params, RESTORE.toString(), SNAPSHOT_NAME_ARG, "--status");
usage(log, "Cancel snapshot restore operation:", SNAPSHOT, params, RESTORE.toString(), SNAPSHOT_NAME_ARG, "--cancel");
}
Expand All @@ -108,7 +130,7 @@ else if (option == SYNC)
@Override public String confirmationPrompt() {
VisorSnapshotRestoreTaskArg arg = (VisorSnapshotRestoreTaskArg)cmdArg;

return arg.jobAction() != VisorSnapshotRestoreTaskAction.START || arg.groupNames() != null ? null :
return arg.jobAction() != START || arg.groupNames() != null ? null :
"Warning: command will restore ALL USER-CREATED CACHE GROUPS from the snapshot " + arg.snapshotName() + '.';
}

Expand Down
Loading