Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rem This script archives automatically the mesaage logs from their folders to the X: drive
- rem author Henry Barton, GCO hOP - v0.1 17/07/2017
- @echo off
- rem Trying to automate archiving, at 0100 of the 1st day of the month, zip, test, and move compressed files from D:\ to X:\, then delete files off of D:\
- rem define location where application logs are found. This is called elsewhere in the script as needed.
- set homeDirectory=%~f1
- rem define location where zipped archives are copied to.
- set archiveDirectory=%~f2
- rem echo input and output directories, for debug.
- echo homeDirectory is %~f1 >> %logfile%
- echo archiveDirectory is %~f2 >> %logfile%
- rem CD to input directory to get started.
- CD /D %homeDirectory%
- rem Step 1: Check date and time
- echo %DATE%
- echo %TIME%
- rem Step 2:count files in folder
- rem C:\NotePad++\AutomatingArchiving - testing directory
- @echo off
- SET rootpath=C:\NotePad++\AutomatingArchiving
- set cnt_files=0
- set cnt_dirs=0
- rem count all files in dir and subdirs
- for /f %%a in ('dir /s /B /a-d "%rootpath%"') do set /A cnt_files+=1
- rem count all folders in dir and subdirs
- for /f %%a in ('dir /s /B /ad "%rootpath%"') do set /A cnt_dirs+=1
- echo Location: %rootpath%
- echo Files: %cnt_files%
- echo Directories: %cnt_dirs%
- rem Step 3: Compress files using 7-zip
- rem This is used from recurseday.bat
- :zipProcess
- @echo off
- rem start in a month folder and loop through the days
- for /d /r %%d in (*) do (
- rem for each day, change directory to the day
- pushd %%d
- rem loop through the hours
- for /d %%h in (*) do (
- rem zip the hour
- START "Compressing Backup. DO NOT CLOSE" /belownormal /wait "C:\Program Files\7-Zip\7z.exe" a -tzip "%%h.zip" ".\%%h\*"
- )
- rem done with the day, change directory back to the month
- popd
- )
- ECHO Zipped file creation completed...
- rem Step 4: Once zipped, each zipped folder needs to be tested to ensure there is no corruption (THIS DOESN'T WORK YET)
- @echo off
- rem Check the integrity of the zipped files
- rem check all the resulting zip files in this subdirectory for integrity - if any zip files are corrupt, write the filename to the errorlog.
- :checkProcess
- echo start check process >> %logfile%
- set /a p=0
- for %%i in (*.log) do set /a p+=1
- if %p%==0 ( goto :eof )
- for %%i in (*.zip) do (
- "C:\Program Files (x86)\7-Zip\7z.exe" t "%%i" >> %logfile%
- set ERL=%ERRORLEVEL%
- echo "Error level of integrity check: %ERRORLEVEL%" >> %logfile%
- if %ERL% NEQ 0 (
- echo "Warning: zipfile %%i has failed integrity check" >> %logfile%
- call :deletecorrupt %%i
- )
- rem this function writes an error log to the failure log if the integrity check fails.
- rem if the integrity check succeeds, it renames all the .log files that were added to it to .log.old
- if %ERL% NEQ 0 ( echo "Warning: zipfile %%i has failed integrity check" >> %failfile% ) else (
- call :rename %%i
- )
- )
- goto :eof
- :rename
- echo start rename process >> %logfile%
- set thisZip=%1
- set thismask=%thisZip:~0,18%
- echo this mask: %thisMask% >> %logfile%
- echo rename capture is %cd%\%thisMask%*.log" >> %logfile%
- ren "%cd%\%thisMask%*.log" %thisMask%*.log.old >> %logfile%
- goto :eof
- :deletecorrupt
- echo start delete corrupt process >> %logfile%
- set thisZip=%1
- del /q %homeDirectory%\*%thisZip% >> %logfile%
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement