KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > dbadmin > Backup


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Nicolas Modrzyk
21  * Contributor(s): Emmanuel Cecchet.
22  */

23
24 package org.continuent.sequoia.console.text.commands.dbadmin;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
30 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
31 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
32
33 /**
34  * This class defines the Backup command for the text console. It backups a
35  * backend to a dump file.
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
38  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
39  * </a>
40  * @version 1.0
41  */

42 public class Backup extends AbstractAdminCommand
43 {
44
45   /**
46    * Creates a new <code>Backup.java</code> object
47    *
48    * @param module the command is attached to
49    */

50   public Backup(VirtualDatabaseAdmin module)
51   {
52     super(module);
53   }
54
55   /**
56    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
57    */

58   public void parse(String JavaDoc commandText) throws Exception JavaDoc
59   {
60
61     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText.trim());
62
63     if (st == null || st.countTokens() < 4)
64     {
65       console.printError(getUsage());
66       return;
67     }
68     String JavaDoc backendName = st.nextToken();
69     String JavaDoc dumpName = st.nextToken();
70     String JavaDoc backuperName = st.nextToken();
71     String JavaDoc path = st.nextToken();
72     ArrayList JavaDoc tables = null;
73     boolean force = false;
74     if (st.hasMoreTokens())
75     {
76       String JavaDoc tok = st.nextToken();
77       if ("-force".equalsIgnoreCase(tok))
78       {
79         force = true;
80       }
81       else
82       {
83         tables = new ArrayList JavaDoc();
84         tables.add(tok);
85       }
86     }
87     
88     if (st.hasMoreTokens())
89     {
90       if (tables == null)
91         tables = new ArrayList JavaDoc();
92       while (st.hasMoreTokens())
93       {
94         tables.add(st.nextToken());
95       }
96     }
97
98     String JavaDoc login = console.readLine(ConsoleTranslate.get("admin.backup.user")); //$NON-NLS-1$
99
if (login == null)
100       return;
101
102     String JavaDoc pwd = console.readPassword(ConsoleTranslate
103         .get("admin.backup.password")); //$NON-NLS-1$
104
if (pwd == null)
105       return;
106
107     console.printInfo(ConsoleTranslate.get("admin.command.backup.echo", //$NON-NLS-1$
108
new String JavaDoc[]{backendName, dumpName}));
109     if (tables != null)
110       console.printInfo(ConsoleTranslate.get("admin.command.backup.tables", //$NON-NLS-1$
111
tables));
112     VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user,
113         password);
114     vdjc.backupBackend(backendName, login, pwd, dumpName, backuperName, path,
115         force, tables);
116   }
117
118   /**
119    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
120    */

121   public String JavaDoc getCommandName()
122   {
123     return "backup"; //$NON-NLS-1$
124
}
125
126   /**
127    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
128    */

129   public String JavaDoc getCommandDescription()
130   {
131     return ConsoleTranslate.get("admin.command.backup.description"); //$NON-NLS-1$
132
}
133
134   /**
135    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
136    */

137   public String JavaDoc getCommandParameters()
138   {
139     return ConsoleTranslate.get("admin.command.backup.params"); //$NON-NLS-1$
140
}
141
142 }
Popular Tags