Advertisement
Guest User

backup.bat

a guest
May 17th, 2012
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. REM Filename: backup.bat
  3. REM Version: W0.1
  4. REM Description: minecraft automated backup script
  5. REM Usage: set script, source, and backup variables
  6. REM place backup.bat into directory where you intend it to remain
  7. REM set the worlds to backup (on line 39)
  8. REM OPTIONAL: change the backup name formatting
  9. REM double click the file once... done
  10. REM at this point don't move the batch file or the scheduled task will not know where it is located
  11. REM if moved run this command: SCHTASKS /Delete /TN "Minecraft Backup" /F
  12. REM and run backup.bat again from its new location
  13. REM Requirements: MS Vista or newer (XP or earlier might not have all the commands)
  14.  
  15. REM script variable to be set to the directory this batch file is located in
  16. set script=C:\Users\username\servers
  17. REM source variable to be set to the lowest common directory of all minecraft world folders
  18. set source=C:\Users\username\servers
  19. REM backup variable to be set to the location where backups are to be stored
  20. set backup=C:\Users\username\servers\backup
  21. REM WARNING: by default folders in the backup directory are deleted after 2 days
  22. REM spaces are okay in folder names
  23.  
  24. schtasks /query /tn "Minecraft Backup">nul
  25. if errorlevel 1 (
  26. REM to change backup interval modify the number after /ri
  27. REM /ri [backup interval in minutes]
  28. REM default is hourly backups
  29. schtasks /create /tn "Minecraft Backup" /ru SYSTEM /sc DAILY /ri 60 /du 24:00 /tr "%script%\backup.bat"
  30. )
  31.  
  32. REM by default backups are deleted after 2 days
  33. REM to change when backups are delete modify the number after /d -
  34. REM /d -[n days to keep old backups]
  35. forfiles /p "%backup%" /d -2 /c "cmd /c rd /q /s @path"
  36. REM if you do not want to delete old backups add REM to the beginning of the line above
  37.  
  38. REM set the worlds between the parentheses below (location relative to source variable)
  39. for %%a in (\yourServer1\world1 \yourServer2\world2) do (
  40. REM separate worlds with one space
  41. for /f "tokens=2-4 delims=/ " %%b in ('echo %date%') do call:setdate %%d %%b %%c
  42. for /f "tokens=1-3 delims=:." %%e in ('echo %time%') do call:settime %%e %%f %%g
  43. call:copy %%a
  44. )
  45. goto end
  46.  
  47. :setdate
  48. REM the line below is to change the formatting of the date (default: YYYY-MM-DD)
  49. set dvar=%1-%2-%3
  50. goto end
  51.  
  52. :settime
  53. REM the line below is to change the formatting of the time (default: hh.mm.ss)
  54. if %1 LEQ 9 (set tvar=0%1.%2.%3) else set tvar=%1.%2.%3
  55. goto end
  56.  
  57. :copy
  58. REM the line below is to set the rest of the backup name formatting (default: world_YYYY-MM-DD_hh.mm.ss)
  59. set filename=%~nx1_%dvar%_%tvar%
  60. if exist "%source%%1" (
  61. xcopy /e /h /q /g /j "%source%%1\*" "%backup%\%filename%\%~nx1\*"
  62. )
  63. if exist "%source%%1_nether" (
  64. xcopy /e /h /q /g /j "%source%%1_nether\*" "%backup%\%filename%\%~nx1_nether\*"
  65. )
  66. if exist "%source%%1_the_end" (
  67. xcopy /e /h /q /g /j "%source%%1_the_end\*" "%backup%\%filename%\%~nx1_the_end\*"
  68. )
  69. goto end
  70.  
  71. :end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement