I have created two .bat scripts to replace an existing powershell based backup system due to being more familiar with bat file coding. The first one should do a full backup of all the source structure, as well as NTFS permissions. The second one is an incremental that should only backup files that have changed that day in the source.
Full Backup which is scheduled to run once a week:
Incremental Backup which is scheduled to run every day.
This seems to do what I want but open to suggestions on anyway my code could be improved.
My question and reason for posting this thread, is that I'd like to be able to compress the source folders and files and put them into the destination directory as a .zip file named as the current date to reduce disk space as at the moment I'm taking a direct copy of the source files and some of them are GB in size rather than MB.
I have found the following code below that compresses what's in the destination folder but I want to link it my two scripts above so that it compresses on the go but don't know how to. It also compresses each folder individually where as I'd like it to just zip everything together as one zip file. The code would need to be told to run from the \\server\folder\full\%datestamp%\ (or \\server\folder\Incremental\%datestamp%\) folder too. If possible I'd like it to only robocopy the compressed versions to the source and save the zip file as %datestamp%.zip otherwise I'd end up with compressed and non-compressed files and folders in the same directory which is double the disc space.
Thanks for any help.
Full Backup which is scheduled to run once a week:
Code:
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
robocopy \\Server\Share\Folder\ \\Server\Folder\Full\%datestamp%\Folder /MIR /E /r:1 /w:30 /COPYALL /LOG+:"\\Server\Folder\%datestamp%_Full_Backup.log"
robocopy \\Server\Share\Folder2\ \\Server\Folder\Full\%datestamp%\Folder2 /MIR /E /r:1 /w:30 /COPYALL /LOG+:"\\Server\Folder\%datestamp%_Full_Backup.log"
robocopy \\Server\Share\Folder3\ \\Server\Folder\Full\%datestamp%\Folder3 /MIR /E /r:1 /w:30 /COPYALL /LOG+:"\\Server\Folder\%datestamp%_Full_Backup.log"
Robocopy \\Server\Folder\ \\Server\Folder\Full\%datestamp%\ /MOV "%datestamp%_Full_Backup.log"
exit
Incremental Backup which is scheduled to run every day.
Code:
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
robocopy \\Server\Share\Folder\ \\Server\Folder\Icremental\%datestamp%\Folder /S /MAXAGE:1 /XD /XF /COPYALL /LOG+:"\\Server\Folder\%datestamp%_Incremental_Backup.log"
robocopy \\Server\Share\Folder2\ \\Server\Folder\Incremental\%datestamp%\Folder2 /S /MAXAGE:1 /XD /XF /COPYALL /LOG+:"\\Server\Folder\%datestamp%_Incremental_Backup.log"
robocopy \\Server\Share\Folder3\ \\Server\Folder\Incremental\%datestamp%\Folder3 /S /MAXAGE:1 /XD /XF /COPYALL /LOG+:"\\Server\Folder\%datestamp%_Incremental_Backup.log"
Robocopy \\Server\Folder\ \\Server\Folder\Incremental\%datestamp%\ /MOV "%datestamp%_Incremental_Backup.log"
exit
This seems to do what I want but open to suggestions on anyway my code could be improved.
My question and reason for posting this thread, is that I'd like to be able to compress the source folders and files and put them into the destination directory as a .zip file named as the current date to reduce disk space as at the moment I'm taking a direct copy of the source files and some of them are GB in size rather than MB.
I have found the following code below that compresses what's in the destination folder but I want to link it my two scripts above so that it compresses on the go but don't know how to. It also compresses each folder individually where as I'd like it to just zip everything together as one zip file. The code would need to be told to run from the \\server\folder\full\%datestamp%\ (or \\server\folder\Incremental\%datestamp%\) folder too. If possible I'd like it to only robocopy the compressed versions to the source and save the zip file as %datestamp%.zip otherwise I'd end up with compressed and non-compressed files and folders in the same directory which is double the disc space.
Code:
for /d %%X in (*) do "c:\7Zip\7za.exe" a "%%X.zip" "%%X\"
Thanks for any help.