Friday, 25 January 2013

Compress Sage backups by date to save disk space


Windows Server 2003 with Sage


Sage creates massive number of backup files, they are uncompressed and take a lot of space.


Create a script, first to compress files, then put all files into another archive with a given date and add as a scheduled task.

Example file:
SAGE_backup_201301212130.bak - size 116MB - size 14MB

 :: created by Plazmus

cd "SAGE\SQLBackups\Daily"

:: First compress all raw files one by one, if compression is successful delete raw file

for /f "delims=" %%G in ('dir /a-d /B /OD *.bak') do "C:\Program Files\7-Zip\7z.exe" a -tzip "" "%%G" && del "%%G"

:: Now compress all zip's into one file
:: loop to compress all files in a directory by date

:: find and extract date from file name and set it as variable
FOR /f "tokens=1 delims=." %%a in ('dir * /aa-d /b /O-D') do set dd=%%a
set data=%dd:~-12%

if %data%==~-12 exit

:: make list of files to be zipped
dir *backup_%data%* /aa-d /b /OD > compressme.txt

:: if there is nothing in compressme.txt exit
for %%i in (compressme.txt) do (
 if %%~zi GTR 0 goto compress else


"C:\Program Files\7-Zip\7z.exe" a -tzip @compressme.txt && for /f "delims=" %%i in (compressme.txt) do del "%%i"

goto start

No comments:

Post a Comment