KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > backup > backupers > OctopusBackuper


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): Emmanuel Cecchet.
21  * Contributor(s): Nicolas Modrzyk.
22  */

23
24 package org.continuent.sequoia.controller.backup.backupers;
25
26 import java.io.BufferedReader JavaDoc;
27 import java.io.BufferedWriter JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileNotFoundException JavaDoc;
30 import java.io.FileReader JavaDoc;
31 import java.io.FileWriter JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.PrintStream JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Date JavaDoc;
36 import java.util.Hashtable JavaDoc;
37 import java.util.Iterator JavaDoc;
38
39 import org.apache.log4j.Category;
40 import org.apache.log4j.Priority;
41 import org.continuent.sequoia.common.exceptions.BackupException;
42 import org.continuent.sequoia.common.exceptions.OctopusException;
43 import org.continuent.sequoia.common.i18n.Translate;
44 import org.continuent.sequoia.common.log.Trace;
45 import org.continuent.sequoia.common.util.FileManagement;
46 import org.continuent.sequoia.common.util.LoggingOutputStream;
47 import org.continuent.sequoia.controller.backend.DatabaseBackend;
48 import org.continuent.sequoia.controller.backup.DumpTransferInfo;
49 import org.continuent.sequoia.controller.sql.schema.DatabaseTable;
50 import org.webdocwf.util.loader.Loader;
51 import org.webdocwf.util.loader.generator.LoaderGenerator;
52
53 /**
54  * This class defines a Backuper based on Octopus v3.4.1.
55  * <p>
56  * The options supported by this Backuper must be separated by commas (default
57  * is 'zip=true,redirectOutput=false'). The options are defined as follows:
58  * <p>
59  * zip=[true,false]: defines if the dump directory must be compressed in a zip
60  * file. Default is true.
61  * <p>
62  * redirectOutput=[true,false]: redirect Octopus output directly in the logger
63  * instead of dumping everything on the standard console (may not work on some
64  * systems). Default is false.
65  *
66  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
67  * </a>
68  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
69  * @version 1.0
70  */

