public void backup() { resetDbLock.readLock().lock(); if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.backup(): " + name); Path path = backupPath(); path.toFile().mkdirs(); try (BackupableDBOptions backupOptions = new BackupableDBOptions(path.toString()); BackupEngine backups = BackupEngine.open(Env.getDefault(), backupOptions)) { backups.createNewBackup(db, true); if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.backup(): " + name + " done"); } catch (RocksDBException e) { logger.error("Failed to backup database '{}'", name, e); hintOnTooManyOpenFiles(e); throw new RuntimeException(e); } finally { resetDbLock.readLock().unlock(); } }
/** * Captures the state of the database in the latest backup * * Just a convenience for {@link #createNewBackup(RocksDB, boolean)} with * the flushBeforeBackup parameter set to false * * @param db The database to backup * * Note - This method is not thread safe * * @throws RocksDBException thrown if a new backup could not be created */ public void createNewBackup(final RocksDB db) throws RocksDBException { createNewBackup(db, false); }
/** * Captures the state of the database in the latest backup * * @param db The database to backup * @param flushBeforeBackup When true, the Backup Engine will first issue a * memtable flush and only then copy the DB files to * the backup directory. Doing so will prevent log * files from being copied to the backup directory * (since flush will delete them). * When false, the Backup Engine will not issue a * flush before starting the backup. In that case, * the backup will also include log files * corresponding to live memtables. The backup will * always be consistent with the current state of the * database regardless of the flushBeforeBackup * parameter. * * Note - This method is not thread safe * * @throws RocksDBException thrown if a new backup could not be created */ public void createNewBackup( final RocksDB db, final boolean flushBeforeBackup) throws RocksDBException { assert (isOwningHandle()); createNewBackup(nativeHandle_, db.nativeHandle_, flushBeforeBackup); }
/** * Backups the DB to a local path. * @param backupPath - The local backup path */ protected void backup(String backupPath) throws RocksDBException { File file = new File(backupPath); if(!file.exists()) file.mkdir(); BackupableDBOptions backupOptions = new BackupableDBOptions(backupPath) .setShareTableFiles(true) .setMaxBackgroundOperations(parallelism); BackupEngine backupEngine = BackupEngine.open(Env.getDefault(), backupOptions); backupEngine.createNewBackup(rocksDB, true); backupEngine.purgeOldBackups(backupsToKeep); backupEngine.close(); backupOptions.close(); }