Backup & Restore: Postgres, Clickhouse, Kafka, & Redis
Overview
This is the generic solution for backup and restore. Depending on the backup strategy used, the tools might change.
Backing up and restoring Postgres
The Ansible script will automatically configure pg_basebackup, pgbackrest, wal-g and other recovery tools. For the sake of simplicity, we can use pg_dump and pg_restore.
The following command takes a backup. This will create a compressed tarball backup in the directory mentioned:
This can be scheduled using a cron as shown below:
Pg_basebackup is installed along with psql client
You can restore from pg_dump as follows:
Backing up and restoring Clickhouse
The plan is to use clickhouse-backup, which is open sourced under the liberal MIT license. This tool has the ability to create archived backups and upload them to NFS, S3, GCS, AZBlob, SFTP and other remote data repositories.
Download the latest release from https://github.com/AlexAkulov/clickhouse-backup/releases
Untar the archive
Create a configuration file as follows, call it config.ini
Ensure configuration under clickhouse and general section of the configuration file. The rest are not mandatory.
If automated remote upload functionality is needed, the appropriate section needs to be filled in: sftp, ftp, s3, GCS, AZBlob, etc.
The following command can be run:
The following is the list of possible commands which can be executed:
Backing up and restoring Kafka
Backup zookeeper state data
- Go to file
- Copy location of dataDir property (typically, /tmp/zookeeper)
- Run the following command:
Backup Kafka topics and messages
- Go to the file kafka/config/server.properties
- Copy location of log.dirs (typically, /tmp/kafka-logs)
- Stop Kafka:
- Login as kafka user:
- Run the following command:
Restore zookeeper
- sudo systemctl stop kafka
- sudo systemctl stop zookeeper
- sudo -iu kafka
- rm -r /tmp/zookeeper/*
- tar -C /tmp/zookeeper -xzf /home/kafka/zookeeper-backup.tar.gz
--strip-components 2
Restore kafka
- rm -r /tmp/kafka-logs/*
- tar -C /tmp/kafka-logs -xzf /home/kafka/kafka-backup.tar.gz --strip-components 2
- sudo systemctl start kafka
- sudo systemctl start zookeeper
Verification of Restoration
- ~/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic
BackupTopic --from-beginning
Backing up and restoring Redis
Redis provides an in-built command to save a backup.
Install redis-cli using
The following command takes a backup of the redis-server:
This will save the backup as dump.rdb within:
Restoration can be done in the following way:
Locate the redis data directory, typically:
Move the dump.rdb file into this folder
Start redis server
This will ensure that data is restored automatically
All content on this page by eGov Foundation is licensed under a Creative Commons Attribution 4.0 International License.
Last updated