一个导数据库脚本

因为线上一个数据库太大,需要拆分,所以开发大大写了一个导库的工具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

你可能感兴趣的:(一个导数据库脚本)