1 package com.daffodilwoods.tools; 2 3 import java.rmi.*; 4 import java.sql.*; 5 import java.sql.Connection ; 6 import java.util.*; 7 8 import com.daffodilwoods.daffodildb.server.serversystem.*; 9 import com.daffodilwoods.database.resource.*; 10 import com.daffodilwoods.rmi.*; 11 import com.daffodilwoods.rmi.interfaces.*; 12 import in.co.daffodil.db.jdbc.*; 13 14 24 25 public class BackupUtility 26 extends AbstractDaffodilDBDriver { 27 private int workingMode = EMBEDDED_MODE; 28 private boolean isOffline = false; 29 private String hostName = "localhost"; 30 private int portNumber = 3456; 31 public static int EMBEDDED_MODE = 0; 32 public static int SERVER_MODE = 1; 33 private boolean verbose = false; 34 35 public BackupUtility() {} 36 37 public Connection getConnection(String driverClass, String url) throws 38 ClassNotFoundException , SQLException { 39 Class.forName(driverClass); 40 return DriverManager.getConnection(url); 41 42 } 43 44 public void setWorkingMode(int mode) { 45 workingMode = mode; 46 } 47 48 protected _Server getServer(String url) throws SQLException { 49 _Server server = super.server; 50 if (server != null) 51 return server; 52 if (!isOffline) { 53 throw new SQLException( 54 "Connect before taking online backup..."); 55 } 56 try { 57 if (workingMode == SERVER_MODE) { 58 _RmiServer rmiServer = (_RmiServer) Naming.lookup("rmi://" + hostName + 59 ":" + portNumber + "/DaffodilDB"); 60 return new RmiServer(rmiServer); 61 } 62 else { 63 return ( (_Server) Class.forName( 64 "com.daffodilwoods.daffodildb.server.serversystem.ServerSystem"). 65 newInstance()); 66 } 67 } 68 catch (Exception ex) { 69 throw new SQLException("DaffodilDB Engine not found....."); 70 } 71 72 } 73 74 protected Properties breakURL(String string, Properties properties) throws 75 SQLException { 76 throw new UnsupportedOperationException ( 77 "Method breakURL yet not implemented"); 78 } 79 80 protected Connection getConnection(String string, Properties properties) throws 81 SQLException { 82 throw new UnsupportedOperationException ( 83 "Method getConnection yet not implemented"); 84 } 85 86 public boolean acceptsURL(String string) throws SQLException { 87 throw new UnsupportedOperationException ( 88 "Method acceptsURL yet not implemented"); 89 } 90 91 public DriverPropertyInfo[] getPropertyInfo(String string, 92 Properties properties) throws 93 SQLException { 94 throw new UnsupportedOperationException ( 95 "Method getPropertyInfo yet not implemented"); 96 } 97 98 public void takeOfflinebakupServer(String hostName, int port, String userName, 99 String password, 100 String databaseNameSource, 101 String databaseNameDestination, 102 String path, 103 boolean overwrite) throws SQLException { 104 105 print("Going to take offline backup ........"); 106 this.hostName = hostName; 107 this.portNumber = port; 108 try { 109 this.isOffline = true; 110 getServer("DaffodilDB").offlineBackup(userName, password, path, 111 databaseNameSource, 112 databaseNameDestination, overwrite); 113 } 114 catch (DException ex) { 115 throw new SQLException(ex.getMessage()); 116 } 117 print("Backup taken successfully............"); 118 } 119 120 public void takeOfflinebakupEmbedded(String sourcePath, String userName, 121 String password, 122 String databaseNameSource, 123 String databaseNameDestination, 124 String path, 125 boolean overwrite) throws SQLException { 126 print("Going to take offline backup ........"); 127 try { 128 this.isOffline = true; 129 System.setProperty("daffodilDB_home", sourcePath); 130 getServer("DaffodilDB").offlineBackup(userName, password, path, 131 databaseNameSource, 132 databaseNameDestination, overwrite); 133 } 134 catch (DException ex) { 135 throw new SQLException(ex.getMessage()); 136 } 137 print("Backup taken successfully............"); 138 } 139 140 public void takeOnlineBackup(String path, String sourceDatabase, 141 String destinationDatabase, boolean overwrite) throws 142 SQLException { 143 print("Going to take offline backup ........"); 144 try { 145 getServer("DaffodilDB").getInconsistentOnlineBackup(path, sourceDatabase, 146 destinationDatabase, 147 overwrite); 148 } 149 catch (DException ex) { 150 throw new SQLException(ex.getMessage()); 151 } 152 print("Backup taken successfully............"); 153 } 154 155 public void restoreBackup(String userName, String password, 156 String databaseNameSource, 157 String databaseNameDestination, String path, 158 boolean overwrite) throws 159 SQLException { 160 print("Going to take offline backup ........"); 161 try { 162 getServer("DaffodilDB").restore(userName, password, path, 163 databaseNameSource, 164 databaseNameDestination, overwrite); 165 166 } 167 catch (DException ex) { 168 throw new SQLException(ex.getMessage()); 169 } 170 print("Backup taken successfully............"); 171 } 172 173 private void print(String str) { 174 if (verbose) 175 ; } 177 178 public void setVerbose(boolean verbose) { 179 this.verbose = verbose; 180 } 181 182 } 183 | Popular Tags |