7. 数据批量导入与导出
2018-01-04 11:13 更新
数据批量导入与导出
通过以下脚本向 xhttpcache 里批量导入磁盘文件, 以下脚本会将参数指定的目录下的文件都导入到 xhttpcache 里.
#!/bin/bash redis_cmd="redis-cli -p 7379 -x set " function batch_convert() { for file in `ls $1` do if [ -d $1"/"$file ] then batch_convert $1"/"$file else key=$1"/"$file #echo 33 $redis_cmd ${key#*/} $1"/"$file $redis_cmd ${key#*/} < $1"/"$file fi done } batch_convert $1
通过以下shell脚本,可以把 xhttpcache 里的数据按目录文件的形式导出到磁盘。
#!/bin/sh # # xHttpCache数据备份脚本 # By: xSky usage() { echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "+ xHttpCache data export shell tools by:xSky " echo "+ usage: " echo "+ $0 data_dir redis_host redis_port " echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" } #判断参数 if [ $# -ne 3 ]; then usage exit 0 fi data_dir=$1 redis_host=$2 redis_port=$3 echo $data_dir $redis_host $redis_port if [ -d $data_dir ];then #redis-cli -p 6579 scan a z | awk '{print "redis-cli -p 6579 get "$0 " >"$0}'|sh cd $data_dir redis-cli -h $redis_host -p $redis_port scan a z | while read line do echo $line bdir=`expr index $line "/"` file_dir=${line%/*} file_name=$line if [[ $bdir -gt 0 ]];then #echo 1 $bdir $file_dir $file_name mkdir -p $file_dir fi redis-cli -h $redis_host -p $redis_port get $line > $line done cd - else echo [ERROR] the dir $data_dir do not exist exit 0 fi
以上内容是否对您有帮助:
更多建议: