1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #!/bin/bash
if [ $# != 1 ]; then echo "Usage: ./date_to.sh [datatime]" exit fi;
datetime_curr=`date '+%Y-%m-%d %H:%M:%S'` timestamp_curr=`date +%s` timestamp_to=`date -d "$1" +%s`
mongo_ip='127.0.0.1' mongo_port=27000 mongo_user='test' mongo_password='test' mongo_dbs=('test01' 'test02')
redis_cluster_ip='127.0.0.1' redis_cluster_port=6300
redis_sentinel_ip='127.0.0.1' redis_sentinel_port=6301
echo "!!!!!!! config mongodb: ${mongo_ip}:${mongo_port} !!!!!!!" for db in ${mongo_dbs[@]}; do echo " ####### db: $db #######" done echo echo "!!!!!!! config redis-cluster: ${redis_cluster_ip}:${redis_cluster_port} !!!!!!!" echo echo "!!!!!!! config redis-sentinel: ${redis_sentinel_ip}:${redis_sentinel_port} !!!!!!!" echo echo
echo "------- current datetime: $datetime_curr ($timestamp_curr) -------" echo "------- to datetime: $1 ($timestamp_to) -------"
echo
if [ $timestamp_curr -gt $timestamp_to ]; then while true; do read -p "current datetime > reset to, drop database?(y/n)" yn if echo "$yn" | grep -iq "^y" ; then echo echo '####### mongodb drop start #######'; printf "show dbs" | mongo --host $mongo_ip --port $mongo_port --username $mongo_user --password $mongo_password; for db in ${mongo_dbs[@]}; do printf "use $db\\n" | mongo --host $mongo_ip --port $mongo_port --username $mongo_user --password $mongo_password; done echo '####### mongodb drop end #######'; echo redis_nodes=`redis-cli -h $redis_cluster_ip -p $redis_cluster_port -c cluster nodes | cut -d ' ' -f 2` for node in $redis_nodes; do node_redis_ip=`echo "$node" | awk -F ':' '{print $1}'` node_redis_port=`echo "$node" | awk -F ':' '{print $2}'` echo "------- redis-cluster ${node} ${node_redis_ip} ${node_redis_port} XXX_flushall -------" done echo echo "------- redis-sentinel ${redis_sentinel_ip}:${redis_sentinel_port} XXX_flushall -------" break; else break; fi; done fi;
echo echo '####### datetime reset #######'; date -s $1
echo date '+%Y-%m-%d %H:%M:%S' exit
|