Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rem ***AGE IS A STATE OF MIND***
- rem Updated Log Copy tool started 8/16/11
- @echo off
- :globalVars
- rem ~~~~~~~~~~~~~~Global VARS~~~~~~~~~~~~~~~~~~~~
- set arg1=%1
- if %1 == autorun (
- call set auto=copy
- ) else (
- call set auto=no
- )
- set daydate=%date:~12,2%%date:~4,2%%date:~7,2%
- set pyy=%date:~12,2%
- rem Daydate is a 2digit yymmdd
- set YYYY=%date:~10,4%
- rem For dynamic folder pathing.
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- set deleteOK=0
- set deleteLIM=0
- rem Count lines to set deleteOK ceiling
- FOR /f "eol=[ tokens=1 delims=~" %%K IN (sources.txt) DO (
- set /a deleteLIM+=1
- )
- echo %deleteLIM%
- rem SETLOCAL DISABLEDELAYEDEXPANSION
- SETLOCAL ENABLEDELAYEDEXPANSION
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- :froty
- rem froty=FirstRunOfTheYear
- set yy=%date:~10,4%
- rem The next few lines do the following: Test for the existance of file corresponding to the current year.
- rem The year is in yyyy format, using yy as var (don't want to overload yyyy too much and get discombobulated.)
- rem
- if NOT exist "%appdata%\WebTrends\%yy%.y" (
- set /a yyyy-=1
- set /a pyy-=1
- echo First run of the year.
- echo %yy% > "C:\Documents and Settings\aps-svc\Application Data\WebTrends\%yy%.y"
- pause
- del /f /q paths.txt
- del /f /q newdirectories.txt
- FOR /f "eol=[ tokens=2 delims=~" %%P IN (sources.txt) DO (
- CALL echo %%P >> paths.txt
- )
- FOR /f "tokens=1,2,3,4 delims=\" %%A IN (paths.txt) DO (
- CALL echo Creating \\%%A\%%B\%%C\%%D\reports\2012 >> newdirectories.txt
- CALL mkdir \\%%A\%%B\%%C\%%D\reports\2012
- )
- del /f /q paths.txt
- goto copy
- ) else (
- set pyy=%date:~12,2%
- echo Not first run of the year. >> "D:\BATCH\Excludes_%daydate%.txt" && goto start
- )
- :start
- if exist D:\BATCH\copylogv2*.* (
- echo Copylog exists in directory for previous run. Please move to the correct directory
- pause
- goto start
- )
- TITLE ~~~~WEBTRENDS Log copy utility v2~~~~
- cls
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- rem FOR loop vars use and assignment:
- rem %%D - Used for 1st "Column" in sources.txt - Path of server\folder where files are to be deleted. Used in pulling attrib flag.
- rem %%E - Excludes file for XCOPY - Used against 1st "column" in sources.txt
- rem %%K - Delete comparison "deleteLIM". The deleteOK var must match this to delete files. - Used against 1st "column" in sources.txt
- rem %%A - Used for 1st "Column" in sources.txt - This is the files SOURCE server\path
- rem %%B - Used for 2nd "Column" in sources.txt - This is the files DESTINATION server\path
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- :sourcesmenu
- cls
- if %auto% == copy (
- goto COPY
- ) else (
- if %auto% == delete (
- goto deletetest
- )
- )
- color 0a
- echo Please select which server to copy from:
- echo 1. To COPY files from WEB servers to ANALYTICS server (PSIWebtrend1)
- echo D. For delete routine. Will only run after copy.
- echo Q. To quit!
- set INPUT=
- set /p INPUT=Choice:
- if /I '%INPUT%'=='1' goto COPY
- if /I '%INPUT%'=='D' goto deletetest
- if /I '%INPUT%'=='Q' goto quit
- if /I '%INPUT%' NEQ '1' goto sourcesmenu
- if /I '%INPUT%' NEQ 'D' goto sourcesmenu
- if /I '%INPUT%' NEQ 'Q' goto sourcesmenu
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- rem set rancopy=1 (This is counter for access to log delete system. Instantiating errorlevel based access)
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- rem The idea of this script is to be run with 2
- rem options. 1: Copy all logs. 2: Delete all logs.
- rem Copy all logs should operate something to the
- rem effect of regard "sources.txt" (text document).
- rem Parse this list file and use the path with the
- rem daydate (which is actually used to EXCLUDE the
- rem current day marked file) and copy all files from
- rem all sources to all destinations, excluding the
- rem current day file and ANY folders.
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- rem THE FOR LOOP. Parses log. Each folder on the
- rem source server will need server path and then folder name
- rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- :COPY
- FOR /f "eol=[ tokens=1 delims=~" %%E IN (sources.txt) DO (
- CALL dir /b /ad "%%E" >> "D:\BATCH\Excludes_%daydate%.txt"
- CALL dir /b "%%E\*%daydate%*" >> "D:\BATCH\Excludes_%daydate%.txt"
- )
- echo Please Wait...
- FOR /f "eol=[ tokens=1,2 delims=~" %%A IN (sources.txt) DO (
- rem CALL echo SOURCE %%A For the following. >> "D:\BATCH\copylogv2_%daydate%.txt"
- CALL xcopy "%%A\*ex%pyy%*" "%%B\" /EXCLUDE:D:\BATCH\Excludes_%daydate%.txt /Z /F /D /E /Y >> "D:\BATCH\copylogv2_%daydate%.txt"
- if NOT ERRORLEVEL 0 (
- set /a deleteOK-=1
- ) else (
- set /a deleteOK+=1
- )
- )
- echo %deleteOK%
- pause
- if %yy% GTR %yyyy% (
- echo.
- echo %YYYY% final copy complete... Starting %yy% initial copy.
- echo.
- echo RERUNNING FOR NEW YEAR...
- set /a yyyy+=1 && set /a pyy+=1 && goto COPY
- ) else (
- if %auto% == copy (
- set auto=delete & goto sourcesmenu
- ) else (
- goto sourcesmenu
- )
- :deletetest
- if '%deleteOK%'=='%deleteLIM%' (
- goto deleteFiles
- ) else (
- set deleteOK=0
- echo There were errors on the copy. Please examine copylogv2_%daydate%.txt for failed copies.
- pause & goto sourcesmenu
- )
- :deleteFiles
- color CF
- FOR /f "eol=[ tokens=1 delims=~" %%D IN (sources.txt) DO (
- CALL attrib -a "%%D\*%daydate%*"
- CALL del /q /aa "%%D\"
- CALL attrib +a "%%D\*%daydate%*"
- )
- echo success
- pause & goto sourcesmenu
- :movelogs
- set MM=%date:~4,2%
- if %MM%==01 set MM=January
- if %MM%==02 set MM=February
- if %MM%==03 set MM=March
- if %MM%==04 set MM=April
- if %MM%==01 set MM=May
- if %MM%==02 set MM=June
- if %MM%==03 set MM=July
- if %MM%==04 set MM=August
- if %MM%==01 set MM=September
- if %MM%==02 set MM=October
- if %MM%==03 set MM=November
- if %MM%==04 set MM=December
- rem
- if NOT exist D:\BATCH\%MM%_%YYYY% (
- mkdir %MM%_%YYYY% & move /y copylog*.* %MM%_%YYYY%\
- ) else (
- move /y D:\BATCH\copylog*.* D:\BATCH\%MM%_%YYYY%
- )
- :errors
- echo Your current error level is %ERRORLEVEL%
- echo If it is 0 there were no problems.
- echo If it is 1 there were problems, review logs.
- echo Log will be found in %MM%_%YYYY%
- pause
- :QUIT
- color 07
Advertisement
Add Comment
Please, Sign In to add comment