Archive

Posts Tagged ‘Redis’

Redis backup script

August 7, 2015 3 comments
#!/bin/bash 
## Fri, 07 Aug 2015 14:04:57 +0300 
## redis backup every 15 minutes 
## */15 * * * * redis.backup.maintenance.sh >> /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 

lockf="/var/run/redis.backup.lock.dir"

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


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
do
 if [ $(redis-cli LASTSAVE | awk '{print $1}') -eq ${last_save} ]
 then
 echo -n ". "
 sleep 2
 else
 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"
 break
 fi
done


if [ -d "${lockf}" ]
then
 echo "$(date +%Y-%m-%d.%H.%M.%S) : removing the lock"
 rm -rf "${lockf}"
fi
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 : http://redis.io/topics/quickstart

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
/usr/bin/tclsh
/usr/bin/tclsh8.4

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


wget http://prdownloads.sourceforge.net/tcl/tcl8.5.11-src.tar.gz
tar xvfz tcl8.5.11-src.tar.gz
cd tcl8.5.11/
cd unix/
./configure
make -j3
removepkg tcl-8.4.15-i486-1
make install
ldconfig

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:


root@aegir.ee:[Tue May 15 21:48:38]:[~]$ yum info redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.skknet.net
 * epel: mirror.telepoint.bg
 * extras: centos.skknet.net
 * updates: centos.skknet.net
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         : http://redis.io
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 http://redis.io/topics/quickstart

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:

http://www.saltwebsites.com/2012/install-redis-245-service-centos-6

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