Posts Tagged ‘Redis’

Redis backup script

August 7, 2015 3 comments
## Fri, 07 Aug 2015 14:04:57 +0300 
## redis backup every 15 minutes 
## */15 * * * * >> /var/log/redis.backup.log 2>&1 
## at /etc/rc.local : 
## test -d /var/run/redis.backup.lock.dir && rm -rf /var/run/redis.backup.lock.dir 
## watch the job: 
## tail -f /var/log/redis.backup.log 

#redis-cli LASTSAVE | awk '{print $1}' | { read gmt ; date "+%Y-%m-%d %H:%M:%S" -d "@$gmt" ; } 
# 2015-08-07 01:25:54 


# check for running script start 
if [ -d "${lockf}" ]
 echo "$(date +%Y-%m-%d.%H.%M.%S) : ${lockf} exists, exiting"
 exit 0
 mkdir "${lockf}" && echo "$(date +%Y-%m-%d.%H.%M.%S) : created lock at ${lockf}"

echo "$(date +%Y-%m-%d.%H.%M.%S) : redis backup start"
echo "$(date +%Y-%m-%d.%H.%M.%S) : cleanup the /redis_backups and leave the last 6 backups"
find /redis_backups -maxdepth 1 -type f -name "dump.rdb.*" | sort -r | sed '7,$!d' | while read to_be_deleted; do rm -f ${to_be_deleted} && echo "$(date +%Y-%m-%d.%H.%M.%S) : deleted ${to_be_deleted}";done

last_save=$(redis-cli LASTSAVE | awk '{print $1}')
echo -n "$(date +%Y-%m-%d.%H.%M.%S) : executing redis-cli BGSAVE : "
redis-cli BGSAVE
while true
 if [ $(redis-cli LASTSAVE | awk '{print $1}') -eq ${last_save} ]
 echo -n ". "
 sleep 2
 echo ""
 echo "$(date +%Y-%m-%d.%H.%M.%S) : start ionice -c2 -n0 cp -vv /opt/redis/dump.rdb to /redis_backups/"
 ionice -c2 -n0 cp -vv /opt/redis/dump.rdb /redis_backups/dump.rdb.$(date +%Y-%m-%d.%H.%M.%S) && echo "$(date +%Y-%m-%d.%H.%M.%S) : backup comleted"

if [ -d "${lockf}" ]
 echo "$(date +%Y-%m-%d.%H.%M.%S) : removing the lock"
 rm -rf "${lockf}"
Categories: AWS, bash, NoSQL Tags: , ,

Install Redis stable (2.4.13) on CentOS release 6.2 x86_64 and Slackware 12.0.0 i686

May 15, 2012 Leave a comment

just follow the instructions here :

there is small issue with the Slackware 12.0.0 install – the default tclsh version installed is tclsh8.4
so after the make is done, on make test you will see this error at Slackware shell:

Hint: To run 'make test' is a good idea 😉

make[1]: Leaving directory `/opt/installs/redis-2.4.13/src'
root@darkwater:[Tue May 15 18:01:17]:[/opt/installs/redis-2.4.13]$ make test
cd src && make test
make[1]: Entering directory `/opt/installs/redis-2.4.13/src'
which: no tclsh8.5 in (/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/qt/bin:/usr/share/texmf/bin:/opt/pgsql/bin:/opt/mysql/bin:/usr/local/ssl/bin:/opt/kannel/sbin:/opt/apache2/bin)
You need 'tclsh8.5' in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/opt/installs/redis-2.4.13/src'
make: *** [test] Error 2
root@darkwater:[Tue May 15 18:01:21]:[/opt/installs/redis-2.4.13]$ locate tclsh
locate: warning: database /var/lib/slocate/slocate.db' is more than 8 days old

how to fix that – install the latest tcl and deinstall the old one :

tar xvfz tcl8.5.11-src.tar.gz
cd tcl8.5.11/
cd unix/
make -j3
removepkg tcl-8.4.15-i486-1
make install

then proceed with the usual Redis install
the debian init script works for Slackware, just configure it

cp redis_init_script /etc/rc.d/rc.redis
chmod +x /etc/rc.d/rc.redis

and add the stop / start execution of the script at the rc.0 and rc.3 script in a view to stop properly and to start on boot

Regarding the CentOS install ,
there is epel package ready for install version 2.4.10:[Tue May 15 21:48:38]:[~]$ yum info redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
Available Packages
Name        : redis
Arch        : x86_64
Version     : 2.4.10
Release     : 1.el6
Size        : 213 k
Repo        : epel
Summary     : A persistent key-value database
URL         :
License     : BSD
Description : Redis is an advanced key-value store. It is similar to memcached but the data
            : set is not volatile, and values can be strings, exactly like in memcached, but
            : also lists, sets, and ordered sets. All this data types can be manipulated with
            : atomic operations to push/pop elements, add/remove elements, perform server side
            : union, intersection, difference between sets, and so forth. Redis supports
            : different kind of sorting abilities.

however I do prefer the latest stable version compiled from source, so I installed Redis by

the provided init script will start the redis server but will not be recognized by chkconfig,
so the fast way to set the start stop init script for Redis is to follow the instructions here:

and that is all, you may start playing with this amazing Redis