Translate to your Language

Disclaimer Statement

Total Pageviews

47,429

Track

Follow us on FaceBook

About

Powered by Blogger.

Popular Posts

Sunday, February 24, 2013

Datastage DSX Files Export Script

by Unknown  |  in DataStage at  8:04 PM


@echo off
:: -----------------------------------------------------------------
:: DataStageExport.bat
:: -----------------------------------------------------------------
:: This batch script is used to Export all the DSX files in a Directory
:: must be run from a DataStage client machine and the parameters below should be
:: modified to fit your environment.  Use of parameters was avoided to simplify Export
:: allow the command to be customized to a particular environment.
:: -----------------------------------------------------------------
:: Required Components:
::     dsExport.exe (Windows Version)
:: -----------------------------------------------------------------
:: Host is server name
:: User is username to use to attach to DataStage
:: Password   is password to use to attach to DataStage
:: ExportDir is the directory above the backed up project
:: ProjectDir is the directory below ExportDir
:: DSExportCmd is directory of the Export command on client
:: -----------------------------------------------------------------
:: Ensure that everything that are set here are not permanent.
:: -----------------------------------------------------------------
    SETLOCAL
:: -----------------------------------------------------------------
:: Test to ensure that command line is provided semi-correctly.
:: -----------------------------------------------------------------
    IF "%1"=="" GOTO Syntax
    IF "%2"=="" GOTO Syntax
    IF "%3"=="" GOTO Syntax
    IF "%4"=="" GOTO Syntax

SET Host=%1
SET Project=%2
SET User=%3
SET Password=%4

SET BaseDir=c:\DataStage\DirD
SET ExportDir=%BaseDir%\Backups
SET ProjectDir=%ExportDir%\%Project%
SET JobList=%ExportDir%\%Project%\JobList.txt

SET DSExportCmd=C:\Progra~1\Ascential\DataStage7.5.1\DsExport.exe

:: -----------------------------------------------------------------
:: Get the current Date
:: -----------------------------------------------------------------
    FOR /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do SET DsxDate=%%c%%a%%b
:: -----------------------------------------------------------------
:: Get the current Time
:: -----------------------------------------------------------------
    FOR /f "tokens=1* delims=:" %%a in ('ECHO.^|TIME^|FINDSTR "[0-9]"') do (SET DsxTime=%%b)
:: -----------------------------------------------------------------
:: Set delimeters so that current time can be broken down into components
:: then execute FOR loop to parse the DsxTime variable into Hr/Min/Sec/Hun.
:: -----------------------------------------------------------------
    SET delim1=%DsxTime:~3,1%
    SET delim2=%DsxTime:~9,1%
    FOR /f "tokens=1-4 delims=%delim1%%delim2% " %%a in ('echo %DsxTime%') do (
        set DsxHr=%%a
        set DsxMin=%%b
        set DsxSec=%%c
        set DsxHun=%%d
    )
:: -----------------------------------------------------------------
:: If provided directory is missing an ending \, append it.
:: Validate %ProjectDir%'s existance.
:: -----------------------------------------------------------------
    if exist %ProjectDir%\ set ProjectDir=%ProjectDir%\
    if NOT exist %ProjectDir% GOTO BadMain
:: -----------------------------------------------------------------
:: Set the log file name to improve readability of code.
:: -----------------------------------------------------------------
    SET LogFileName=%ProjectDir%\DataStageExport_bat_%DsxDate%_%DsxHr%_%DsxMin%_%DsxSec%.log

:: -----------------------------------------------------------------
:: Main
:: -----------------------------------------------------------------
SET ArchiveDir=Archive_%DsxDate%_%DsxHr%_%DsxMin%_%DsxSec%

    cd %ProjectDir%
    mkdir %ArchiveDir%
    MOVE *.dsx %ArchiveDir%
    MOVE *.log %ArchiveDir%

:: -----------------------------------------------------------------
:: Announce to log of this program's run.
:: -----------------------------------------------------------------
    ECHO. > %LogFileName%
    ECHO DataStage Export ran on %DsxDate% %DsxHr%:%DsxMin%:%DsxSec% with the following parameters >> %LogFileName%
    ECHO Host=%Host% >> %LogFileName%
    ECHO User=%user% >> %LogFileName%
    ECHO ExportDir=%ExportDir% >> %LogFileName%
    ECHO ProjectDir=%ProjectDir% >> %LogFileName%
    ECHO DSExportCmd=%DSExportCmd% >> %LogFileName%
    ECHO JobList=%JobList% >> %LogFileName%
    ECHO. >> %LogFileName%

:: -----------------------------------------------------------------
:: dsExport.exe /H=hostname /U=username /P=password /O=omitflag /NUA project|/ALL|/ASK dsx_pathname1 dsx_pathname2
:: -----------------------------------------------------------------
    for /F "tokens=1" %%i in (%JobList%) do (

        ECHO Exporting %%i to Project: %Project% on Host: %Host%

        echo "%DSExportCmd% /H=%Host% /U=%User% /P=%Password% /JOB=%%i %Project% %%i.dsx" >> %LogFileName%
        %DSExportCmd% /H=%Host% /U=%User% /P=%Password% /JOB=%%i %Project% %%i.dsx >> %LogFileName%
        IF NOT %ERRORLEVEL%==0 GOTO ProjFail

        ECHO. >> %LogFileName%
        ECHO *** Completed Export for Project: %Project% on Host: %Host% >> %LogFileName%
        ECHO     from File: %ProjectDir%\%%i >> %LogFileName%
        ECHO. >> %LogFileName%
    )

    GOTO EXITPT

    GOTO ENDPOINT
:: -----------------------------------------------------------------
:: Report that directory is non-existant.
:: -----------------------------------------------------------------
:BadMain
    echo.
    echo Bad/Non-existing directory: %ExportDir%
    echo.
    echo Please ensure that you have permission to access/create directories
    echo and files.  Also ensure that directory listed exists.
    echo.

    echo. >> %LogFileName%
    echo Bad/Non-existing directory: %ExportDir% >> %LogFileName%
    echo. >> %LogFileName%

    GOTO EXITPT
:: -----------------------------------------------------------------
:: ERROR: a file failed to be Exported.
:: -----------------------------------------------------------------
:ProjFail
    ECHO.
    ECHO *** ERROR:  Failed to Export Project: %Project% on Host: %Host%
    ECHO.
    ECHO Please ensure that nobody else is accessing this server while you
    ECHO are running this Export script.
    ECHO.

    ECHO. >> %LogFileName%
    ECHO *** ERROR:  Failed to Export File: %ProjectDir%\%%i Project: %Project% on Host: %Host% >> %LogFileName%
    ECHO. >> %LogFileName%

GOTO ENDPOINT
:: -----------------------------------------------------------------
:EXITPT
    ECHO. >> %LogFileName%

:: -----------------------------------------------------------------
:ENDPOINT
    ENDLOCAL

Related Posts

0 comments:

© Copyright © 2014Bigdata-dwbi. by Bloggertheme9