71 public class OctopusBackuper extends AbstractBackuper
72 {
73   static Trace logger = Trace
74                                                    .getLogger(OctopusBackuper.class
75                                                        .getName());
76   private boolean redirectOutput = false;
77   private boolean zipBackupFiles = true;
78
79   static
80   {
81     String JavaDoc sequoiaHome = System.getProperty("sequoia.home");
82     if (sequoiaHome != null)
83       System.setProperty("OCTOPUS_HOME", sequoiaHome + File.separator + "lib"
84           + File.separator + "octopus" + File.separator + "xml");
85   }
86
87   //
88
// Octopus constants
89
//
90

91   private static final int DB_NAME = 0;
92   private static final int DRIVER = 1;
93   private static final int FULL_NAME = 2;
94   private static final int PREFIX_URL = 3;
95
96   // four values ... this is REALLY dirty but I see no other way to deal with
97
// octopus constants ...
98
// 1. If we parse the url, what can describe the db we're dealing with
99
// 2. In octopus specific conf file, <Driver name="hsql">
100
// 3. In octopus general vendors file, what driver are we using ...
101
// 4. the part of the url, octopus adds up automatically, from conf file
102

103   private static final String JavaDoc[] HSQL = {"hsqldb", "hsql",
104       "HypersonicSQL", "jdbc:hsqldb:" };
105   private static final String JavaDoc[] CSV = {"csv", "csv", "Csv",
106       "jdbc:relique:csv:" };
107   private static final String JavaDoc[] MYSQL = {"mysql", "mm", "MySQL",
108       "jdbc:mysql://" };
109   private static final String JavaDoc[] POSTGRESQL = {"postgresql", "postgresql",
110       "PostgreSQL", "jdbc:postgresql://" };
111   private static final String JavaDoc[] ORACLE = {"oracle", "oracle", "Oracle",
112       "jdbc:oracle:thin:" };
113   private static final String JavaDoc[] JTURBO = {"jTurbo", "jTurbo", "MSQL",
114       "jdbc:JTurbo://" };
115   private static final String JavaDoc[] MSSQL = {"microsoft", "microsoft",
116       "MSQL", "jdbc:microsoft:sqlserver://" };
117
118   static final Hashtable JavaDoc TYPES;
119   static
120   {
121     TYPES = new Hashtable JavaDoc();
122     TYPES.put(HSQL[DB_NAME], HSQL);
123     TYPES.put(CSV[DB_NAME], CSV);
124     TYPES.put(MYSQL[DB_NAME], MYSQL);
125     TYPES.put(ORACLE[DB_NAME], ORACLE);
126     TYPES.put(POSTGRESQL[DB_NAME], POSTGRESQL);
127     TYPES.put(JTURBO[DB_NAME], JTURBO);
128     TYPES.put(MSSQL[DB_NAME], MSSQL);
129   }
130
131   //
132
// OctopusBackuper interface implementation
133
//
134

135   /**
136    * Creates a new <code>OctopusBackuper</code> object
137    */

138   public OctopusBackuper()
139   {
140   }
141
142   /**
143    * @see org.continuent.sequoia.controller.backup.Backuper#getDumpFormat()
144    */

145   public String JavaDoc getDumpFormat()
146   {
147     if (zipBackupFiles)
148       return "Octopus v3.4.1 database neutral dump compressed";
149     else
150       return "Octopus v3.4.1 database neutral dump";
151   }
152
153   /**
154    * @see org.continuent.sequoia.controller.backup.Backuper#backup(org.continuent.sequoia.controller.backend.DatabaseBackend,
155    * java.lang.String, java.lang.String, java.lang.String,
156    * java.lang.String, java.util.ArrayList)
157    */

158   public Date JavaDoc backup(DatabaseBackend backend, String JavaDoc login, String JavaDoc password,
159       String JavaDoc dumpName, String JavaDoc path, ArrayList JavaDoc tables) throws BackupException
160   {
161     logger.info(Translate.get("backup.manager.backuping.backend", new String JavaDoc[]{
162         backend.getName(), dumpName}));
163
164     if (logger.isDebugEnabled())
165       logger.debug("Creating directory for backup");
166
167     // The dump will be located in a sub-directory with the same name
168
String JavaDoc octopusDir = createOctopusDir(path, dumpName);
169
170     String JavaDoc type = getDatabaseType(backend.getURL());
171     String JavaDoc sourceType = getOctopusType(type);
172     String JavaDoc sourceUrl = backend.getURL().substring(getUrlPrefix(type).length());
173     String JavaDoc sourceDriver = getOctopusDriver(type);
174     String JavaDoc targetType = getOctopusType(TYPE_CSV);
175     String JavaDoc targetDriver = getOctopusDriver(TYPE_CSV);
176     String JavaDoc targetUrl = createCsvDir(octopusDir);
177     String JavaDoc targetUser = "";
178     String JavaDoc targetPassword = "";
179
180     PrintStream JavaDoc oldStream = null;
181     if (redirectOutput)
182     {
183       if (logger.isDebugEnabled())
184         logger.debug("Redirecting Octopus output streams");
185
186       // Prevent Octopus from dumping everything on the standard output
187
oldStream = redirectOutputStream();
188     }
189
190     try
191     {
192       // Generate metadata
193
if (logger.isDebugEnabled())
194         logger.debug("### Generating Octopus metadata ###");
195       callOctopusLoader(sourceType, sourceUrl, sourceDriver, login, password,
196           targetType, targetDriver, targetUrl, targetUser, targetPassword,
197           true, true, octopusDir);
198
199       // Generate loader job
200
if (logger.isDebugEnabled())
201         logger.debug("### Generating loader job ###");
202       callOctopusLoader(sourceType, sourceUrl, sourceDriver, login, password,
203           targetType, targetDriver, targetUrl, targetUser, targetPassword,
204           true, false, octopusDir);
205
206       if (logger.isDebugEnabled())
207       {
208         logger.debug("=======================================");
209         logger.debug("Using the following Octopus settings:");
210         logger.debug("Octopus dump directory=" + octopusDir);
211         logger.debug("Target URL=" + targetUrl);
212         logger.debug("Loader job file=" + getLoaderJobFile(octopusDir));
213         logger.debug("Compress backup=" + zipBackupFiles);
214         logger.debug("OCTOPUS HOME:" + System.getProperty("OCTOPUS_HOME"));
215         logger.debug("=======================================");
216       }
217
218       // Perform the backup
219
launchOctopus(octopusDir, dumpName, tables);
220
221       if (redirectOutput)
222       {
223         // Restore previous output stream
224
System.setOut(oldStream);
225       }
226     }
227     catch (Exception JavaDoc e)
228     {
229       if (redirectOutput)
230       {
231         // Restore previous output stream
232
System.setOut(oldStream);
233       }
234       String JavaDoc msg = "Error while performing backup for backend "
235           + backend.getName();
236       logger.error(msg, e);
237       throw new BackupException(msg, e);
238     }
239
240     // Check if we need to compress the backup
241
if (zipBackupFiles)
242     {
243       try
244       {
245         if (logger.isDebugEnabled())
246           logger.debug("Compressing dump");
247         Zipper.zip(path + File.separator + dumpName + Zipper.ZIP_EXT,
248             octopusDir, Zipper.STORE_PATH_FROM_ZIP_ROOT);
249         if (logger.isDebugEnabled())
250           logger.debug("Cleaning uncompressed dump files");
251         cleanUp(octopusDir);
252       }
253       catch (Exception JavaDoc e)
254       {
255         String JavaDoc msg = "Error while compressing dump";
256         logger.error(msg, e);
257         throw new BackupException(msg, e);
258       }
259     }
260
261     return new Date JavaDoc(System.currentTimeMillis());
262   }
263
264   /**
265    * @see org.continuent.sequoia.controller.backup.Backuper#restore(org.continuent.sequoia.controller.backend.DatabaseBackend,
266    * java.lang.String, java.lang.String, java.lang.String,
267    * java.lang.String, java.util.ArrayList)
268    */

269   public void restore(DatabaseBackend backend, String JavaDoc login, String JavaDoc password,
270       String JavaDoc dumpName, String JavaDoc path, ArrayList JavaDoc tables) throws BackupException
271   {
272     logger.info(Translate.get("backup.manager.restoring.backend", new String JavaDoc[]{
273         backend.getName(), dumpName}));
274
275     // The dump will be located in a sub-directory with the same name
276
String JavaDoc octopusDir = createOctopusDir(path, dumpName);
277
278     if (zipBackupFiles)
279     {
280       try
281       {
282         if (logger.isDebugEnabled())
283           logger.debug("Uncompressing dump");
284         Zipper.unzip(path + File.separator + dumpName + Zipper.ZIP_EXT,
285             octopusDir);
286       }
287       catch (Exception JavaDoc e)
288       {
289         String JavaDoc msg = "Error while uncompressing dump";
290         logger.error(msg, e);
291         throw new BackupException(msg, e);
292       }
293     }
294
295     String JavaDoc type = getDatabaseType(backend.getURL());
296     String JavaDoc targetType = getOctopusType(type);
297     String JavaDoc targetUrl = backend.getURL().substring(getUrlPrefix(type).length());
298     String JavaDoc targetDriver = getOctopusDriver(type);
299     String JavaDoc sourceType = getOctopusType(TYPE_CSV);
300     String JavaDoc sourceDriver = getOctopusDriver(TYPE_CSV);
301     String JavaDoc sourceUrl = createCsvDir(octopusDir);
302     String JavaDoc sourceUser = "";
303     String JavaDoc sourcePassword = "";
304
305     PrintStream JavaDoc oldStream = null;
306     if (redirectOutput)
307     {
308       if (logger.isDebugEnabled())
309         logger.debug("Redirecting Octopus output streams");
310
311       // Prevent Octopus from dumping everything on the standard output
312
oldStream = redirectOutputStream();
313     }
314
315     try
316     {
317       // Generate loader job
318
if (logger.isDebugEnabled())
319         logger.debug("### Generating loader job ###");
320       callOctopusLoader(sourceType, sourceUrl, sourceDriver, sourceUser,
321           sourcePassword, targetType, targetDriver, targetUrl, login, password,
322           false, false, octopusDir);
323
324       setOctopusLoaderJob(octopusDir, sourceType);
325
326       if (logger.isDebugEnabled())
327       {
328         logger.debug("=======================================");
329         logger.debug("Using the following Octopus settings:");
330         logger.debug("Octopus dump directory=" + octopusDir);
331         logger.debug("Source URL=" + sourceUrl);
332         logger.debug("Target URL=" + targetUrl);
333         logger.debug("Loader job file=" + getLoaderJobFile(octopusDir));
334         logger.debug("Compress backup=" + zipBackupFiles);
335         logger.debug("OCTOPUS HOME:" + System.getProperty("OCTOPUS_HOME"));
336         logger.debug("=======================================");
337       }
338
339       // Perform the backup
340
launchOctopus(octopusDir, dumpName, tables);
341
342       if (zipBackupFiles)
343       {
344         if (logger.isDebugEnabled())
345           logger.debug("Cleaning backup files");
346         cleanUp(octopusDir);
347       }
348
349       if (redirectOutput)
350       {
351         // Restore previous output stream
352
System.setOut(oldStream);
353       }
354     }
355     catch (Exception JavaDoc e)
356     {
357       if (redirectOutput)
358       {
359         // Restore previous output stream
360
System.setOut(oldStream);
361       }
362       String JavaDoc msg = "Error while performing restore operation on backend "
363           + backend.getName();
364       logger.error(msg, e);
365       throw new BackupException(msg, e);
366     }
367   }
368
369   /**
370    * @see org.continuent.sequoia.controller.backup.Backuper#deleteDump(java.lang.String,
371    * java.lang.String)
372    */

373   public void deleteDump(String JavaDoc path, String JavaDoc dumpName) throws BackupException
374   {
375     if (zipBackupFiles)
376     {
377       File JavaDoc toRemove = new File JavaDoc(path + File.separator + dumpName
378           + Zipper.ZIP_EXT);
379       if (logger.isDebugEnabled())
380         logger.debug("Deleting compressed dump " + toRemove);
381       toRemove.delete();
382     }
383     else
384     {
385       if (logger.isDebugEnabled())
386         logger.debug("Deleting dump directory " + path + File.separator
387             + dumpName);
388       cleanUp(path + File.separator + dumpName);
389     }
390   }
391
392   //
393
// Octopus wrappers
394
//
395

396   private static final String JavaDoc TYPE_CSV = "csv";
397   private static final String JavaDoc COPY_MODE = "copy";
398   private static final String JavaDoc OCTOPUS_INCLUDE_HREF = "<include HREF=\"sql/";
399
400   private void callOctopusLoader(String JavaDoc sourceType, String JavaDoc sourceUrl,
401       String JavaDoc sourceDriver, String JavaDoc sourceUser, String JavaDoc sourcePassword,
402       String JavaDoc targetType, String JavaDoc targetDriver, String JavaDoc targetUrl,
403       String JavaDoc targetUser, String JavaDoc targetPassword, boolean backup,
404       boolean generateAllVendors, String JavaDoc octopusDir) throws OctopusException
405   {
406     try
407     {
408       if (logger.isDebugEnabled())
409       {
410         logger.debug("Source Type:" + sourceType);
411         logger.debug("Source Driver:" + sourceDriver);
412         logger.debug("Source URL :" + sourceUrl);
413         logger.debug("Source User :" + sourceUser);
414         logger.debug("Target Type:" + targetType);
415         logger.debug("Target Driver:" + targetDriver);
416         logger.debug("Target URL:" + targetUrl);
417         logger.debug("Target User :" + targetUser);
418         logger.debug("Generate SQL for all vendors :" + generateAllVendors);
419       }
420       LoaderGenerator loader = new LoaderGenerator(sourceType, // sourceType
421
sourceUrl, // sourceDatabase Url?
422
COPY_MODE, // valueMode
423
octopusDir, // generatorOutput
424
sourceDriver, // sourceDriverName
425
targetDriver, // TargetDriverName
426
targetUrl, // targetDataBase
427
targetType, // TargetType
428
sourceUser, // sourceUser
429
sourcePassword, // sourcePassword
430
targetUser, // targetUser
431
targetPassword, // targetPassword
432
"", // domlPath
433
"org.webdoc.util.loader", // package name
434
"true", // generate drop table stmt
435
"true", // generate drop integrity statement
436
"true", // generate create table stmt
437
"true", // generate create pk statement
438
"true", // generate create fk statement
439
"true", // generate create index stmt
440
String.valueOf(generateAllVendors), // generate sql for all vendors
441
String.valueOf(!generateAllVendors), // generate xml
442
"false", // generate doml
443
String.valueOf(!generateAllVendors), // full mode ??
444
String.valueOf(!backup), // restore mode
445
null, // convertTablesToSemicolonSeparatedList(database.getTables()),
446
// tables list
447
null // Jar file structure
448
);
449       loader.generate();
450     }
451     catch (Exception JavaDoc e)
452     {
453       throw new OctopusException(e);
454     }
455   }
456
457   /**
458    * This start octopus with previously generated LoaderJob file
459    *
460    * @param octopusDir the working directory
461    * @param tables the list of tables to backup, null means all tables
462    * @throws OctopusException if octopus fails
463    */

464   private void launchOctopus(String JavaDoc octopusDir, String JavaDoc dumpName,
465       ArrayList JavaDoc tables) throws OctopusException
466   {
467     try
468     {
469       Loader myOctopus;
470       String JavaDoc loaderLogging;
471       if (logger.isDebugEnabled())
472         loaderLogging = Loader.LOGMODE_FULL;
473       else if (!logger.isFatalEnabled()) // Logger is OFF
474
loaderLogging = Loader.LOGMODE_NONE;
475       else
476         loaderLogging = Loader.LOGMODE_NORMAL;
477
478       if (tables == null)
479       {
480         // Copy everything
481
myOctopus = new Loader(getLoaderJobFile(octopusDir), loaderLogging,
482             "sequoia", octopusDir, "Octopus" + dumpName + ".log", true, null,
483             null, true, null, 0, 100);
484       }
485       else
486       {
487         // Copy only the tables we want
488
myOctopus = new Loader(getLoaderJobFile(octopusDir), loaderLogging,
489             "sequoia", octopusDir, "Octopus" + dumpName + ".log", true, null,
490             null, true, null, 0, 100, convertTablesToArray(tables));
491       }
492       try
493       {
494         myOctopus.load();
495       }
496       catch (Exception JavaDoc e)
497       {
498         logger.error("Failed to load octopus", e);
499         throw new OctopusException(Translate.get(
500             "controller.octopus.load.failed", e));
501       }
502     }
503     // I am doing this because Octopus throws NullPointerException
504
// all the time so it is impossible to know which failed
505
catch (OctopusException oe)
506     {
507       // This is thrown only by the above.
508
throw oe;
509     }
510     catch (Exception JavaDoc e)
511     {
512       throw new OctopusException(Translate
513           .get("controller.octopus.instance.failed"));
514     }
515   }
516
517   private void cleanUp(String JavaDoc octopusDir)
518   {
519     if (logger.isDebugEnabled())
520       logger.debug("Cleaning up temporary backup files...");
521     File JavaDoc toRemove = new File JavaDoc(octopusDir);
522     FileManagement.deleteDir(toRemove);
523   }
524
525   private String JavaDoc[] convertTablesToArray(ArrayList JavaDoc tablesList)
526   {
527     int length = tablesList.size();
528     String JavaDoc[] result = new String JavaDoc[length];
529     for (int i = 0; i < length; i++)
530       result[i] = ((DatabaseTable) tablesList.get(i)).getName();
531     return result;
532   }
533
534   private String JavaDoc createOctopusDir(String JavaDoc path, String JavaDoc dumpName)
535       throws BackupException
536   {
537     // Create main octopus directory
538
String JavaDoc octopusDir = path + File.separator + dumpName;
539
540     File JavaDoc octopusd = new File JavaDoc(octopusDir);
541     octopusd.mkdirs();
542     octopusd.mkdir();
543
544     if (!octopusd.exists())
545       throw new BackupException("backup.directory.cannot.be.created");
546
547     return octopusDir;
548   }
549
550   private String JavaDoc createCsvDir(String JavaDoc octopusDir) throws BackupException
551   {
552     // Create Csv directory
553
String JavaDoc csvDir = TYPE_CSV;
554     File JavaDoc csvd = new File JavaDoc(octopusDir + File.separator + csvDir);
555     csvDir = csvd.getAbsolutePath();
556     csvd.mkdirs();
557     csvd.mkdir();
558
559     if (!csvd.exists())
560       throw new BackupException("backup.directory.cannot.be.created");
561
562     return csvDir;
563   }
564
565   private String JavaDoc getDatabaseType(String JavaDoc url) throws BackupException
566   {
567     if (url == null)
568       throw new BackupException("Invalid null source url");
569     int index = url.indexOf(':');
570     int index2 = url.indexOf(':', index + 1);
571     if (index == -1 || index2 == -1 || index > index2)
572       throw new BackupException("Invalid source url format");
573     String JavaDoc type = url.substring(index + 1, index2);
574     return type;
575   }
576
577   private String JavaDoc getLoaderJobFile(String JavaDoc octopusDir)
578   {
579     return octopusDir + File.separator + "LoaderJob.olj";
580   }
581
582   private PrintStream JavaDoc redirectOutputStream()
583   {
584     PrintStream JavaDoc previousOut = System.out;
585     System.setOut(new PrintStream JavaDoc(new LoggingOutputStream(Category
586         .getInstance(this.getClass().getName()), Priority.DEBUG), true));
587     return previousOut;
588   }
589
590   private void setOctopusLoaderJob(String JavaDoc octopusDir, String JavaDoc sourceType)
591       throws OctopusException
592   {
593     String JavaDoc onErrorContinueEqualFalse = "onErrorContinue=\"false\"";
594     String JavaDoc onErrorContinueEqualTrue = "onErrorContinue=\"true\"";
595     BufferedReader JavaDoc br = null;
596     BufferedWriter JavaDoc bw = null;
597
598     try
599     {
600       br = new BufferedReader JavaDoc(new FileReader JavaDoc(getLoaderJobFile(octopusDir)));
601       String JavaDoc line = "";
602       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
603
604       while ((line = br.readLine()) != null)
605       {
606         /* Give the metadata location */
607         int idx = line.indexOf(OCTOPUS_INCLUDE_HREF);
608         if (idx != -1)
609         {
610           idx += OCTOPUS_INCLUDE_HREF.length();
611           // -4 = Skip "sql/"
612
line = line.substring(0, idx - 4) + ".." + File.separator
613               + octopusDir + File.separator + "SQLForAllVendors"
614               + File.separator + sourceType + File.separator + "sql"
615               + File.separator + line.substring(idx);
616         }
617
618         /* Force on error continue */
619         int index7 = line.indexOf(onErrorContinueEqualFalse);
620         if (index7 != -1)
621         {
622           line = line.substring(0, index7) + onErrorContinueEqualTrue
623               + line.substring(index7 + onErrorContinueEqualFalse.length());
624         }
625         buffer.append(line + System.getProperty("line.separator"));
626       }
627       br.close();
628       if (logger.isDebugEnabled())
629       {
630         logger.debug("Octopus file updated with success");
631       }
632
633       bw = new BufferedWriter JavaDoc(new FileWriter JavaDoc(getLoaderJobFile(octopusDir)));
634       bw.write(buffer.toString());
635       bw.close();
636     }
637     catch (FileNotFoundException JavaDoc fie)
638     {
639       // loader job was not generated properly
640
logger.warn(Translate.get("controller.octopus.loader.job.not.found"));
641       throw new OctopusException(fie.getMessage());
642     }
643     catch (IOException JavaDoc e)
644     {
645       // Error while reading file
646
logger.warn(Translate.get("controller.octopus.loader.io.problem"));
647     }
648     finally
649     {
650       // close the open streams
651
if (bw != null)
652         try
653         {
654           bw.close();
655         }
656         catch (IOException JavaDoc e1)
657         {
658
659         }
660       if (br != null)
661         try
662         {
663           br.close();
664         }
665         catch (IOException JavaDoc e2)
666         {
667         }
668     }
669   }
670
671   /**
672    * Get octopus type.
673    *
674    * @param type from url
675    * @return value from hashtable or null
676    * @throws BackupException if the type is not supported
677    */

678   private String JavaDoc getOctopusType(String JavaDoc type) throws BackupException
679   {
680     if (type == null)
681       return null;
682
683     // SEQUOIA-700 fix
684
if (!TYPES.containsKey(type))
685       throw new BackupException(
686           "OctopusBackuper does not support this database type.");
687
688     return ((String JavaDoc[]) TYPES.get(type))[OctopusBackuper.FULL_NAME];
689   }
690
691   /**
692    * Get octopus driver.
693    *
694    * @param type from url
695    * @return value from hashtable or null
696    */

697   private String JavaDoc getOctopusDriver(String JavaDoc type)
698   {
699     if (type == null)
700       return null;
701     return ((String JavaDoc[]) TYPES.get(type))[OctopusBackuper.DRIVER];
702   }
703
704   /**
705    * Get Octopus url prefix
706    *
707    * @param type from url
708    * @return value from hashtable or null
709    */

710   private String JavaDoc getUrlPrefix(String JavaDoc type)
711   {
712     if (type == null)
713       return null;
714     return ((String JavaDoc[]) TYPES.get(type))[OctopusBackuper.PREFIX_URL];
715   }
716
717   //
718
// Octopus Backuper options
719
//
720

721   /**
722    * @see org.continuent.sequoia.controller.backup.Backuper#setOptions(java.lang.String)
723    */

724   public void setOptions(String JavaDoc options)
725   {
726     super.setOptions(options);
727
728     for (Iterator JavaDoc iter = optionsMap.keySet().iterator(); iter.hasNext();)
729     {
730       String JavaDoc option = (String JavaDoc) iter.next();
731       String JavaDoc value = (String JavaDoc) optionsMap.get(option);
732
733       if (option.equals("zip"))
734       {
735         try
736         {
737           zipBackupFiles = !"false".equals(value);
738         }
739         catch (RuntimeException JavaDoc e)
740         {
741           zipBackupFiles = true;
742           logger
743               .warn("Invalid zip value for OctopusBackuper, available option is 'zip=[true,false]' ("
744                   + value + ")");
745         }
746       }
747       else if (option.equals("redirectOutput"))
748       {
749         try
750         {
751           redirectOutput = "true".equals(value);
752         }
753         catch (RuntimeException JavaDoc e)
754         {
755           redirectOutput = false;
756           logger
757               .warn("Invalid redirectOutput value for OctopusBackuper, available option is 'redirectOutput=[true,false]' ("
758                   + value + ")");
759         }
760       }
761       else
762       {
763         logger.warn("Unsupported option '" + option + "' for OctopusBackuper");
764       }
765     }
766     logger.info("OctopusBackuper backup compression is set to "
767         + zipBackupFiles);
768   }
769
770   /**
771    * @see org.continuent.sequoia.controller.backup.Backuper#fetchDump(org.continuent.sequoia.controller.backup.DumpTransferInfo,
772    * java.lang.String, java.lang.String)
773    */

774   public void fetchDump(DumpTransferInfo dumpTransferInfo, String JavaDoc path,
775       String JavaDoc dumpName) throws BackupException, IOException JavaDoc
776   {
777     super.fetchDump(dumpTransferInfo, path, dumpName + Zipper.ZIP_EXT);
778   }
779
780 }
Popular Tags