#!/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