001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Nicolas Modrzyk
021: * Contributor(s): Emmanuel Cecchet.
022: */package org.continuent.sequoia.console.text.commands.dbadmin;
023:
024: import java.util.ArrayList;
025: import java.util.StringTokenizer;
026:
027: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
028: import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
029: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
030:
031: /**
032: * This class defines the Backup command for the text console. It backups a
033: * backend to a dump file.
034: *
035: * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
036: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
037: * </a>
038: * @version 1.0
039: */
040: public class Backup extends AbstractAdminCommand {
041:
042: /**
043: * Creates a new <code>Backup.java</code> object
044: *
045: * @param module the command is attached to
046: */
047: public Backup(VirtualDatabaseAdmin module) {
048: super (module);
049: }
050:
051: /**
052: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
053: */
054: public void parse(String commandText) throws Exception {
055:
056: StringTokenizer st = new StringTokenizer(commandText.trim());
057:
058: if (st == null || st.countTokens() < 4) {
059: console.printError(getUsage());
060: return;
061: }
062: String backendName = st.nextToken();
063: String dumpName = st.nextToken();
064: String backuperName = st.nextToken();
065: String path = st.nextToken();
066: ArrayList tables = null;
067: boolean force = false;
068: if (st.hasMoreTokens()) {
069: String tok = st.nextToken();
070: if ("-force".equalsIgnoreCase(tok)) {
071: force = true;
072: } else {
073: tables = new ArrayList();
074: tables.add(tok);
075: }
076: }
077:
078: if (st.hasMoreTokens()) {
079: if (tables == null)
080: tables = new ArrayList();
081: while (st.hasMoreTokens()) {
082: tables.add(st.nextToken());
083: }
084: }
085:
086: String login = console.readLine(ConsoleTranslate
087: .get("admin.backup.user")); //$NON-NLS-1$
088: if (login == null)
089: return;
090:
091: String pwd = console.readPassword(ConsoleTranslate
092: .get("admin.backup.password")); //$NON-NLS-1$
093: if (pwd == null)
094: return;
095:
096: console.printInfo(ConsoleTranslate.get(
097: "admin.command.backup.echo", //$NON-NLS-1$
098: new String[] { backendName, dumpName }));
099: if (tables != null)
100: console.printInfo(ConsoleTranslate.get(
101: "admin.command.backup.tables", //$NON-NLS-1$
102: tables));
103: VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(
104: dbName, user, password);
105: vdjc.backupBackend(backendName, login, pwd, dumpName,
106: backuperName, path, force, tables);
107: }
108:
109: /**
110: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
111: */
112: public String getCommandName() {
113: return "backup"; //$NON-NLS-1$
114: }
115:
116: /**
117: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
118: */
119: public String getCommandDescription() {
120: return ConsoleTranslate.get("admin.command.backup.description"); //$NON-NLS-1$
121: }
122:
123: /**
124: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
125: */
126: public String getCommandParameters() {
127: return ConsoleTranslate.get("admin.command.backup.params"); //$NON-NLS-1$
128: }
129:
130: }
|