dumpdata.sh 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. year=
  3. while getopts ":y:m:" opt
  4. do
  5. case $opt in
  6. y)
  7. year=$OPTARG
  8. ;;
  9. m)
  10. month=$OPTARG
  11. ;;
  12. ?)
  13. echo "usage: dumpdata -y=2019 -m=2"
  14. exit 1;;
  15. esac
  16. done
  17. if [ ! -n "$year" ]; then
  18. echo "no year paramerter"
  19. exit 1
  20. fi
  21. start_month=`printf "%02d" ${month}`
  22. start_year=${year}
  23. next_month=`expr ${month} + 1`
  24. if [ $next_month -gt 12 ]; then
  25. end_month="01"
  26. end_year=`expr ${year} + 1`
  27. else
  28. end_month=`printf "%02d" ${next_month}`
  29. end_year=${year}
  30. fi
  31. start_day="${start_year}-${start_month}-01"
  32. start_ts=`date -u -d ${start_day} +%s`000
  33. end_day="${end_year}-${end_month}-01"
  34. end_ts=`date -u -d ${end_day} +%s`000
  35. echo $start_day
  36. echo $start_ts
  37. echo $start_month
  38. echo $start_year
  39. echo $end_day
  40. echo $end_ts
  41. echo $end_month
  42. echo $end_year
  43. echo "`pwd`/backup/${start_year}_${start_month}_01-${end_year}_${end_month}_01"
  44. output="`pwd`/backup/${start_year}_${start_month}_01-${end_year}_${end_month}_01"
  45. rm -rf $output
  46. mkdir -p $output
  47. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c dealer_income_proxies -q='{"$and": [{"dateTimeAdded": {"$gte":{"$date": {"$numberLong": "'${start_ts}'"}}}}, {"dateTimeAdded": {"$lt": {"$date": {"$numberLong": "'${end_ts}'"}}}}]}' --gzip -o ${output}
  48. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c dealer_daily_stats -q='{"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}' --gzip -o ${output}
  49. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c device_daily_stats -q='{"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}' --gzip -o ${output}
  50. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c group_daily_stats -q='{"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}' --gzip -o ${output}
  51. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c DealerReport -q='{"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}' --gzip -o ${output}
  52. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c DevReport -q='{"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}' --gzip -o ${output}
  53. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d report -c GroupReport -q='{"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}' --gzip -o ${output}
  54. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d washpay -c RechargeRecord -q='{"$and": [{"dateTimeAdded": {"$gte":{"$date": {"$numberLong": "'${start_ts}'"}}}}, {"dateTimeAdded": {"$lt": {"$date": {"$numberLong": "'${end_ts}'"}}}}]}' --gzip -o ${output}
  55. mongodump --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 -d washpay -c ConsumeRecord -q='{"$and": [{"dateTimeAdded": {"$gte":{"$date": {"$numberLong": "'${start_ts}'"}}}}, {"dateTimeAdded": {"$lt": {"$date": {"$numberLong": "'${end_ts}'"}}}}]}' --gzip -o ${output}