一个导数据库脚本

因为线上一个数据库太大,需要拆分,所以开发大大写了一个导库的工具redis_storage, 为了方便自动导库,写了下面脚本

#!/bin/bash
cd /opt/storage_new/
all_db_conf='/opt/storage_new/all_list.txt'
rm -rf /opt/storage_new/db/*
mkdir /opt/storage_new/log/ -p
for each_db in `cat ${all_db_conf}`;do
    cd /opt/storage_new
    echo "Backup ${each_db} Start! Time: `date +%F-%R`" >> /opt/storage_new/log/bak_record.log
    echo "cp /opt/storage_new/ready_storage/${each_db}  /opt/storage_new/conf/onland.toml"
    \cp /opt/storage_new/ready_storage/${each_db}  /opt/storage_new/conf/onland.toml
    echo "rm -rf /opt/storage_new/db/*"
    rm -rf /opt/storage_new/db/*
    echo "./redis_storage onlandall"
    ./redis_storage onlandall  >> /opt/storage_new/log/bak_${each_db} 2>&1
    echo "--------Now check onland ${each_db}---------"
    if  grep -q ERR /opt/storage_new/log/bak_${each_db};then
        echo "Bak_${each_db}  have ERR!"
        echo "Bak_${each_db}  have ERR! Time: `date +%F-%R`" >> /opt/storage_new/log/bak_record.log
        exit 1
    else
        echo "Backup ${each_db} OK! Time: `date +%F-%R`" >> /opt/storage_new/log/bak_record.log
    fi
    echo "Restore ${each_db} Start! Time: `date +%F-%R`" >> /opt/storage_new/log/restore_record.log
    echo "./redis_storage restoreall"
    ./redis_storage restoreall  >> /opt/storage_new/log/res_${each_db} 2>&1
    echo "--------Now check restore ${each_db}---------"
    if  grep -q ERR /opt/storage_new/log/res_${each_db};then
        echo "Res_${each_db}  have ERR!"
        echo "Res_${each_db}  have ERR! Time: `date +%F-%R`" >> /opt/storage_new/log/restore_record.log
        exit 1
    else
        echo "Restore ${each_db} OK! Time: `date +%F-%R`" >> /opt/storage_new/log/restore_record.log
    fi
done
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 关于Mongodb的全面总结 MongoDB的内部构造《MongoDB The Definitive Guide》...
    中v中阅读 32,027评论 2 89
  • 需要原文的可以留下邮箱我给你发,这里的文章少了很多图,懒得网上粘啦 1数据库基础 1.1数据库定义 1)数据库(D...
    极简纯粹_阅读 7,500评论 0 46
  • NOSQL类型简介键值对:会使用到一个哈希表,表中有一个特定的键和一个指针指向特定的数据,如redis,volde...
    MicoCube阅读 4,060评论 2 27
  • 花了一上午的时间把《小狗钱钱》这本书看完了,刚开始看的时候觉得有些幼稚,但再往下看的时候却渐渐被吸引,道理浅显易懂...
    阿九ninenine阅读 449评论 0 1
  • 说起花就想到草 说起风便想到雨 说起家就是你 我等过风,风吹乱我的发 我等过雨,雨淋湿我的衣 我等着你,从何方来 ...
    矣以呀阅读 229评论 0 1