backup.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. #backup MongoDB
  3. OUT_DIR=`pwd`/backup
  4. DUMP=/usr/bin/mongodump
  5. DATE=`date +%Y_%m_%d`
  6. DB_USER=backup
  7. DB_PASS=74be16979710d4c4e7c6647856088456
  8. rm -rf $OUT_DIR/*
  9. mkdir -p $OUT_DIR/$DATE
  10. $DUMP -h 172.16.69.131:27228 -u $DB_USER -p $DB_PASS --authenticationDatabase admin --authenticationMechanism=SCRAM-SHA-1 -d washpay --excludeCollection=service_progress --excludeCollection=DevicePortReport --excludeCollection=dev_status_record --excludeCollection=SIMCard --excludeCollection=device_control_info --excludeCollection=dealer_message --excludeCollection=complaint --excludeCollection=check_devices --excludeCollection=exception_log --excludeCollection=events --excludeCollection=on_sale_record --excludeCollection=operator_logs --excludeCollection=promotion_records --excludeCollection=temp_values --excludeCollection=test_record --excludeCollection=tester_log --excludeCollection=device_replacements --excludeCollection=ad_pv --excludeCollection=device_upload_info --excludeCollection=device_migration_histories --excludeCollection=device_port_last_report --excludeCollection=ConsumeRecord --excludeCollection=RechargeRecord --excludeCollection=MyUser --excludeCollection=unique_user --gzip --numParallelCollections=1 -o $OUT_DIR/$DATE
  11. tar -zcvf $OUT_DIR/washpay_small_$DATE.tar.gz $OUT_DIR/$DATE
  12. /opt/ossutil64 cp -f $OUT_DIR/washpay_small_$DATE.tar.gz oss://mongo-history/mongobackup/
  13. rm -rf $OUT_DIR/*
  14. mkdir -p $OUT_DIR/$DATE
  15. $DUMP -h 172.16.69.131:27228 -u $DB_USER -p $DB_PASS --authenticationDatabase admin --authenticationMechanism=SCRAM-SHA-1 -d washpay -c MyUser --gzip -o $OUT_DIR/$DATE
  16. tar -zcvf $OUT_DIR/washpay_MyUser_$DATE.tar.gz $OUT_DIR/$DATE
  17. /opt/ossutil64 cp -f $OUT_DIR/washpay_MyUser_$DATE.tar.gz oss://mongo-history/mongobackup/
  18. rm -rf $OUT_DIR/*
  19. mkdir -p $OUT_DIR/$DATE
  20. $DUMP -h 172.16.69.131:27228 -u $DB_USER -p $DB_PASS --authenticationDatabase admin --authenticationMechanism=SCRAM-SHA-1 -d washpay -c unique_user --gzip -o $OUT_DIR/$DATE
  21. tar -zcvf $OUT_DIR/washpay_unique_user_$DATE.tar.gz $OUT_DIR/$DATE
  22. /opt/ossutil64 cp -f $OUT_DIR/washpay_unique_user_$DATE.tar.gz oss://mongo-history/mongobackup/
  23. year=`date '+%Y'`
  24. month=`date '+%m'`
  25. month=$(echo -e $month | sed -r 's/0*([0-9])/\1/')
  26. bash ./dumpdata.sh -y $year -m $month
  27. bash ./maketar.sh -y $year -m $month