Backup DHCP on Windows Server 2012

@echo off

SET srv=10.0.0.199
SET backup_dir=c:\dhcp
SET ESMTPSRV=mail.yourserver.ru
SET EFROM="[email protected]"
SET ESUBJ="[DHCP_BACKUP]"
SET ETO="[email protected]"

path=%path%;"%programfiles%\7-Zip";"%backup_dir%";"%backup_dir%\gnu"
SET year=%DATE:~6,4%
SET month=%DATE:~3,2%
SET day=%DATE:~0,2%
SET today=%year%-%month%-%day%
SET BKPFILE=backup_dhcp_%srv%_%today%.7z

cd /D %backup_dir%
mkdir archive

netsh dhcp server %srv% dump > %backup_dir%\dhcpcfg_%srv%.dmp
7z a %backup_dir%\%BKPFILE% %backup_dir%\dhcpcfg_%srv%.dmp
echo "< b>%today% DHCP Server [%srv%] backup< br>Recovery command: netsh exec dhcpcfg.dmp< pre>" > %backup_dir%\diff.txt
diff -u %backup_dir%\dhcpcfg_%srv%.dmp %backup_dir%\dhcpcfg_prev.dmp >> %backup_dir%\diff.txt
echo "\< /pre>" >> %backup_dir%\diff.txt
del %backup_dir%\dhcpcfg_prev.dmp
move %backup_dir%\dhcpcfg_%srv%.dmp %backup_dir%\dhcpcfg_prev.dmp

::blat -server %ESMTPSRV% -f %EFROM% -to %ETO% -html -s "%ESUBJ% %today%" -body "%today%" -attach %BKPFILE%
blat %backup_dir%\diff.txt -server %ESMTPSRV% -f %EFROM% -to %ETO% -html -s "%ESUBJ% %srv% : %today%" -attach %BKPFILE%

del %backup_dir%\dhcpcfg_%srv%.dmp
del %backup_dir%\diff.txt
move %backup_dir%\*.7z %backup_dir%\archive\

:: backup recovery: netsh exec dhcpcfg.dmp