Incremental Backup and Restore
(Since v2.2 - Enteprise Edition only)
Incremental backup generates smaller backup files with only the delta between 2 versions of databases. This is useful when you execute a backup at regular basis and you want to avoid to backup the entire database everytime.
See also
How does it work?
Every time a backup is executed, OrientDB writes in the database directory, a file named last-backup.json
. This is an example of the content:
{
"lsn": 8438432,
"startedOn": "2015-08-17 10:33:23.943",
"completedOn": "2015-08-17 10:33:45.121"
}
The most important information is the lsn
field that is the WAL LSN (Last Serial Number). Thanks to this number, OrientDB is able to understand the last change in database, so the next incremental backup will be done starting from last lsn
+ 1.
Execute an incremental backup
Incremental backup via console
Backup Database console command accepts -incremental
as optional parameter to execute an incremental backup. In this case the new backup is executed from last backup executed (File last-backup.json
is read if any). If this is the first incremental backup, a full backup is executed. Example:
orientdb> connect plocal:/databases/mydb admin admin
orientdb {db=Whisky}> backup database /tmp/backup -incremental
Incremental backup setting allows also to specify a specific version (LSN) to start. Example:
orientdb> connect plocal:/databases/mydb admin admin
orientdb {db=Whisky}> backup database /tmp/backup -incremental=93222
Incremental backup via Java API
You can perform an incremental backup through the Java API too. If you are managing a ODocumentDatabase you have to call the ‘incrementalBackup’ method that accepts as parameter the String path of the backup directory:
ODatabaseDocumentTx documentDatabase = new ODatabaseDocumentTx(dbURL);
documentDatabase.incrementalBackup("/tmp/backup");
If you are managing a OrientGraph you have to get the raw graph before the call to the ‘incrementalBackup’ method:
OrientGraph graphDatabase = new OrientGraphNoTx(dbURL);
graphDatabase.getRawGraph().incrementalBackup("/tmp/backup");
Execute an incremental restore
Incremental restore via console
Restore Database console command automatically recognizes if a backup contains incremental data. Example:
orientdb> connect plocal:/databases/mydb admin admin
orientdb {db=Whisky}> restore database /tmp/backup
Incremental restore via Java API
You can perform an incremental restore through the Java API too. If you are managing a ODocumentDatabase you have to call the ‘incrementalRestore’ method that accepts as parameter the String path of the backup directory:
ODatabaseDocumentTx documentDatabase = new ODatabaseDocumentTx(dbURL);
documentDatabase.incrementalRestore("/tmp/backup");
If you are managing a OrientGraph you have to get the raw graph before the call to the ‘incrementalRestore’ method:
OrientGraph graphDatabase = new OrientGraphNoTx(dbURL);
graphDatabase.getRawGraph().incrementalRestore("/tmp/backup");
Distributed Architecture
Incremental backup is used in Distributed Architecture when a server node restarts. This avoid to backup and tranfer the entire database across the network.
Internals
File format
In case of incremental backup, the content of the zip file is not the database directory, but rather meta files needed to update the database with the delta. Example of content:
- Employee.pcl
- Person.pcl.incremental
- Person.pcm.incremental
This means only 3 files are changed, Employee.pcl is a full file, while the other 2 files with extension “.incremental” are incremental. Incremental files contain all the page changes with the following format:
+----------------+-----------------+
| PAGE NUMBER | PAGE CONTENT |
| (long) | byte[] |
+----------------+-----------------+