Sunday, April 22, 2018

RocksDB: Back up

This blog will illustrate how to backup RocksDB database with ldb too. ldb is LevelDB tool, it works the same on RocksDB as long as the Comparator is compatible. 

By default, ldb would have been built along the RocksDB.

If not, please refer to the following link for more details.
https://github.com/facebook/rocksdb/wiki/Administration-and-Data-Access-Tool#ldb-tool


Assuming the following is how I have setup my RocksDB:

Database name is "dbtest1".

RocksDB installed in "/home/ubuntu/RocksDB"
Created a backup directory to "/home/ubuntu/backup_directory"

Command to initiate ldb "ldb --db=rocksdb_dir --backup_dir=where_it_backup_to



~/rocksdb$ ./ldb --db=/home/ubuntu/dbtest1 backup --backup_dir=/home/ubuntu/backup_directory/x.bk
open db OK
open backup engine OK
create new backup OK


The backup is in a form of a bundle of  3 directories where meta contains sst. All the unnecessary files such as *.log will be omitted.


/home/ubuntu/backup_directory/x.bk

ls --full -Gg
total 12
drwxr-xr-x 2 4096 2018-04-18 12:13:38.812297927 -0700 meta
drwxr-xr-x 3 4096 2018-04-18 12:13:38.804297785 -0700 private
drwxr-xr-x 2 4096 2018-04-18 12:13:38.800297715 -0700 shared



While creating the backup make sure the RocksDB do not have any applications accessing it, otherwise, they will place a lock on it and be preventing ldb from backing up. So, the RocksDB has to be in a "closed" state. 

Failed: IO error: While lock file: /home/ubuntu/dbtest1/LOCK: Resource temporarily unavailable


That's it. 

No comments:

Post a Comment