zoukankan      html  css  js  c++  java
  • win 批处理,导出 MongoDB 到 json 文件

    1. call.bat

    @echo off
    
    REM **** TWO WAY TO USE THIS TOOLS                                                                   ****
    REM **** WAY 1: call test.bat                                             [yestoday's data]          ****
    REM **** WAY 2: call test.bat begin_date<yyyy-mm-dd> end_date<yyyy-mm-dd> [begin to end date's data] ****
    
    call Call_MongoDB_Export.bat
    
    exit

    2. Call_MongoDB_Export.bat

    @ECHO OFF
    
    IF "%2"=="" GOTO SYSDATE
    
    
    REM **** GET PARAMATER DATE ****
    SET LDATE=%1
    SET RDATE=%2
    SET TDATE=%2
    SET FDATE=%TDATE:~0,4%%TDATE:~5,2%%TDATE:~8,2%
    GOTO RUN
    
    
    REM **** GET SYSDATE ****
    :SYSDATE
    
    REM **** GET TODAY'S YEAR,MONTH,DAY ****
    SET YEAR=%DATE:~0,4%
    SET MONTH=%DATE:~5,2%
    SET DAY=%DATE:~8,2%
    IF %DATE:~5,1%==0 SET MONTH=%DATE:~6,1%
    IF %DATE:~8,1%==0 SET DAY=%DATE:~9,1%
    
    REM **** GET YESTODAY'S YEAR,MONTH,DAY ****
    SET /A DAY=%DAY%-1
    IF %DAY% EQU 0 SET /A MONTH=%MONTH%-1
    IF %MONTH% EQU 0 (
        SET MONTH=12
        SET /A YEAR=%YEAR%-1
    )
    IF %DAY% EQU 0 (
        IF %MONTH% EQU 1 SET DAY=31
        IF %MONTH% EQU 3 SET DAY=31
        IF %MONTH% EQU 5 SET DAY=31
        IF %MONTH% EQU 7 SET DAY=31
        IF %MONTH% EQU 8 SET DAY=31
        IF %MONTH% EQU 10 SET DAY=31
        IF %MONTH% EQU 12 SET DAY=31
        IF %MONTH% EQU 4 SET DAY=30
        IF %MONTH% EQU 6 SET DAY=30
        IF %MONTH% EQU 9 SET DAY=30
        IF %MONTH% EQU 2 (
            SET DAY=28
            IF %YEAR% EQU 2016 SET DAY=29
            IF %YEAR% EQU 2020 SET DAY=29
            IF %YEAR% EQU 2024 SET DAY=29
        )
    )
    
    REM **** FORMAT DAY,MONTH ****
    IF %DAY% LSS 10 SET DAY=0%DAY%
    IF %MONTH% LSS 10 SET MONTH=0%MONTH%
    SET LDATE=%YEAR%-%MONTH%-%DAY%
    SET RDATE=%LDATE%
    SET FDATE=%YEAR%%MONTH%%DAY%
    
    
    REM **** EXPORT MONGODB ****
    :RUN
    
    SET EXP=CALL MongoDB_export.bat %LDATE% %RDATE% %FDATE%
    
    %EXP% PU001
    %EXP% PU002

    3. MongoDB_Export.bat

    @echo off
    
    Rem D:MongoDBServer3.2inmongoexport -h repset/172.*.*.96:27017,172.*.*.97:27017,172.*.*.98:27017 -u username -p passwd --authenticationDatabase=admin -d dbname -c colname -q "{funcNo:'PU001','content.timestamp':{$gte:'2016-08-02',$lt:'2016-08-03'}}" -o D:MongoDB_ExportPU001PU001_20160803.json
    
    set MongoEX=D:MongoDBServer3.2inmongoexport -h repset/172.*.*.96:27017,172.*.*.97:27017,172.*.*.98:27017 -u username -p passwd --authenticationDatabase=admin -d dbname -c colname -q
    
    %MongoEX% "{funcNo:'%4','content.timestamp':{$gte:'%1',$lte:'%2 24:00:00'}}" -o D:MongoDB_Export\%4\%4_%3.json
  • 相关阅读:
    Spring Batch与ETL工具比较
    Spring Batch基本概念
    SpringBatch介绍
    2019第51周日
    用arthas的watch方法观察执行方法的输入输出
    三人行必有我师
    用arthas查看JVM已加载的类及方法信息
    线上问题排查利器Arthas
    换个视觉
    Java Servlet:服务器小程序
  • 原文地址:https://www.cnblogs.com/wanggs/p/5737402.html
Copyright © 2011-2022 走看看