1 8 9 package com.sleepycat.je.util; 10 11 import com.sleepycat.je.DatabaseException; 12 import com.sleepycat.je.DbInternal; 13 import com.sleepycat.je.Environment; 14 import com.sleepycat.je.dbi.EnvironmentImpl; 15 import com.sleepycat.je.log.FileManager; 16 import com.sleepycat.je.utilint.DbLsn; 17 18 19 112 public class DbBackup { 113 114 private EnvironmentImpl envImpl; 115 private boolean backupStarted; 116 private long lastFileInBackupSet = -1; 117 private boolean envIsReadOnly; 118 119 124 public DbBackup(Environment env) 125 throws DatabaseException { 126 127 128 env.checkHandleIsValid(); 129 envImpl = DbInternal.envGetEnvironmentImpl(env); 130 FileManager fileManager = envImpl.getFileManager(); 131 132 136 envIsReadOnly = fileManager.checkEnvHomePermissions(true); 137 if ((!envIsReadOnly) && envImpl.isReadOnly()) { 138 throw new DatabaseException(this.getClass().getName() + 139 " requires a read/write Environment handle"); 140 } 141 } 142 143 149 public synchronized void startBackup() 150 throws DatabaseException { 151 152 if (backupStarted) { 153 throw new DatabaseException(this.getClass().getName() + 154 ".startBackup was already called"); 155 } 156 157 backupStarted = true; 158 159 try { 160 161 envImpl.getCleaner().setDeleteProhibited(); 162 163 FileManager fileManager = envImpl.getFileManager(); 164 165 169 if (envIsReadOnly) { 170 lastFileInBackupSet = fileManager.getLastFileNum().longValue(); 171 } else { 172 long newFileNum = envImpl.forceLogFileFlip(); 173 lastFileInBackupSet = DbLsn.getFileNumber(newFileNum) - 1; 174 } 175 } catch (DatabaseException e) { 176 backupStarted = false; 177 throw e; 178 } 179 } 180 181 184 public synchronized void endBackup() 185 throws DatabaseException { 186 187 checkBackupStarted(); 188 189 try { 190 envImpl.getCleaner().clearDeleteProhibited(); 191 } finally { 192 backupStarted = false; 193 } 194 } 195 196 203 public synchronized long getLastFileInBackupSet() 204 throws DatabaseException { 205 206 checkBackupStarted(); 207 return lastFileInBackupSet; 208 } 209 210 218 public synchronized String [] getLogFilesInBackupSet() 219 throws DatabaseException { 220 221 checkBackupStarted(); 222 return envImpl.getFileManager().listFiles(0, lastFileInBackupSet); 223 } 224 225 237 public synchronized 238 String [] getLogFilesInBackupSet(long lastFileCopiedInPrevBackup) 239 throws DatabaseException { 240 241 checkBackupStarted(); 242 FileManager fileManager = envImpl.getFileManager(); 243 return fileManager.listFiles(lastFileCopiedInPrevBackup + 1, 244 lastFileInBackupSet); 245 } 246 247 private void checkBackupStarted() 248 throws DatabaseException { 249 250 if (!backupStarted) { 251 throw new DatabaseException( this.getClass().getName() + 252 ".startBackup was not called"); 253 } 254 } 255 } 256 | Popular Tags |