justhink

AutoBackup - Update

May 21st, 2011
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. color 0c
  3. MODE CON: COLS=50 LINES=11
  4. echo ***************************************
  5. echo Auto SystemState Backup with Retention
  6. echo Log Archive and Mail Notification
  7. echo Code By : Saugata Datta
  8. echo ~~~
  9. echo (c) http://technochat.in
  10. echo Date: %DATE%, Time: %TIME%
  11. echo ***************************************
  12. ::Backup Settings START
  13. ::Map Network Share
  14. set mapdrivename=H:
  15. set mapdrivepath=\\server\share
  16. set mapdriveuser=user
  17. set mapdrivepass=password
  18. ::Set Backup Path
  19. ::~~~~~~~~~~~~~~~~~~~~
  20. set savepath=D:\TestBackup
  21. ::Set Backup Name
  22. ::~~~~~~~~~~~~~~~~~~~~
  23. set backupname=SysBackup
  24. ::Set Backup Retention Period(in days)
  25. ::~~~~~~~~~~~~~~~~~~~~
  26. set retention=3
  27. ::Set Log Archive Path(Only Folder Name)
  28. ::~~~~~~~~~~~~~~~~~~~~
  29. set logarchivepath=BackupLog
  30. ::If 'yes' then backup log retention will enabled
  31. ::~~~~~~~~~~~~~~~~~~~~
  32. set logretention=yes
  33. ::If avove settings is "yes" then set log Retention Period(in days)
  34. ::~~~~~~~~~~~~~~~~~~~~
  35. set logretentionperiod=3
  36. ::----------x---------
  37. ::E-Mail Settings (SMTP without authentication will work)
  38. ::----------x---------
  39. ::If 'yes' a mail will be fired after backup
  40. ::~~~~~~~~~~~~~~~~~~~~
  41. set _mailnotification=yes
  42. ::If 'yes' backup log will attached with mail
  43. ::~~~~~~~~~~~~~~~~~~~~
  44. set attachment=no
  45. ::Type your e-mail address(for multiple e-mail ID, use ',')
  46. ::~~~~~~~~~~~~~~~~~~~~
  47. set email=saugata.datta@technochat.in
  48. :: Type from mail ID
  49. ::~~~~~~~~~~~~~~~~~~~~
  50. set from=%computername%@FC-Auto-NTBackUP
  51. ::Set SMTP Server IP Address
  52. ::~~~~~~~~~~~~~~~~~~~~
  53. set mserver=10.0.0.6
  54. ::Backup Settings END
  55. ::--------------------------------
  56. ::Don't change following lines.
  57. ::--------------------------------
  58. forfiles -p "%savepath%" /m *.bkf /s /d -%retention% /c "cmd /C del @FILE"
  59. :: get the date and time and then into single variable
  60. for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
  61. set MM=%%j
  62. set DD=%%k
  63. set YYYY=%%l
  64. set date=%%k-%%j-%%l
  65. set dirdate=%%j%%k%%l
  66. )
  67. for /f "Tokens=1-2 delims=/ " %%i in ('time /t') do (
  68. set tm=%%i
  69. set ampm=%%j
  70. )
  71. ::Deleting Old Backup Log files
  72. if not exist "%SystemDrive%%HOMEPATH%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\*.log" goto _nodel
  73. del "%SystemDrive%%HOMEPATH%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\*.log" >nul
  74. :_nodel
  75. ntbackup.exe backup systemstate /v:no /r:no /rs:no /hc:off /J %backupname% /l:s /f "%savepath%\%backupname%_%computername%_%date%.bkf"
  76. net use %mapdrivename% "%mapdrivepath%" /USER:%mapdriveuser% %mapdrivepass%
  77. copy "%savepath%\%backupname%_%computername%_%date%.bkf" %mapdrivename%\
  78. net use %mapdrivename% /delete >nul
  79. if not exist "%savepath%\%logarchivepath%" md "%savepath%\%logarchivepath%" >nul
  80. move "%SystemDrive%%HOMEPATH%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\*.log" %savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt >nul
  81. if not "%_mailnotification%" == "yes" goto _end
  82. if not "%attachment%" == "yes" goto _noattach
  83. blat "%savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt" -attach "%savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt" -to %email% -s "NT Backup Success/Failure Report of %computername%" -f "%from%" -server "%mserver%" > nul
  84. goto _skip
  85. :_noattach
  86. blat "%savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt" -to %email% -s "NT Backup Success/Failure Report of %computername%" -f "%from%" -server "%mserver%" > nul
  87. :_skip
  88. if not "%logretention%" == "yes" goto _end
  89. forfiles -p "%savepath%\%logarchivepath%" /m *.txt /s /d -%logretentionperiod% /c "cmd /C del @FILE"
  90. :_end
  91. exit
RAW Paste Data