dumpdata.sh 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if [ ! -n "$month" ]; then
  22. output="`pwd`/dump/${year}"
  23. rm -rf $output
  24. mkdir -p $output
  25. start_day="${year}-01-01"
  26. start_ts=`date -u -d ${start_day} +%s`000
  27. start_month="${year}-01"
  28. next_year=`expr ${year} + 1`
  29. end_day="${next_year}-01-01"
  30. end_ts=`date -u -d ${end_day} +%s`000
  31. end_month="${next_year}-01"
  32. echo $start_day
  33. echo $start_ts
  34. echo $start_month
  35. echo $year
  36. echo $end_day
  37. echo $end_ts
  38. echo $end_month
  39. echo $next_year
  40. else
  41. start_month=`printf "%02d" ${month}`
  42. start_year=${year}
  43. next_month=`expr ${month} + 1`
  44. if [ $next_month -gt 12 ]; then
  45. end_month="01"
  46. end_year=`expr ${year} + 1`
  47. else
  48. end_month=`printf "%02d" ${next_month}`
  49. end_year=${year}
  50. fi
  51. start_day="${start_year}-${start_month}-01"
  52. start_ts=`date -u -d ${start_day} +%s`000
  53. end_day="${end_year}-${end_month}-01"
  54. end_ts=`date -u -d ${end_day} +%s`000
  55. echo $start_day
  56. echo $start_ts
  57. echo $start_month
  58. echo $start_year
  59. echo $end_day
  60. echo $end_ts
  61. echo $end_month
  62. echo $end_year
  63. echo "`pwd`/dump/${start_year}_${start_month}_01-${end_year}_${end_month}_01"
  64. output="`pwd`/dump/${start_year}_${start_month}_01-${end_year}_${end_month}_01"
  65. rm -rf $output
  66. mkdir -p $output
  67. fi
  68. 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}
  69. 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}
  70. 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}
  71. 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}
  72. 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}
  73. 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}
  74. 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}
  75. 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}
  76. 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}