Date: Tue, 13 Jun 2006 16:14:31 +0400 From: =?Windows-1251?B?wOvl6vHl6SDD5fDs4O3u4g==?= <lex9999@mail.ru> To: FreeBSD-CVSweb mailing list <freebsd-cvsweb@FreeBSD.org> Subject: Firebird backuper for Sequoia Message-ID: <1485400932.20060613161431@mail.ru>
index | next in thread | raw e-mail
[-- Attachment #1 --] Hello, FreeBSD-CVSweb! Here is a Firebird backuper for Sequoia. It was successfully tested with Sequoia 2.8.2 and Firebird 1.5.3 under Windows XP SP2. Backuper uses gbak utility for backup and restore operations. Alexey Germanov, TopDog Russia mailto:lex9999@mail.ru [-- Attachment #2 --] /** * Sequoia: Database clustering technology. * Copyright (C) 2005 Emic Networks * Contact: sequoia@continuent.org * * Licensed 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. * * Initial developer(s): Emmanuel Cecchet. * Contributor(s): ______________________. */ package org.continuent.sequoia.controller.backup.backupers; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.continuent.sequoia.common.exceptions.BackupException; import org.continuent.sequoia.common.log.Trace; import org.continuent.sequoia.controller.backend.DatabaseBackend; import org.continuent.sequoia.controller.backup.BackupManager; import org.continuent.sequoia.controller.backup.Backuper; import org.continuent.sequoia.controller.backup.DumpTransferInfo; /** * This class defines a Backuper for Firebird databases. * <p> * Supported URLs are jdbc:firebirdsql:PathToFirebirdDatabase * <p> * The Backuper itself does not take any option. It simply dumps the Firebird * database into a file. * * @author <a href="mailto:lex9999@mail.ru">Alexey Germanov</a> * @version 1.0 */ public class FirebirdBackuper implements Backuper { static Trace logger = Trace.getLogger(FirebirdBackuper.class.getName()); /** * Creates a new <code>FirebirdBackuper</code> object */ public FirebirdBackuper() { } /** * @see org.continuent.sequoia.controller.backup.Backuper#getDumpFormat() */ public String getDumpFormat() { return "Firebird database dump"; } /** * @see org.continuent.sequoia.controller.backup.Backuper#getOptions() */ public String getOptions() { return null; } /** * @see org.continuent.sequoia.controller.backup.Backuper#setOptions(java.lang.String) */ public void setOptions(String options) { // no options are supported } /** * @see org.continuent.sequoia.controller.backup.Backuper#backup(org.continuent.sequoia.controller.backend.DatabaseBackend, * java.lang.String, java.lang.String, java.lang.String, * java.lang.String, java.util.ArrayList) */ public Date backup(DatabaseBackend backend, String login, String password, String dumpName, String path, ArrayList tables) throws BackupException { String firebirdUrlPrefix = "jdbc:firebirdsql:"; String url = backend.getURL().trim(); if (!url.startsWith(firebirdUrlPrefix)) { throw new BackupException("Unsupported db url " + url); } String pathToDb = url.replaceFirst(firebirdUrlPrefix, ""); try { String backupPath = getDumpPhysicalPath(path, dumpName); if (logger.isDebugEnabled()) logger.debug("Dumping " + pathToDb + " in " + backupPath); String command = "gbak -B -USER " + login + " -PAS " + password + " " + pathToDb + " " + backupPath; executeNativeCommand(command); } catch (Exception e) { String msg = "Error while performing backup"; logger.error(msg, e); throw new BackupException(msg, e); } return new Date(System.currentTimeMillis()); } /** * Executes a native operating system command, output of this command * is captured and logged. * * @param command String of command to execute * @return 0 if successful, any number otherwise * @throws IOException * @throws InterruptedException */ protected int executeNativeCommand(String command) throws IOException, InterruptedException { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(command); List errors = new ArrayList(); // Spawn 2 threads to capture the process output, prevents blocking NativeCommandOutputThread inStreamThread = new NativeCommandOutputThread( process.getInputStream()); NativeCommandOutputThread errStreamThread = new NativeCommandOutputThread( process.getErrorStream()); if (logger.isInfoEnabled()) { logger.info(command); } inStreamThread.start(); errStreamThread.start(); process.waitFor(); // Save the errors (if any) that we were returned from the output thread errors.addAll(inStreamThread.getErrors()); errors.addAll(errStreamThread.getErrors()); if (logger.isInfoEnabled()) { logger.info("Command \"" + command + "\" logged " + errors.size() + " errors and terminated with exitcode " + process.exitValue()); } // Return exitValue + size of errors (if all is well, should be 0) return process.exitValue() + errors.size(); } /** * @see org.continuent.sequoia.controller.backup.Backuper#restore(org.continuent.sequoia.controller.backend.DatabaseBackend, * java.lang.String, java.lang.String, java.lang.String, * java.lang.String, java.util.ArrayList) */ public void restore(DatabaseBackend backend, String login, String password, String dumpName, String path, ArrayList tables) throws BackupException { String firebirdUrlPrefix = "jdbc:firebirdsql:"; String url = backend.getURL().trim(); File dump = new File(getDumpPhysicalPath(path, dumpName)); if (!dump.exists()) throw new BackupException("Backup '" + dump + "' does not exist!"); if (!url.startsWith(firebirdUrlPrefix)) { throw new BackupException("Unsupported db url " + url); } String pathToDb = url.replaceFirst(firebirdUrlPrefix, ""); try { if (logger.isDebugEnabled()) logger.debug("Restoring " + pathToDb + " from " + dump); String command = "gbak -R -USER " + login + " -PAS " + password + " " + dump + " " + pathToDb; executeNativeCommand(command); } catch (Exception e) { String msg = "Error while performing restore"; logger.error(msg, e); throw new BackupException(msg, e); } } /** * @see org.continuent.sequoia.controller.backup.Backuper#deleteDump(java.lang.String, * java.lang.String) */ public void deleteDump(String path, String dumpName) throws BackupException { File toRemove = new File(getDumpPhysicalPath(path, dumpName)); if (logger.isDebugEnabled()) logger.debug("Deleting dump " + toRemove); toRemove.delete(); } /** * Get the dump physical path from its logical name * * @param path * the path where the dump is stored * @param dumpName * dump logical name * @return path to zip file */ private String getDumpPhysicalPath(String path, String dumpName) { return path + File.separator + dumpName; } /** * @see org.continuent.sequoia.controller.backup.Backuper#fetchDump(org.continuent.sequoia.controller.backup.DumpTransferInfo, * java.lang.String, java.lang.String) */ public void fetchDump(DumpTransferInfo dumpTransferInfo, String path, String dumpName) throws BackupException, IOException { BackupManager.fetchDumpFile(dumpTransferInfo, path, dumpName); } /** * @see org.continuent.sequoia.controller.backup.Backuper#setupDumpServer() */ public DumpTransferInfo setupDumpServer() throws IOException { return BackupManager.setupDumpFileServer(); } }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1485400932.20060613161431>
