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  192.168.1.2
    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 192.168.1.3
    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 192.168.1.4

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 192.168.1.2 with following script.

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

###

— 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 – 192.168.1.2
2. Either copy the whole data and log directory to server 192.168.1.4 and restart the zookeeper process.

Here is some examples of restoration –

— restore by date

On backup server 192.168.1.3/backup 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 192.168.1.4 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/zkServer.sh 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
https://intellipaat.com/blog/what-is-apache-zookeeper/
https://github.com/DeemOpen/zkui



		

Leave a Reply

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