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(); } }
/** * 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(); }
/** * <p>Share table files between backups.</p> * * @param shareTableFiles If {@code share_table_files == true}, backup will * assume that table files with same name have the same contents. This * enables incremental backups and avoids unnecessary data copies. If * {@code share_table_files == false}, each backup will be on its own and * will not share any data with other backups. * * <p>Default: true</p> * * @return instance of current BackupableDBOptions. */ public BackupableDBOptions setShareTableFiles(final boolean shareTableFiles) { assert(isOwningHandle()); setShareTableFiles(nativeHandle_, shareTableFiles); return this; }
/** * Up to this many background threads will copy files for * {@link BackupEngine#createNewBackup(RocksDB, boolean)} and * {@link BackupEngine#restoreDbFromBackup(int, String, String, RestoreOptions)} * * Default: 1 * * @param maxBackgroundOperations The maximum number of background threads * @return instance of current BackupableDBOptions. */ public BackupableDBOptions setMaxBackgroundOperations( final int maxBackgroundOperations) { assert(isOwningHandle()); setMaxBackgroundOperations(nativeHandle_, maxBackgroundOperations); return this; }
/** * <p>BackupableDBOptions constructor.</p> * * @param path Where to keep the backup files. Has to be different than db * name. Best to set this to {@code db name_ + "/backups"} * @throws java.lang.IllegalArgumentException if illegal path is used. */ public BackupableDBOptions(final String path) { super(newBackupableDBOptions(ensureWritableFile(path))); }
/** * <p>Return information if log files shall be persisted.</p> * * @return boolean value indicating if log files will be persisted. */ public boolean backupLogFiles() { assert(isOwningHandle()); return backupLogFiles(nativeHandle_); }
/** * <p>Returns the path to the BackupableDB directory.</p> * * @return the path to the BackupableDB directory. */ public String backupDir() { assert(isOwningHandle()); return backupDir(nativeHandle_); }
/** * <p>Returns if old data will be destroyed will performing new backups.</p> * * @return boolean value indicating if old data will be destroyed. */ public boolean destroyOldData() { assert(isOwningHandle()); return destroyOldData(nativeHandle_); }
/** * <p>Return backup rate limit which described the max bytes that can be * transferred in a second during backup.</p> * * @return numerical value describing the backup transfer limit in bytes per * second. */ public long backupRateLimit() { assert(isOwningHandle()); return backupRateLimit(nativeHandle_); }
/** * During backup user can get callback every time next * {@link #callbackTriggerIntervalSize()} bytes being copied. * * Default: 4194304 * * @return The interval size for the callback trigger */ public long callbackTriggerIntervalSize() { assert(isOwningHandle()); return callbackTriggerIntervalSize(nativeHandle_); }
if(path.exists()) { RestoreOptions restoreOptions = new RestoreOptions(false); BackupableDBOptions backupOptions = new BackupableDBOptions(backupPath) .setShareTableFiles(true) .setMaxBackgroundOperations(parallelism); BackupEngine backupEngine = BackupEngine.open(Env.getDefault(), backupOptions); List<BackupInfo> backupInfo = backupEngine.getBackupInfo(); backupEngine.purgeOldBackups(backupsToKeep); backupEngine.close(); backupOptions.close(); restoreOptions.close(); configure(config);
try (BackupableDBOptions backupOptions = new BackupableDBOptions(backupPath().toString()); RestoreOptions restoreOptions = new RestoreOptions(false); BackupEngine backups = BackupEngine.open(Env.getDefault(), backupOptions)) {