-
Notifications
You must be signed in to change notification settings - Fork 109
Backup
Regardless of which API layer you use, in run-time you can take the full and consistent copy of the database as tar.gzip
or zip
archive file. The Environment
and the PersistentEntityStore
interfaces inherit Backupable. Any instance of Backupable
can be backed up with one of the thee overloaded utility methods CompressBackupUtil.backup().
E.g., creating the new tar.gz
backup of an Environment
without name prefix in the "backups" subdirectory of the environment's location is like follows:
final Environment env = Environments.newInstance(...);
// ...
final File backupFile = CompressBackupUtil.backup(env, new File(env.getLocation(), "backups"), null, false);
As a result, backupFile
with the name like 2017-02-01-18-21-54.tar.gz
will be created.
The same can be done with PersistentEntityStore
:
final PersistentEntityStore store = PersistentEntityStores.newInstance(...);
// ...
final File backupFile = CompressBackupUtil.backup(store, new File(store.getLocation(), "backups"), null, false);
Environment
and PersistentEntityStore
instances don't require any specific actions (like, e.g., switching to read-only mode) to do backups and get consistent copies of data within backups files. Backup can be performed on-the-fly not affecting database operations.
BackupBean is handy for doing asynchronous backups. It's a decorator of one or several backupables. If you do backup of several backupables at a time you should care about their consistency yourself. Backup settings (path, name prefix and zip flag) can be provided with BackupBean
, and the bean can be used as a single parameter:
final BackupBean backupBean = new BackupBean(environment);
backupBean.setBackupToZip(true);
backupBean.setBackupPath(new File(environment.getLocation(), "backups").getAbsolutePath());
backupBean.setBackupNamePrefix("my_daily_backup");
// ...
// ...
// and further
final File backup = CompressBackupUtil.backup(backupBean);
Incremental backup is under development.