Advertisement
kapott

backup.cmd

Jan 24th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @ECHO off
  2. SETLOCAL ENABLEEXTENSIONS
  3. SET me=%~n0
  4. SET parent=%~dp0
  5.  
  6. :configurables
  7. SET _srvname_=yourservernamehere
  8. SET _compressioncmd_=7z a -r -tzip -bb0 -mx5
  9.  
  10. :set_backup_filename_tags
  11. SET _date_=%date:~3,10%
  12. :: getting 24h timestamp in windows...
  13. SET hour=%time:~0,2%
  14. IF "%hour:~0,1%" == " " (SET hour=0%time:~1,1%)
  15. SET mins=%time:~3,2%
  16. SET secs=%time:~6,2%
  17. SET stamp=%hour%%mins%%secs%
  18. SET tag=%_srvname_%_%_date_%_%stamp%
  19.  
  20. :set_dirs
  21. SET srvdir=%cd%
  22. cd ..
  23. SET backupdir=%cd%\backups\%_srvname_%
  24. SET tempdir=%temp%\%tag%
  25.  
  26. :copy_to_temp
  27. ECHO [%me%] Copying server to temp dir...
  28. xcopy /q /f /e /i %srvdir% %tempdir% > nul
  29.  
  30. :compress
  31. ECHO [%me%] Compressing the copied server files..
  32. %comspec% /Q /C %_compressioncmd_% %backupdir%\%tag%.zip %tempdir%\*.* > nul
  33.  
  34. :cleanup
  35. ECHO [%me%] Removing temp files..
  36. rmdir %tempdir% /s /q
  37.  
  38. IF /I "%ERRORLEVEL%" NEQ "0" (goto error_compression) else (goto done)
  39.  
  40. :error_compression
  41. ECHO [%me%] An error occurred whilst trying to compress!
  42. EXIT /B 1
  43.  
  44. :done
  45. ECHO [%me%] All done! Backup file created: %backupdir%\%tag%.zip
  46. exit /B 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement