Create a shell script that will dump the Redis database
cd ~
mkdir redi-backups-script
cd redis-backups-script
nano redis_backups-script.sh
Paste the script below:
#!/bin/bash
rdb_file="/Place-directory-of-rdb-here/redis/dump.rdb"
redis_cli="/usr/bin/redis-cli"
DIR=`date +%d-%m-%y`
DEST=~/redis_backups/$DIR
mkdir $DEST
echo save| $redis_cli
exit 1
Set script to executable:
chmod +x ~/scripts/redis_backups-script.sh
Create a cron to run daily:
Then create a cron job to run the script every day at midnight:
crontab -e
0 0 * * * ~/redis-backups-script/redis_backup.sh
Restore RDB backup
Disable Append Only in the config:
nano /etc/redis/redis.conf
appendonly no
Stop redis:
sudo service redis-server stop
Restore the redis backup:
rename the rdb file you wish
sudo cp /home/redis/dump.rdb /home/redis/dump.rdb.bak
You can then copy the backup rdb file as follows:
sudo cp /redis_backups/------/dump.rdb /home/redis/dump.rdb
Apply the proper permissions to the dump.rdb file:
sudo chmod 660 /home/redis/dump.rdb
Re-starting Redis server
sudo service redis-server start