#!/bin/bash
host="127.0.0.1"
port="6379"
password="bUvQslxqop"
bin_path="/web/bin/redis-3.2.11/src"
BACK_DIR="/web/bak/data/redis"
DATE="`date  +%Y%m%d%H%M`"
keepdays=10

cd $bin_path && ./redis-cli -h $host -p $port -a $password save
cp $bin_path/dump.rdb $BACK_DIR/dump.rdb$DATE


cd $BACK_DIR
for datafile in `ls`
do
    if [ ! -e $datafile ];
    then
        continue
    fi
    find . -type f -name "dump.rdb*" -mtime +$keepdays -exec ionice -c3 rm -rf {} \;
done

