Advertisement
Guest User

Untitled

a guest
Mar 5th, 2011
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 34.93 KB | None | 0 0
  1. @ECHO OFF
  2. TITLE Minecraft AutoBackup Utility
  3. ECHO Waiting 30 seconds before starting backup.
  4. SLEEP 30
  5. ::By Dateranoth - August 28, 2010
  6. ::Addition of Overviwer thanks to instinx
  7. ::Timer Script, Variables and base idea thanks to MonkeyDKS
  8. ::Original AutoBackup by MonkeyDKS found here-
  9. ::http://www.minecraftforum.net/viewtopic.php?f=10&t=25967
  10. ::Used by http://www.gamercide.org on their server.
  11. ::Feel free to change, adapt, and distribute
  12. ::Download packaged backup and restore batch, and vbs script file here-
  13. ::http://www.dateranoth.com/gamercide/mcbackuppackage.zip
  14.  
  15. ::V1.0-This backup utility prefers you have Sleep EXE available at this website--------::
  16. ::----http://www.computerhope.com/dutil.htm - However, this is not a necessary file.---::
  17. ::-------------------------------------------------------------------------------------::
  18. ::----Either winrar or 7-zip archiving files - 7z.exe or rar.exe are required!---------::
  19. ::----Place either 7z.exe or rar.exe In the Backup Directory That you set below.-------::
  20. ::-------------------------------------------------------------------------------------::
  21. ::----7zip is a free utility found here - http://www.7-zip.org/ -----------------------::
  22. ::----The 7z.exe will be located in the directory you installed 7-zip to.--------------::
  23. ::-------------------------------------------------------------------------------------::
  24.  
  25. ::V1.1-Added ability to use Cartographer to generate map images for each backup--------::
  26. ::----Cartographer can be found here:--------------------------------------------------::
  27. ::----http://www.minecraftforum.net/viewtopic.php?f=25&t=13134-------------------------::
  28. ::-------------------------------------------------------------------------------------::
  29.  
  30. ::V1.2-Added VBS Script file to force save-all before backup---------------------------::
  31. ::----VBS Script can be downloaded @ http://www.dateranoth.com/gamercide/saveall.zip----::
  32. ::-------------------------------------------------------------------------------------::
  33.  
  34. ::V1.3-Added delay before execution of Cartograph do to lock ups when starting too fast::
  35. ::----Added check for temporary folder before backup starts. Will remove the folder----::
  36. ::----if found in case of mid backup crashes, etc.-------------------------------------::
  37. ::----Fixed comment lines and added comments to each section. Changed some formatting--::
  38. ::-------------------------------------------------------------------------------------::
  39.  
  40. ::V1.4-Added check for temporary file that was locking up Cartograph-------------------::
  41. ::----If found, deletes tmp file before running Cartograph-----------------------------::
  42. ::----Previous timer for Cartograph reduced. Lock ups were probably the temp file the--::
  43. ::----entire time.  Timer left in for a just in case measure---------------------------::
  44. ::----Added line in Variable to change the map type that Cartograph creates------------::
  45. ::----Will need to refer to Cartograph Readme.txt for options otherwise set to normal--::
  46. ::-------------------------------------------------------------------------------------::
  47.  
  48. ::V1.5-Added Minecraft Overviewer Option for mapping-----------------------------------::
  49. ::----Edited by instinx - smithtec(AT)gmail.com----------------------------------------::
  50. ::----October 6th, 2010 - Added Option for using Minecraft Overviewer------------------::
  51. ::----http://github.com/brownan/Minecraft-Overviewer-----------------------------------::
  52.  
  53. ::V1.6-Cleaned up a lot of code. Added option to only run Overviewer after a certain----::
  54. ::-----amount of time.  Instructions for Overviewer found in User Variables-------------::
  55.  
  56. ::V1.7-Added ability to use WinSCP FTP to upload Overviewer map to remote website-------::
  57. ::-----Runs a Synchronize command so only files that have changed will be uploaded------::
  58. ::-----Also cleaned up some more code and rearranged User Variables.--------------------::
  59. ::-----Download WinSCP Here: http://winscp.net : Required for FTP Upload but Free App---::
  60.  
  61. ::V1.8-MAJOR UPDATE!  Added option to use Incremental Updates.  Incremental updates-----::
  62. ::-----greatly reduce total backup time and space.  Incremental updates store one master::
  63. ::-----backup file in a dated directory.  Then dated incremental updates of only changes::
  64. ::-----are produced on the next backup run.  The very first run will create Cache files-::
  65. ::-----of both the world directory and the compressed backup in your backup directory.--::
  66. ::-----They will be used to produce incremental updates without recopying the full world::
  67. ::-----directory or recompressing the full directory.  They will only be deleted if the-::
  68. ::-----backup script detectes a restored backup.  This is done by a folder named--------::
  69. ::-----_IncrBackupRestored being created in the archives. If you restore a backup it----::
  70. ::-----will be placed in your world folder so the backup script will know to purge the--::
  71. ::-----cache.  Otherwise you can manually delete the files in IncrBackupCache to force--::
  72. ::-----what is basically a full backup to be done.  I'm working on a simple restore-----::
  73. ::-----script, but for now you must first extract the IncrMaster_Worldname.7z and then--::
  74. ::-----extract, in order overwriting existing files the incr_# until you get to the time::
  75. ::-----you wish to restore.  Everytime you restart the script or restore a backup a new-::
  76. ::-----dated folder is created with a new master and it's own set of incremental backups::
  77. ::-----**************************IMPORTANT READ BELOW****************************-------::
  78. ::-----WinRAR is NOT SUPPORTED FOR INCREMENTAL BACKUPS.  You must use the 7-zip method.-::
  79. ::-----With the addition of Incremental backup 7z.exe is no longer REQUIRED to be in----::
  80. ::-----the backup directory, but there now is an option to set the path to the exe------::
  81. ::-----This must be set for either FULL or INCREMENTAL backups to work------------------::
  82. ::-----**************************************************************************-------::
  83. ::-----Additionally I added the option to change how often Cartograph runs, and---------::
  84. ::-----rearranged some of the code for a smoother script. Along with modifications to---::
  85. ::-----check for winrar methods and notify user that Incremental backups are not--------::
  86. ::-----Supported for WinRAR.  7-ZIP is a free program so RAR support seemed uneccessary-::
  87.  
  88. ::V1.9-Name Changed from SMPBackup to MCBackup.  The backup package now includes a------::
  89. ::-----script to easily and quickly restore backups.  Refer to it for directions.-------::
  90. ::-----http://www.dateranoth.com/gamercide/MCRestore.zip--------------------------------::
  91.  
  92. ::V2.0-Modified the way batch captures time/date from system.  Added the ability to-----::
  93. ::-----change the date format.  Refer to User Variables for more information------------::
  94.  
  95. ::V2.1-Added a max incremental count.  This counter will create X number of incremental-::
  96. ::-----backups before starting a new folder and master file.  This is so users who use--::
  97. ::-----regular incremental backups can create a new master folder daily or whenever.----::
  98. ::-----Which will in turn make restoring much easier and faster. If you do not wish to--::
  99. ::-----use the feature then set it to a very high number. ie. 9999999-------------------::
  100.  
  101. ::V2.2-Added option to change ftp protocol when uploading Overviewer map----------------::
  102. ::-----Also, note that yes/no variables are case sensitive. They need to be lowercase---::
  103.  
  104. ::V2.3-Added option to set ftp open Switches. Useful for enabling -passive mode in ftp--::
  105. ::-----Also made yes/no variables case insensitive.  Case no longer matters.------------::
  106.  
  107. ::V2.4-Added double quotes around FTP usernames and passwords.  Common @ symbols in-----::
  108. ::-----user names were messing up the script.  Should work with these now. Added option-::
  109. ::-----to wait for X seconds before running backup after server save-all. This will-----::
  110. ::-----make sure servers with lots of changes have time to finish saving before the-----::
  111. ::-----files are copied and compressed.-------------------------------------------------::
  112.  
  113. ::V2.5-Added backup of Minecraft Server directory files.  Only the files, and not the---::
  114. ::-----directories in your Server Directory will be copied into the backup world in a---::
  115. ::-----folder call _ServerFiles.  This way you will have the configs if you have a crash::
  116. ::-----or need to restore when using mods/etc.  There is also the option to use an------::
  117. ::-----exclude file.  This file contains files or filetypes (one per line) that you-----::
  118. ::-----don't wish to have backed up.  I have included a default one that skips .jar .bat::
  119. ::-----and .vbs.  You can choose to use it or not.  Default is to back up all files.----::
  120.  
  121. ::V2.6-Added backup of entire Minecraft Server Directory. Refer to Variables below for -::
  122. ::-----options an instructions.  Also added option to upload backups to FTP directory.--::
  123. ::-----These have been completely seperated in case overviewer and your other backups---::
  124. ::-----reside one two different servers.  Refer to the variables for instructions.------::
  125.  
  126. ::V2.7-Fixed Incremental FTP uploads.  The ftp folder is now successfully created.------::
  127. ::-----Allowing ftp backup to work as it should for incremental backups.  Also fixed----::
  128. ::-----remote backup directory option.  Wasn't placing backup in correct directory.-----::
  129. ::-----If using FTP upload of backup, incremental backups with a very large max is------::
  130. ::-----recommended.  This way the first backup will be large and take time uploading----::
  131. ::-----but the following incremental backups will be much smaller and save time and-----::
  132. ::-----bandwidth.-----------------------------------------------------------------------::
  133.  
  134. ::V2.8-Updated saveall.vbs to V1.2 - Condensed Keystroke Commands & Added Server--------::
  135. ::-----Backup notification. Download at www.gamercide.org/minecraft/MCBackup/saveall.zip::
  136. ::-----Change Cartograph to Cartograph G to support the new save format. Can be found at::
  137. ::-----http://www.minecraftforum.net/viewtopic.php?f=1022&t=165779&hilit=Cartograph+G --::
  138. ::-----Please refer to Readme.txt included with Cartograph G for map render settings----::
  139. ::-----Added option to change output directory of the Cart maps. Default is BackupDIR---::
  140.  
  141. ::-----------------------------------------------------------------------------------::
  142. ::----------------User Variables - Change these to fit your situation----------------::
  143. ::-----------------------------------------------------------------------------------::
  144.  
  145. ::Set to use Incremental Backup.  Only supports 7zip compression method. (yes or no)
  146. ::Incremental will create one base file and then only the changed updates from that point forward in 7-zip format.
  147. ::In order to restore the world you MUST extract the base file and then the changes in order until the date/time you wish to restore is reached.
  148. SET UseIncr=yes
  149.  
  150. ::Set to the number of Incremental Backups you would like created before a new folder and master file is created.
  151. ::If you multiply this number by your backup Time you will get the amount of time between new incremental folder creation.
  152. ::ie. Backup time of 10 minutes, and an Incremental Backup # of 6 would create a new master and folder every 60 minutes.
  153. SET IncrCounterMax=24
  154.  
  155. ::Set Server Directory (The folder your "World" folder lives in...NOT the path inside your world folder)
  156. SET WorldDIR=R:\
  157.  
  158. ::Set World Name (Copy your World Folder name here)
  159. SET WorldNAM=craftbukkit
  160.  
  161. ::Set Backup Directory (Where do you want to save your backups?)
  162. SET BackupDIR=G:\minecraft backup
  163.  
  164. ::Set Time between Backups (in minutes)
  165. SET Timer=30
  166.  
  167. ::Set Compression Method (rar or 7zip)
  168. SET Method=7zip
  169.  
  170. ::Set Directory for 7z.exe
  171. SET _7zipdir=C:\Program Files\7-Zip
  172.  
  173. ::Set the format you would like the date to appear on backup files. Default is year(%%g)-month(%%e)-day(%%f). Your windows time format may differ.
  174. :: If it does or you would like something different then rearrange the parameters below until satisfied. Results will be format1-format2-format3
  175. SET dateformat1=%%g
  176. SET dateformat2=%%e
  177. SET dateformat3=%%f
  178.  
  179. ::You now have the option to backup your ENTIRE Minecraft Server Directory.
  180. ::All files will be found in your BackupDIR under the chosen WorldNAM ( Including the world itself ).
  181. ::Would you like to backup the entire Minecraft Server Directory? (yes or no)
  182. SET BackupAll=no
  183.  
  184. ::If you chose to Backup your Entire Server directory then you can use the exclude file to not backup certain files/folders.
  185. ::Would you like to exclude some of the files or folders? (yes or no)
  186. SET UseExcl=no
  187.  
  188. ::Set the filename of the file containing a list of files you would like to exclude.
  189. ::File must be located in same directory as MCBackup.bat
  190. ::Each excluded item should be on a seperate line.
  191. ::Filetypes and directoreis are accepted ie. .jar \world\
  192. SET excludefile=exclude.txt
  193.  
  194. ::Would you like to use the VBS file to force a save-all to your server? yes or no
  195. SET UseVBS=yes
  196.  
  197. ::Set directory where saveall.vbs is located
  198. SET VBSDir=R:\craftbukkit\backupscripts2.5
  199.  
  200. ::Set how long you would like to wait for Minecraft Server to finish save-all before backing up.
  201. ::Maps with lots of players and changes occuring will need more time than maps
  202. ::with only a few players and changes.  (Time in Seconds, 0 to start immediately)
  203. SET VBSDelay=5
  204.  
  205. ::Will you be using Sleep.exe? (yes or no)
  206. SET UseSleep=yes
  207.  
  208. ::Set Sleep EXE directory if using Sleep.exe
  209. SET SleepExe=C:\windows\system32
  210.  
  211. ::Would you like to use Cartographer to map your backups? yes or no
  212. SET UseCart=no
  213.  
  214. ::Set directory where Cartograph_G_Renderer.exe is located
  215. SET CartDIR=C:\minecraft\cartographer
  216.  
  217. ::Set the directory where you would like the maps output to. Default is your Backup directory.
  218. SET CartOutputDIR=%BackupDIR%
  219.  
  220. ::Set Cartograph G map type. Refer to Cartograph G Readme.txt for more info or leave at default setting.
  221. ::Note that the old Cartograph defaulted east as up.  If you wish to keep this, change north to east.
  222. SET CartMap=normal day north
  223.  
  224. ::Set how often you would like Cartograph G to be ran. (in minutes) Minimum is the time between backups.
  225. ::Will only be ran when a backup runs. ie. If your backup time is every 30 minutes, then Cartograph
  226. ::can be set to run every 30 minutes, 1 hour, 1 hour and 30 minutes, 2 hours, etc.
  227. ::Odd times will round forward, running after the time has been met but not until the backup starts.
  228. ::Time can be different from Overviewer Time.
  229. SET CartTimer=240
  230.  
  231. ::Set to 0 if you DON'T want Cartograph to run when the batch file is initially opened.
  232. SET CartFirstRun=1
  233.  
  234. ::Would you like to use Overviewer to map your backups? First run can take a LONG time. (yes or no)
  235. SET UseOVWR=no
  236.  
  237. ::Which method of Overviewer?  Windows Executable or Python Script? (exe or python)
  238. SET OVWRmethod=exe
  239.  
  240. ::Set directory where Overviewer is located
  241. SET OVWRDIR=C:\minecraft\Overviewer-0.0.5
  242.  
  243. ::Set Overviewer Image Directory (Overviewer Output)
  244. SET OVWROUTDIR=G:\minecraft overviewer\output\buildworld
  245.  
  246. ::Set Overviewer CACHE Directory (Where Overviewer Cache files are stored)
  247. SET OVWRCACHEDIR=G:\minecraft overviewer\cache\buildworld
  248.  
  249. ::How many processors should Overviewer Use? (This should be set low or it will cause lag on the server)
  250. SET Procs=2
  251.  
  252. ::Set how often you would like Overviewer to be ran. (in minutes) Minimum is the time between backups.
  253. ::Will only be ran when a backup runs. ie. If your backup time is every 30 minutes, then Overviewer
  254. ::can be set to run every 30 minutes, 1 hour, 1 hour and 30 minutes, 2 hours, etc.
  255. ::Odd times will round forward, running after the time has been met but not until the backup starts.
  256. ::Time can be different from Cartograph Time.
  257. SET OVWRTimer=480
  258.  
  259. ::Set to 0 if you DON'T want Overviwer to run when the batch file is initially opened.
  260. SET OVWRFirstRun=1
  261.  
  262. ::Would you like to use WinSCP FTP to upload the Minecraft Server backup files to a web server? (yes or no)
  263. ::If connecting to a secure ftp the first run will ask you to save the key to cache.
  264. ::Once saved it will run automatically without user input from that point on.
  265. :: If yes, please refer to 'Backup Files to FTP Options' below
  266. SET useftp=no
  267.  
  268. ::Would you like to use WinSCP FTP to upload the Overviewer map to a web server? (yes or no)
  269. ::If connecting to a secure ftp the first run will ask you to save the key to cache.
  270. ::Once saved it will run automatically without user input from that point on.
  271. :: If yes, please refer to 'Overviewer Map FTP Options' below
  272. SET OVWRuseftp=no
  273.  
  274. ::WinSCP is required if using FTP.  Please set the path to WinSCP
  275. SET ftpwinscpdir=C:\program files (x86)\winscp
  276.  
  277. ::-------Start Backup Files to FTP Options-------::
  278.  
  279. ::Set your ftp Protocol (ftp or sftp or scp)
  280. SET ftpprotocol=ftp
  281.  
  282. ::This is where you can set WinSCP switches for connecting. Refer to http://winscp.net/eng/docs/script_commands#open for details.
  283. ::Main uses are to leave blank for default OR -passive for ftp protocol passive mode.
  284. SET ftpswitch=
  285.  
  286. ::Set your ftp address here WITHOUT ftp:// (site:port)
  287. SET ftpurlport=yourftp.com:21
  288.  
  289. ::Set the login name for your FTP.
  290. SET ftploginname=yourftploginname
  291.  
  292. ::Set the password for your FTP.
  293. SET ftploginpass=yourftppass
  294.  
  295. ::Set the max upload bandwidth you want WinSCP to use (kibps)
  296. SET ftpspeed=60
  297.  
  298. ::Set your REMOTE ftp directory for placing the backup files. (Full Remote Path)
  299. SET ftpdirectory=/home/WWW/minecraft
  300.  
  301. ::-------End Backup Files to FTP Options------::
  302.  
  303. ::-------Start Overviewer Map FTP Options-----::
  304.  
  305. ::Set your ftp Protocol (ftp or sftp or scp)
  306. SET OVWRftpprotocol=ftp
  307.  
  308. ::This is where you can set WinSCP switches for connecting. Refer to http://winscp.net/eng/docs/script_commands#open for details.
  309. ::Main uses are to leave blank for default OR -passive for ftp protocol passive mode.
  310. SET OVWRftpswitch=
  311.  
  312. ::Set your ftp address here WITHOUT ftp:// (site:port)
  313. SET OVWRftpurlport=yourftp.com:21
  314.  
  315. ::Set the login name for your FTP.
  316. SET OVWRftploginname=yourftploginname
  317.  
  318. ::Set the password for your FTP.
  319. SET OVWRftploginpass=yourftppass
  320.  
  321. ::Set the max upload bandwidth you want WinSCP to use (kibps)
  322. SET OVWRftpspeed=60
  323.  
  324. ::Set your REMOTE ftp directory for Overviewer. Should be base directory containing index.html. (Full Remote Path)
  325. SET OVWRftpdirectory=/home/WWW/minecraft
  326. ::-------End Overviewer Map FTP Options-----::
  327.  
  328.  
  329. ::------------------------------------------------------------------------------------------------------------------------------::
  330.  
  331. ::!!!!!!!!!!!!!!!!DON'T TOUCH BELOW HERE unless you know Batch (And are willing to lower yourself to that level)!!!!!!!!!!!!!!!!::
  332.  
  333. ::------------------------------------------------------------------------------------------------------------------------------::
  334. ::Set Overviewer and Cartograph Counter to 0 on first run.
  335. SET RemainingOVWRTimer=0
  336. SET RemainingCartTimer=0
  337. ::Set variables for Incremental backup.
  338. SET IncrBootRun=1
  339. SET IncrCounter=0
  340. ::Set variables for excluding files from Server Directory
  341. IF /i %UseExcl%==yes (SET exclude=/exclude:%excludefile%) ELSE (SET exclude=)
  342.  
  343. ::Below Checks to make sure the proper Method is there and the files can be located for compression. If not, stops backup before it starts.
  344. :Methodtest
  345. IF /i %Method%==7zip (goto 7zip) ELSE IF /i %Method%==rar (goto rar) ELSE (goto methodwrong)
  346.  
  347. ::Notifies the user that an invalid compression method was selected. Then exits.
  348. :methodwrong
  349. ECHO You have entered an invalid Method (Currently %Method%) Must be rar or 7zip
  350. ECHO Change the Method and then restart the batch file to continue with Backup.
  351. pause
  352. exit
  353.  
  354. ::RAR method detected. Check to see if its FULL or INCREMENTAL backup method.
  355. :rar
  356. IF /i %UseIncr%==yes (goto rarINCR) ELSE (goto rarFULL)
  357.  
  358. ::RAR is not supported for Incremental backups.  Notify user and exit.
  359. :rarINCR
  360. ECHO Current method of backup is %Method% .  %Method% is not supported for incremental backups.
  361. ECHO.
  362. ECHO Either change to 7zip method or Change to Full backups and restart script.
  363. pause
  364. exit
  365.  
  366. ::Checks for the rar.exe before continuing with backup
  367. :rarFULL
  368. IF EXIST "%BackupDIR%\rar.exe". (goto start) ELSE (goto rarbad)
  369.  
  370. ::Checks for the 7z.exe before continuing with backup
  371. :7zip
  372. IF EXIST "%_7zipdir%\7z.exe". (goto start) ELSE (goto 7zipbad)
  373.  
  374. ::Notifies user that winrar was selected but no rar.exe was found.
  375. :rarbad
  376. Echo rar.exe not found. Please Place rar.exe in the BackupDIR (Currently: %BackupDIR%)
  377. Echo and restart script to continue with Backup.
  378. pause
  379. exit
  380.  
  381. ::Notifies user that 7-zip was selected but no 7z.exe was found.
  382. :7zipbad
  383. Echo 7z.exe not found. Current location %_7zipdir% . Please update location and restart script  
  384. Echo to continue with Backup.
  385. pause
  386. exit
  387.  
  388. ::Resets timer and Checks for BackupMethod
  389. :start
  390.  
  391. SET RemainingTimer=%Timer%
  392. echo.
  393. echo Starting Back up of MineCraft World - %WorldNam%
  394. echo.
  395. IF /i %UseIncr%==yes (goto VBScheck) ELSE (goto startfull)
  396.  
  397. ::Checks for old temporary directory
  398. :startfull
  399. IF EXIST "%BackupDIR%\%WorldNam%\" (goto tempcleanup) ELSE (goto VBScheck)
  400.  
  401. ::Removes Temporary world folder if found.
  402. :tempcleanup
  403. echo Old Temporary folder found.
  404. echo Deleting Temporary Folder before backup.
  405. rd /s/q "%BackupDIR%\%WorldNAM%"
  406. goto VBScheck
  407.  
  408. ::Checks to see if Script for forcing server save is enabled
  409. :VBScheck
  410. IF /i %UseVBS%==yes (goto VBS) ELSE (goto backupmethod)
  411.  
  412. ::Uses VBS Script to force command input of save-all into server
  413. :VBS
  414. echo Forcing Server to save world
  415. cd /d "%VBSDir%"
  416. saveall.vbs
  417. IF %VBSDelay% LEQ 0 (echo.) ELSE (ECHO Waiting for %VBSDelay% seconds before starting backup)
  418. IF %VBSDelay% LEQ 0 (goto backupmethod) ELSE IF /i %UseSleep%==yes (%SleepEXE%\sleep.exe %VBSDelay%) ELSE (PING -n %VBSDelay% 127.0.0.1 >nul)
  419. goto backupmethod
  420.  
  421. ::Check to see which backup method should be used. Full or Incremental.
  422. :backupmethod
  423. IF /i %UseIncr%==yes (goto startincr) ELSE (goto tempcopy)
  424.  
  425. ::-----------START INCREMENTAL BACKUP CODE------------------------::
  426. ::Check to see if this is the intial Incremental run.
  427. :startincr
  428. ::SET WorldNamDate=%WorldNAM%-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%---%TIME:~0,2%%TIME:~3,2%
  429. for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%
  430. for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%e
  431. SET WorldNamDate=%worldNAM%-%Date1%---%Time1%
  432. IF %IncrBootRun%==1 (goto incrboot) ELSE IF %IncrCounter% GEQ %IncrCounterMax% (goto incrboot) ELSE IF EXIST "%WorldDIR%\%WorldNam%\_IncrBackupRestored" (goto incrboot) ELSE (goto incrpass)
  433.  
  434. ::Initial Incremental run creates some folders and resets the counter for the incremental backups.
  435. ::Also runs check to see if a world backup has been restored since last run.
  436. :incrboot
  437. ECHO Starting Initial Run of Backup.  New, dated folder will be created and Incr Backups will be stored there until Script restarted.
  438. ECHO.
  439. SET IncrBootRun=0
  440. for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date2=%dateformat1%-%dateformat2%-%dateformat3%
  441. for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time2=%%d%%e
  442. SET WorldNamIncrDate=%worldNAM%-%Date2%---%Time2%
  443. SET IncrCounter=1
  444. md "%BackupDIR%\%WorldNamIncrDate%
  445. IF EXIST "%WorldDIR%\%WorldNam%\_IncrBackupRestored" (goto incrdelworld) ELSE (goto incrfirstpass)
  446.  
  447. ::This is to ensure we don't get crossed files if a backup has been restored. Removes BackupCache thus Forcing recopy of ENTIRE world directory.
  448. ::Also removes tagged folder in worlddir.  Should only reappear if user restores another backup.
  449. :incrdelworld
  450. ECHO Restored Backup found. Must delete cache to insure proper backup.
  451. ECHO.
  452. rd /s/q "%BackupDIR%\IncrBackupCache\%WorldNAM%"
  453. rd /s/q "%WorldDIR%\%WorldNam%\_IncrBackupRestored"
  454. goto incrfirstpass
  455.  
  456. ::First Pass will update Cached world directory and master compressed file.  Also creates Master file in dated folder.
  457. ::Also creates the folder _IncrBackupRestored so it can be checked for after a restored backup.
  458. :incrfirstpass
  459. ECHO This is a new run of backup script.  Updating cache files and creating initial backup.
  460. ECHO.
  461. IF /i %BackupAll%==yes (xcopy "%WorldDIR%" "%BackupDIR%\IncrBackupCache\%WorldNam%" /E/D/I/Q/H/Y %exclude%) ELSE (xcopy "%WorldDIR%\%WorldNam%" "%BackupDIR%\IncrBackupCache\%WorldNam%" /S/I/Q/Y/D)
  462. md "%BackupDIR%\IncrBackupCache\%WorldNam%\_IncrBackupRestored"
  463. "%_7zipdir%\7z.exe" u "%BackupDIR%\IncrBackupCache\IncrMaster_%WorldNam%.7z" -up0q0r2x2y2z1w2 "%BackupDIR%\IncrBackupCache\%WorldNAM%" -ms=off
  464. xcopy "%BackupDIR%\IncrBackupCache\IncrMaster_%WorldNam%.7z" "%BackupDIR%\%WorldNamIncrDate%\" /Q/Y
  465. IF %useftp%==yes (
  466. cd /d "%ftpwinscpdir%"
  467. start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "cd ""%ftpdirectory%/""" "mkdir ""%WorldNamIncrDate%""" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamIncrDate%\IncrMaster_%WorldNam%.7z"" ""%ftpdirectory%/%WorldNamIncrDate%/""" "exit"
  468. )
  469. IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
  470.  
  471. ::Passes after the first one will create Incremental files in the last dated world backup directory.  
  472. ::They will only reflect changes made that differ from the Master file. Thus greatly speeding up the entire process.
  473. :incrpass
  474. for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date3=%dateformat1%-%dateformat2%-%dateformat3%
  475. for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time3=%%d%%e
  476. SET IncrCounterDate=%IncrCounter%__%Date3%---%Time3%
  477. ECHO Updating MineCraft world to working Directory. Only new files will be transferred.
  478. IF /i %BackupAll%==yes (xcopy "%WorldDIR%" "%BackupDIR%\IncrBackupCache\%WorldNam%" /E/D/I/Q/H/Y %exclude%) ELSE (xcopy "%WorldDIR%\%WorldNam%" "%BackupDIR%\IncrBackupCache\%WorldNam%" /S/I/Q/Y/D)
  479. ECHO Compressing New Files to Incr. 7z file.
  480. "%_7zipdir%\7z.exe" u "%BackupDIR%\IncrBackupCache\IncrMaster_%WorldNam%.7z" -up0q0r2x2y2z1w2 -up3q3r2x2y2z0w2!"%BackupDIR%\%WorldNamIncrDate%\incr_#%IncrCounterDate%.7z" "%BackupDIR%\IncrBackupCache\%WorldNam%" -ms=off
  481. SET /a IncrCounter=IncrCounter+1
  482. IF %useftp%==yes (
  483. cd /d "%ftpwinscpdir%"
  484. start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamIncrDate%\incr_#%IncrCounterDate%.7z"" ""%ftpdirectory%/%WorldNamIncrDate%/""" "exit"
  485. )
  486. IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
  487. ::------------END INCREMENTAL BACKUP CODE----------------------------::
  488.  
  489. ::------------START FULL BACKUP CODE---------------------------------::
  490. ::Copies the world folder from the server to a temporary directory for processing. Also Sets the backup file name.
  491. :tempcopy
  492. echo Copying MineCraft world to temporary working Directory
  493. IF /i %BackupAll%==yes (xcopy "%WorldDIR%" "%BackupDIR%\%WorldNam%" /E/I/Q/H/Y %exclude%) ELSE (xcopy "%WorldDIR%\%WorldNam%" "%BackupDIR%\%WorldNam%" /S/I/Q/Y)
  494. cd /d "%BackupDIR%"
  495. ::SET WorldNamDate=%WorldNAM%-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%---%TIME:~0,2%%TIME:~3,2%
  496. for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%
  497. for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%e
  498. SET WorldNamDate=%worldNAM%-%DATE1%---%Time1%
  499. IF /i %Method%==7zip (goto 7zipgood) ELSE IF /i %Method%==rar (goto rargood) ELSE (goto methodtest)
  500.  
  501. ::7z.exe method. Compresses files then waits for 5 seconds using Sleep or Ping
  502. :7zipgood
  503. echo Compressing using 7zip
  504. "%_7zipdir%\7z.exe" a "%BackupDIR%\%WorldNamDate%.7z" "%BackupDIR%\%WorldNAM%"
  505. IF %useftp%==yes (
  506. cd /d "%ftpwinscpdir%"
  507. start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamDate%.7z"" ""%ftpdirectory%/""" "exit"
  508. )
  509. IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
  510.  
  511. ::rar.exe method. Compresses files then waits for 5 seconds using Sleep or Ping
  512. :rargood
  513. cd /d "%BackupDIR%"
  514. echo Compressing using WinRAR
  515. rar.exe a -m5 -- "%WorldNamDate%" "%WorldNAM%"
  516. IF %useftp%==yes (
  517. cd /d "%ftpwinscpdir%"
  518. start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamDate%.rar"" ""%ftpdirectory%/""" "exit"
  519. )
  520. IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
  521. ::---------------------END FULL BACKUP CODE------------------------------::
  522.  
  523.  
  524. ::Delay of 5 seconds added to be sure Files Copied. Sleep method
  525. ::Then checks whether to use Cartograph or Overviewer or neither
  526. :mapdelaysleep
  527. IF /i %UseIncr%==yes (SET TempWorld=%BackupDIR%\IncrBackupCache\%WorldNAM%) ELSE (SET TempWorld=%BackupDIR%\%WorldNAM%)
  528. IF /i %BackupAll%==yes (SET TempWorldDir=%Tempworld%\%WorldNAM%) ELSE (SET TempWorldDir=%TempWorld%)
  529. cd /d %SleepEXE%
  530. sleep 5
  531. IF /i %UseCart%==yes (goto carttimecheck) ELSE IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
  532.  
  533. ::Delay of 5 seconds added to be sure Files Copied.  Ping method.
  534. ::Then checks whether to use Cartograph or Overviewer or neither
  535. :mapdelayping
  536. IF /i %UseIncr%==yes (SET TempWorld=%BackupDIR%\IncrBackupCache\%WorldNAM%) ELSE (SET TempWorld=%BackupDIR%\%WorldNAM%)
  537. IF /i %BackupAll%==yes (SET TempWorldDir=%Tempworld%\%WorldNAM%) ELSE (SET TempWorldDir=%TempWorld%)
  538. PING -n 5 127.0.0.1 >nul
  539. IF /i %UseCart%==yes (goto carttimecheck) ELSE IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
  540.  
  541. ::Check to see if this is first run of batch file. If so, note this and then run cartograph.
  542. ::Otherwise Check to see if cartograph should be ran based on user selected time. If not, skip cartograph this run.
  543. :carttimecheck
  544. IF %CartFirstRun%==1 (goto cartboot) ELSE IF %RemainingCartTimer% GEQ %CartTimer% (goto cartobadfilecheck) ELSE IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
  545.  
  546. :cartboot
  547. SET CartFirstRun=0
  548. goto cartobadfilecheck
  549.  
  550. ::Checks for Temporary File that's been locking up Cartograph
  551. :cartobadfilecheck
  552. IF EXIST "%TempWorldDir%\tmp_chunk.dat" (goto deletebadfile) ELSE (goto cartostart)
  553.  
  554. ::Deletes Temporary File that's been locking up Cartograph
  555. :deletebadfile
  556. del /f "%TempWorldDir%\tmp_chunk.dat"
  557. echo Temporary file that causes Cartograph lockups found and deleted.
  558. goto cartostart
  559.  
  560. ::User selected to use cartograph. Runs Cartograh then checks to see if user would also like to run Overviwer.
  561. :cartostart
  562. echo Creating map image using Cartographer
  563. echo Process may take a long time. Be patient.
  564. echo.
  565. cd /d %CartDIR%
  566. Cartograph_G_Renderer.exe custom "%TempWorldDir%" output "%CartOutputDIR%\%WorldNamDate%.png" %CartMap%
  567. SET RemainingCartTimer=0
  568. IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
  569.  
  570. ::Check to see if this is first run of batch file. If so, note this and then run overviewer.
  571. ::Otherwise Check to see if overviewer should be ran based on user selected time. If not, skip overviewer this run.
  572. :OVWR
  573. IF %OVWRFirstRun%==1 (goto OVWRBoot) ELSE IF %RemainingOVWRTimer% GEQ %OVWRTimer% (goto OVWRStart) ELSE (goto endbackup)
  574.  
  575. :OVWRBoot
  576. SET OVWRFirstRun=0
  577. goto OVWRStart
  578.  
  579. ::User selected to use Overviewer. Should we run the EXE or Python Version?
  580. :OVWRStart
  581. echo Creating map image using OverViewer
  582. echo Process takes a very long time. Get a sandwich.
  583. echo.
  584. IF /i %OVWRmethod%==exe (goto OVWRexestart) ELSE IF /i %OVWRmethod%==python (goto OVWRpythonstart) ELSE (goto OVWRError)
  585.  
  586. ::A method that doesn't exist was entered. We are notified and allowed to continue backup process after input.
  587. :OVWRError
  588. ECHO You have entered an invalid Method (Currently %OVWRmethod%) Must be exe or python
  589. ECHO Change the Method and then restart the backup process or press enter to continue.
  590. pause
  591. goto endbackup
  592.  
  593. ::Python method was selected. Overviewer will now be ran using the selected options. Run timer will then be reset.
  594. :OVWRpythonstart
  595. cd /d %OVWRDIR%
  596. Python gmap.py --cachedir="%OVWRCACHEDIR%" -p "%Procs%" "%TempWorldDir%" "%OVWROUTDIR%"
  597. SET RemainingOVWRTimer=0
  598. IF /i %OVWRuseftp%==yes (goto startftp) ELSE (goto endbackup)
  599.  
  600. ::EXE method was selected. Overviwer will now be ran using selected options. Run timer will then be reset.
  601. :OVWRexestart
  602. cd /d %OVWRDIR%
  603. gmap.exe --cachedir="%OVWRCACHEDIR%" -p "%Procs%" "%TempWorldDir%" "%OVWROUTDIR%"
  604. SET RemainingOVWRTimer=0
  605. IF /i %OVWRuseftp%==yes (goto startftp) ELSE (goto endbackup)
  606.  
  607. ::Attempts to kill WinSCP in case it was still running or stuck from last time.
  608. ::Starting the FTP Upload Process. It is opened as a seperate process and is not waited for because it can take a long time.
  609. :startftp
  610. ECHO Starting FTP Upload of Overviewer. Process will open in a new window and backup batch will continue to run without waiting.
  611. taskkill /im winscp.exe
  612. cd /d "%ftpwinscpdir%"
  613. start winscp.exe /console /command "open %OVWRftpprotocol%://""%OVWRftploginname%"":""%OVWRftploginpass%""@%OVWRftpurlport% %OVWRftpswitch%" "synchronize remote -delete -criteria=both -speed=%OVWRftpspeed% ""%OVWROUTDIR%"" ""%OVWRftpdirectory%""" "exit"
  614. goto endbackup
  615.  
  616. ::All processes are complete. Check if we should delete the temporary folder or not.
  617. :endbackup
  618. IF /i %UseIncr%==yes (goto backupcomplete) ELSE (goto tempdelete)
  619.  
  620. ::Full backups have temporary folder removed everytime.
  621. :tempdelete
  622. echo Deleting Temporary Folder
  623. rd /s/q "%BackupDIR%\%WorldNAM%"
  624. goto backupcomplete
  625.  
  626. ::Notifies user backup is complete then starts Timer to next backup.
  627. :backupcomplete
  628. cls
  629. IF /i %UseIncr%==yes (ECHO Incremental Backup #%IncrCounter% of %IncrCounterMax% Of) ELSE (ECHO Full Backup Of)
  630. for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%
  631. for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%e
  632. ECHO %WorldNAM% COMPLETED On %Date1%---%Time1%
  633. goto RemainingLoop
  634.  
  635. ::Checks if timer has counted down to 0. If so restarts backup
  636. :RemainingLoop
  637. IF %RemainingTimer% gtr 0 (goto OneMoreMinuteMom) ELSE (goto Start)
  638.  
  639. ::Notifies user of remaining time then checks whether to use sleep.exe or ping method.
  640. :OneMoreMinuteMom
  641. IF /i %UseOVWR%==yes (SET /a OVWRStatus=OVWRTimer-RemainingOVWRTimer)
  642. IF /i %UseCart%==yes (SET /a CartStatus=CartTimer-RemainingCartTimer)
  643. ECHO.
  644. ECHO: %RemainingTimer% more minutes until next backup...
  645. ECHO.
  646. IF /i %UseOVWR%==yes (ECHO: %OVWRStatus% more minutes until next Overviewer Run...)
  647. IF /i %UseCart%==yes (ECHO: %CartStatus% more minutes until next Cartograph Run...)
  648. IF /i %UseSleep%==yes (goto sleeptimer) ELSE (goto pingtimer)
  649.  
  650. ::Uses sleep timer to countown 60 seconds then subtracts 1 from user selected time between backup and Overviewer minutes.
  651. :sleeptimer
  652. cd /d %SleepEXE%
  653. sleep 60
  654. SET /a RemainingTimer=RemainingTimer-1
  655. IF /i %UseOVWR%==yes (SET /a RemainingOVWRTimer=RemainingOVWRTimer+1)
  656. IF /i %UseCart%==yes (SET /a RemainingCartTimer=RemainingCartTimer+1)
  657. GOTO RemainingLoop
  658.  
  659. ::Uses ping timer to countown 60 seconds then subtracts 1 from user selected time between backup and Overviewer minutes.
  660. :pingtimer
  661. PING -n 60 127.0.0.1 >nul
  662. SET /a RemainingTimer=RemainingTimer-1
  663. IF /i %UseOVWR%==yes (SET /a RemainingOVWRTimer=RemainingOVWRTimer+1)
  664. IF /i %UseCart%==yes (SET /a RemainingCartTimer=RemainingCartTimer+1)
  665. GOTO RemainingLoop
  666.  
  667. ::Should never be used. Hopefully catches any errors.
  668. :end
  669. pause
  670. Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement