mongodb按月份拆库
#!/bin/bash
begintime=`date -d "-$1 month" +%Y-%m`
lasttime=`date -d "-$2 month" +%Y-%m`
mogotime=`date -d "-$1 month" +%Y%m`
BeginTimestamp=$[$(date -d "$begintime-1 00:00:00" +%s%N)/1000000]
LastTimestamp=$[$(date -d "$lasttime-1 00:00:00" +%s%N)/1000000]
mkdir /data/monbak/${mogotime} -p
bak_dir=/data/monbak/${mogotime}
gte=\$gte
lt=\$lt
cr=\"create_time\"
create_time=''{$cr:{$gte:$BeginTimestamp,$lt:$LastTimestamp}}''
del_sql="
use accountdb;
db.a_payment_info.remove($create_time)
"
export_mon() {
cd ${bak_dir}
/usr/local/mongodb/bin/mongoexport -d accountdb -c a_payment_info -q $create_time -o a_payment_info.json >./export.log 2>&1
}
import_mon() {
cd ${bak_dir}
/usr/local/mongodb/bin/mongoimport -d accountdb -c a_payment_info_$mogotime ./a_payment_info.json >./import.log 2>&1
}
del_mon() {
cd ${bak_dir}
echo "$del_sql"|/usr/local/mongodb/bin/mongo >./del.log 2>&1
}
proof() {
if [ $check_export == $check_del ] && [ $check_export == $check_del ]
then echo "TRUE"
else echo "FALSE"
fi
}
main() {
export_mon
import_mon
del_mon
}
main
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步