How to backup and restore zookeeper

How to backup and restore zookeeper

What is Zookeeper

ZooKeeper is a centralised service for maintaining configuration information, naming, providing distributed synchronisation and providing group services.What exactly it means that it is a ready to use application for a maintaining configuration between distributed systems like Solr, or maintaining node status like in kafka.

Why do you need a backup

Apache Zookeeper is a crucial service but most of the times backup is not created for zookeeper which could be helpful in case of system failure.

How to create a backup of Apache zookeeper

We have a created a custom script to take backup of zookeeper. Our infra is as follows :

    1. One server from source zookeeper quorum let’s suppose the IP be
    2. A destination location to keep the backup secure it can be s3 location or any server on which you can secure backup. Let’s suppose the IP of backup server is
    3. A new server running zookeeper with no data, where data needs to be restored in case of failure of old zookeeper server. let’s suppose the IP of new server is

Lets start with setup of backup script
Go to the folder from where zookeeper is running and check for dataDir in zookeeper config file – In our case zookeeper is running from /opt/zookeeper/.
So to get the dataDir open file conf/zoo.cfg and look for keyword dataDir, in out case it is /mnt/zk. If in zoo.cfg file – there is no such keyword dataLogDir then your snapshot and logs are going in same directory which mention in /mnt/zk. But for best practice you can define both separately.

Now setup a cron on server with following script.

backup script##
rsync -arv /mnt/zk [email protected]:/backup/
if [ $? -eq 0 ]
echo “Successfully backup”
echo “zookeeper backup failure check logs” | mail -s “zookeeper backup failure,please check logs” [email protected]


— Restoration procedure —

There are two directory in zookeeper service
data : – its having snapshots file of all transaction
log : – having log file for all transaction

1. Now start a new server and install same zookeeper version as on current server –
2. Either copy the whole data and log directory to server and restart the zookeeper process.

Here is some examples of restoration –

— restore by date

On backup server find the desired snapshot by executing below command –
mkdir /opt/zoo
find . -name ‘snapshot.*’ -daystart -type f -mtime 10 -exec cp {} /opt/zoo/ \;

This command will copy the backup file 10 days before to the directory /opt/zoo/ and you can send the snapshot to new zookeeper server dataDirectory. Perform same steps for logs.

How to start zookeeper
login to server – Goto zookeeper directory
cd /opt/zookeeper-3.4.12

And execute the command –
</>sudo ./bin/ start

Zookeeper WebUI

Zookeeper WebUI is an easier way to manage zookeeper cluster, It makes easy to manage zookeeper config and resources.

For further information about Zookeeper WebUI please refer to


Leave a Reply

Your email address will not be published. Required fields are marked *