Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- TITLE Minecraft AutoBackup Utility
- ECHO Waiting 30 seconds before starting backup.
- SLEEP 30
- ::By Dateranoth - August 28, 2010
- ::Addition of Overviwer thanks to instinx
- ::Timer Script, Variables and base idea thanks to MonkeyDKS
- ::Original AutoBackup by MonkeyDKS found here-
- ::http://www.minecraftforum.net/viewtopic.php?f=10&t=25967
- ::Used by http://www.gamercide.org on their server.
- ::Feel free to change, adapt, and distribute
- ::Download packaged backup and restore batch, and vbs script file here-
- ::http://www.dateranoth.com/gamercide/mcbackuppackage.zip
- ::V1.0-This backup utility prefers you have Sleep EXE available at this website--------::
- ::----http://www.computerhope.com/dutil.htm - However, this is not a necessary file.---::
- ::-------------------------------------------------------------------------------------::
- ::----Either winrar or 7-zip archiving files - 7z.exe or rar.exe are required!---------::
- ::----Place either 7z.exe or rar.exe In the Backup Directory That you set below.-------::
- ::-------------------------------------------------------------------------------------::
- ::----7zip is a free utility found here - http://www.7-zip.org/ -----------------------::
- ::----The 7z.exe will be located in the directory you installed 7-zip to.--------------::
- ::-------------------------------------------------------------------------------------::
- ::V1.1-Added ability to use Cartographer to generate map images for each backup--------::
- ::----Cartographer can be found here:--------------------------------------------------::
- ::----http://www.minecraftforum.net/viewtopic.php?f=25&t=13134-------------------------::
- ::-------------------------------------------------------------------------------------::
- ::V1.2-Added VBS Script file to force save-all before backup---------------------------::
- ::----VBS Script can be downloaded @ http://www.dateranoth.com/gamercide/saveall.zip----::
- ::-------------------------------------------------------------------------------------::
- ::V1.3-Added delay before execution of Cartograph do to lock ups when starting too fast::
- ::----Added check for temporary folder before backup starts. Will remove the folder----::
- ::----if found in case of mid backup crashes, etc.-------------------------------------::
- ::----Fixed comment lines and added comments to each section. Changed some formatting--::
- ::-------------------------------------------------------------------------------------::
- ::V1.4-Added check for temporary file that was locking up Cartograph-------------------::
- ::----If found, deletes tmp file before running Cartograph-----------------------------::
- ::----Previous timer for Cartograph reduced. Lock ups were probably the temp file the--::
- ::----entire time. Timer left in for a just in case measure---------------------------::
- ::----Added line in Variable to change the map type that Cartograph creates------------::
- ::----Will need to refer to Cartograph Readme.txt for options otherwise set to normal--::
- ::-------------------------------------------------------------------------------------::
- ::V1.5-Added Minecraft Overviewer Option for mapping-----------------------------------::
- ::----Edited by instinx - smithtec(AT)gmail.com----------------------------------------::
- ::----October 6th, 2010 - Added Option for using Minecraft Overviewer------------------::
- ::----http://github.com/brownan/Minecraft-Overviewer-----------------------------------::
- ::V1.6-Cleaned up a lot of code. Added option to only run Overviewer after a certain----::
- ::-----amount of time. Instructions for Overviewer found in User Variables-------------::
- ::V1.7-Added ability to use WinSCP FTP to upload Overviewer map to remote website-------::
- ::-----Runs a Synchronize command so only files that have changed will be uploaded------::
- ::-----Also cleaned up some more code and rearranged User Variables.--------------------::
- ::-----Download WinSCP Here: http://winscp.net : Required for FTP Upload but Free App---::
- ::V1.8-MAJOR UPDATE! Added option to use Incremental Updates. Incremental updates-----::
- ::-----greatly reduce total backup time and space. Incremental updates store one master::
- ::-----backup file in a dated directory. Then dated incremental updates of only changes::
- ::-----are produced on the next backup run. The very first run will create Cache files-::
- ::-----of both the world directory and the compressed backup in your backup directory.--::
- ::-----They will be used to produce incremental updates without recopying the full world::
- ::-----directory or recompressing the full directory. They will only be deleted if the-::
- ::-----backup script detectes a restored backup. This is done by a folder named--------::
- ::-----_IncrBackupRestored being created in the archives. If you restore a backup it----::
- ::-----will be placed in your world folder so the backup script will know to purge the--::
- ::-----cache. Otherwise you can manually delete the files in IncrBackupCache to force--::
- ::-----what is basically a full backup to be done. I'm working on a simple restore-----::
- ::-----script, but for now you must first extract the IncrMaster_Worldname.7z and then--::
- ::-----extract, in order overwriting existing files the incr_# until you get to the time::
- ::-----you wish to restore. Everytime you restart the script or restore a backup a new-::
- ::-----dated folder is created with a new master and it's own set of incremental backups::
- ::-----**************************IMPORTANT READ BELOW****************************-------::
- ::-----WinRAR is NOT SUPPORTED FOR INCREMENTAL BACKUPS. You must use the 7-zip method.-::
- ::-----With the addition of Incremental backup 7z.exe is no longer REQUIRED to be in----::
- ::-----the backup directory, but there now is an option to set the path to the exe------::
- ::-----This must be set for either FULL or INCREMENTAL backups to work------------------::
- ::-----**************************************************************************-------::
- ::-----Additionally I added the option to change how often Cartograph runs, and---------::
- ::-----rearranged some of the code for a smoother script. Along with modifications to---::
- ::-----check for winrar methods and notify user that Incremental backups are not--------::
- ::-----Supported for WinRAR. 7-ZIP is a free program so RAR support seemed uneccessary-::
- ::V1.9-Name Changed from SMPBackup to MCBackup. The backup package now includes a------::
- ::-----script to easily and quickly restore backups. Refer to it for directions.-------::
- ::-----http://www.dateranoth.com/gamercide/MCRestore.zip--------------------------------::
- ::V2.0-Modified the way batch captures time/date from system. Added the ability to-----::
- ::-----change the date format. Refer to User Variables for more information------------::
- ::V2.1-Added a max incremental count. This counter will create X number of incremental-::
- ::-----backups before starting a new folder and master file. This is so users who use--::
- ::-----regular incremental backups can create a new master folder daily or whenever.----::
- ::-----Which will in turn make restoring much easier and faster. If you do not wish to--::
- ::-----use the feature then set it to a very high number. ie. 9999999-------------------::
- ::V2.2-Added option to change ftp protocol when uploading Overviewer map----------------::
- ::-----Also, note that yes/no variables are case sensitive. They need to be lowercase---::
- ::V2.3-Added option to set ftp open Switches. Useful for enabling -passive mode in ftp--::
- ::-----Also made yes/no variables case insensitive. Case no longer matters.------------::
- ::V2.4-Added double quotes around FTP usernames and passwords. Common @ symbols in-----::
- ::-----user names were messing up the script. Should work with these now. Added option-::
- ::-----to wait for X seconds before running backup after server save-all. This will-----::
- ::-----make sure servers with lots of changes have time to finish saving before the-----::
- ::-----files are copied and compressed.-------------------------------------------------::
- ::V2.5-Added backup of Minecraft Server directory files. Only the files, and not the---::
- ::-----directories in your Server Directory will be copied into the backup world in a---::
- ::-----folder call _ServerFiles. This way you will have the configs if you have a crash::
- ::-----or need to restore when using mods/etc. There is also the option to use an------::
- ::-----exclude file. This file contains files or filetypes (one per line) that you-----::
- ::-----don't wish to have backed up. I have included a default one that skips .jar .bat::
- ::-----and .vbs. You can choose to use it or not. Default is to back up all files.----::
- ::V2.6-Added backup of entire Minecraft Server Directory. Refer to Variables below for -::
- ::-----options an instructions. Also added option to upload backups to FTP directory.--::
- ::-----These have been completely seperated in case overviewer and your other backups---::
- ::-----reside one two different servers. Refer to the variables for instructions.------::
- ::V2.7-Fixed Incremental FTP uploads. The ftp folder is now successfully created.------::
- ::-----Allowing ftp backup to work as it should for incremental backups. Also fixed----::
- ::-----remote backup directory option. Wasn't placing backup in correct directory.-----::
- ::-----If using FTP upload of backup, incremental backups with a very large max is------::
- ::-----recommended. This way the first backup will be large and take time uploading----::
- ::-----but the following incremental backups will be much smaller and save time and-----::
- ::-----bandwidth.-----------------------------------------------------------------------::
- ::V2.8-Updated saveall.vbs to V1.2 - Condensed Keystroke Commands & Added Server--------::
- ::-----Backup notification. Download at www.gamercide.org/minecraft/MCBackup/saveall.zip::
- ::-----Change Cartograph to Cartograph G to support the new save format. Can be found at::
- ::-----http://www.minecraftforum.net/viewtopic.php?f=1022&t=165779&hilit=Cartograph+G --::
- ::-----Please refer to Readme.txt included with Cartograph G for map render settings----::
- ::-----Added option to change output directory of the Cart maps. Default is BackupDIR---::
- ::-----------------------------------------------------------------------------------::
- ::----------------User Variables - Change these to fit your situation----------------::
- ::-----------------------------------------------------------------------------------::
- ::Set to use Incremental Backup. Only supports 7zip compression method. (yes or no)
- ::Incremental will create one base file and then only the changed updates from that point forward in 7-zip format.
- ::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.
- SET UseIncr=yes
- ::Set to the number of Incremental Backups you would like created before a new folder and master file is created.
- ::If you multiply this number by your backup Time you will get the amount of time between new incremental folder creation.
- ::ie. Backup time of 10 minutes, and an Incremental Backup # of 6 would create a new master and folder every 60 minutes.
- SET IncrCounterMax=24
- ::Set Server Directory (The folder your "World" folder lives in...NOT the path inside your world folder)
- SET WorldDIR=R:\
- ::Set World Name (Copy your World Folder name here)
- SET WorldNAM=craftbukkit
- ::Set Backup Directory (Where do you want to save your backups?)
- SET BackupDIR=G:\minecraft backup
- ::Set Time between Backups (in minutes)
- SET Timer=30
- ::Set Compression Method (rar or 7zip)
- SET Method=7zip
- ::Set Directory for 7z.exe
- SET _7zipdir=C:\Program Files\7-Zip
- ::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.
- :: If it does or you would like something different then rearrange the parameters below until satisfied. Results will be format1-format2-format3
- SET dateformat1=%%g
- SET dateformat2=%%e
- SET dateformat3=%%f
- ::You now have the option to backup your ENTIRE Minecraft Server Directory.
- ::All files will be found in your BackupDIR under the chosen WorldNAM ( Including the world itself ).
- ::Would you like to backup the entire Minecraft Server Directory? (yes or no)
- SET BackupAll=no
- ::If you chose to Backup your Entire Server directory then you can use the exclude file to not backup certain files/folders.
- ::Would you like to exclude some of the files or folders? (yes or no)
- SET UseExcl=no
- ::Set the filename of the file containing a list of files you would like to exclude.
- ::File must be located in same directory as MCBackup.bat
- ::Each excluded item should be on a seperate line.
- ::Filetypes and directoreis are accepted ie. .jar \world\
- SET excludefile=exclude.txt
- ::Would you like to use the VBS file to force a save-all to your server? yes or no
- SET UseVBS=yes
- ::Set directory where saveall.vbs is located
- SET VBSDir=R:\craftbukkit\backupscripts2.5
- ::Set how long you would like to wait for Minecraft Server to finish save-all before backing up.
- ::Maps with lots of players and changes occuring will need more time than maps
- ::with only a few players and changes. (Time in Seconds, 0 to start immediately)
- SET VBSDelay=5
- ::Will you be using Sleep.exe? (yes or no)
- SET UseSleep=yes
- ::Set Sleep EXE directory if using Sleep.exe
- SET SleepExe=C:\windows\system32
- ::Would you like to use Cartographer to map your backups? yes or no
- SET UseCart=no
- ::Set directory where Cartograph_G_Renderer.exe is located
- SET CartDIR=C:\minecraft\cartographer
- ::Set the directory where you would like the maps output to. Default is your Backup directory.
- SET CartOutputDIR=%BackupDIR%
- ::Set Cartograph G map type. Refer to Cartograph G Readme.txt for more info or leave at default setting.
- ::Note that the old Cartograph defaulted east as up. If you wish to keep this, change north to east.
- SET CartMap=normal day north
- ::Set how often you would like Cartograph G to be ran. (in minutes) Minimum is the time between backups.
- ::Will only be ran when a backup runs. ie. If your backup time is every 30 minutes, then Cartograph
- ::can be set to run every 30 minutes, 1 hour, 1 hour and 30 minutes, 2 hours, etc.
- ::Odd times will round forward, running after the time has been met but not until the backup starts.
- ::Time can be different from Overviewer Time.
- SET CartTimer=240
- ::Set to 0 if you DON'T want Cartograph to run when the batch file is initially opened.
- SET CartFirstRun=1
- ::Would you like to use Overviewer to map your backups? First run can take a LONG time. (yes or no)
- SET UseOVWR=no
- ::Which method of Overviewer? Windows Executable or Python Script? (exe or python)
- SET OVWRmethod=exe
- ::Set directory where Overviewer is located
- SET OVWRDIR=C:\minecraft\Overviewer-0.0.5
- ::Set Overviewer Image Directory (Overviewer Output)
- SET OVWROUTDIR=G:\minecraft overviewer\output\buildworld
- ::Set Overviewer CACHE Directory (Where Overviewer Cache files are stored)
- SET OVWRCACHEDIR=G:\minecraft overviewer\cache\buildworld
- ::How many processors should Overviewer Use? (This should be set low or it will cause lag on the server)
- SET Procs=2
- ::Set how often you would like Overviewer to be ran. (in minutes) Minimum is the time between backups.
- ::Will only be ran when a backup runs. ie. If your backup time is every 30 minutes, then Overviewer
- ::can be set to run every 30 minutes, 1 hour, 1 hour and 30 minutes, 2 hours, etc.
- ::Odd times will round forward, running after the time has been met but not until the backup starts.
- ::Time can be different from Cartograph Time.
- SET OVWRTimer=480
- ::Set to 0 if you DON'T want Overviwer to run when the batch file is initially opened.
- SET OVWRFirstRun=1
- ::Would you like to use WinSCP FTP to upload the Minecraft Server backup files to a web server? (yes or no)
- ::If connecting to a secure ftp the first run will ask you to save the key to cache.
- ::Once saved it will run automatically without user input from that point on.
- :: If yes, please refer to 'Backup Files to FTP Options' below
- SET useftp=no
- ::Would you like to use WinSCP FTP to upload the Overviewer map to a web server? (yes or no)
- ::If connecting to a secure ftp the first run will ask you to save the key to cache.
- ::Once saved it will run automatically without user input from that point on.
- :: If yes, please refer to 'Overviewer Map FTP Options' below
- SET OVWRuseftp=no
- ::WinSCP is required if using FTP. Please set the path to WinSCP
- SET ftpwinscpdir=C:\program files (x86)\winscp
- ::-------Start Backup Files to FTP Options-------::
- ::Set your ftp Protocol (ftp or sftp or scp)
- SET ftpprotocol=ftp
- ::This is where you can set WinSCP switches for connecting. Refer to http://winscp.net/eng/docs/script_commands#open for details.
- ::Main uses are to leave blank for default OR -passive for ftp protocol passive mode.
- SET ftpswitch=
- ::Set your ftp address here WITHOUT ftp:// (site:port)
- SET ftpurlport=yourftp.com:21
- ::Set the login name for your FTP.
- SET ftploginname=yourftploginname
- ::Set the password for your FTP.
- SET ftploginpass=yourftppass
- ::Set the max upload bandwidth you want WinSCP to use (kibps)
- SET ftpspeed=60
- ::Set your REMOTE ftp directory for placing the backup files. (Full Remote Path)
- SET ftpdirectory=/home/WWW/minecraft
- ::-------End Backup Files to FTP Options------::
- ::-------Start Overviewer Map FTP Options-----::
- ::Set your ftp Protocol (ftp or sftp or scp)
- SET OVWRftpprotocol=ftp
- ::This is where you can set WinSCP switches for connecting. Refer to http://winscp.net/eng/docs/script_commands#open for details.
- ::Main uses are to leave blank for default OR -passive for ftp protocol passive mode.
- SET OVWRftpswitch=
- ::Set your ftp address here WITHOUT ftp:// (site:port)
- SET OVWRftpurlport=yourftp.com:21
- ::Set the login name for your FTP.
- SET OVWRftploginname=yourftploginname
- ::Set the password for your FTP.
- SET OVWRftploginpass=yourftppass
- ::Set the max upload bandwidth you want WinSCP to use (kibps)
- SET OVWRftpspeed=60
- ::Set your REMOTE ftp directory for Overviewer. Should be base directory containing index.html. (Full Remote Path)
- SET OVWRftpdirectory=/home/WWW/minecraft
- ::-------End Overviewer Map FTP Options-----::
- ::------------------------------------------------------------------------------------------------------------------------------::
- ::!!!!!!!!!!!!!!!!DON'T TOUCH BELOW HERE unless you know Batch (And are willing to lower yourself to that level)!!!!!!!!!!!!!!!!::
- ::------------------------------------------------------------------------------------------------------------------------------::
- ::Set Overviewer and Cartograph Counter to 0 on first run.
- SET RemainingOVWRTimer=0
- SET RemainingCartTimer=0
- ::Set variables for Incremental backup.
- SET IncrBootRun=1
- SET IncrCounter=0
- ::Set variables for excluding files from Server Directory
- IF /i %UseExcl%==yes (SET exclude=/exclude:%excludefile%) ELSE (SET exclude=)
- ::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.
- :Methodtest
- IF /i %Method%==7zip (goto 7zip) ELSE IF /i %Method%==rar (goto rar) ELSE (goto methodwrong)
- ::Notifies the user that an invalid compression method was selected. Then exits.
- :methodwrong
- ECHO You have entered an invalid Method (Currently %Method%) Must be rar or 7zip
- ECHO Change the Method and then restart the batch file to continue with Backup.
- pause
- exit
- ::RAR method detected. Check to see if its FULL or INCREMENTAL backup method.
- :rar
- IF /i %UseIncr%==yes (goto rarINCR) ELSE (goto rarFULL)
- ::RAR is not supported for Incremental backups. Notify user and exit.
- :rarINCR
- ECHO Current method of backup is %Method% . %Method% is not supported for incremental backups.
- ECHO.
- ECHO Either change to 7zip method or Change to Full backups and restart script.
- pause
- exit
- ::Checks for the rar.exe before continuing with backup
- :rarFULL
- IF EXIST "%BackupDIR%\rar.exe". (goto start) ELSE (goto rarbad)
- ::Checks for the 7z.exe before continuing with backup
- :7zip
- IF EXIST "%_7zipdir%\7z.exe". (goto start) ELSE (goto 7zipbad)
- ::Notifies user that winrar was selected but no rar.exe was found.
- :rarbad
- Echo rar.exe not found. Please Place rar.exe in the BackupDIR (Currently: %BackupDIR%)
- Echo and restart script to continue with Backup.
- pause
- exit
- ::Notifies user that 7-zip was selected but no 7z.exe was found.
- :7zipbad
- Echo 7z.exe not found. Current location %_7zipdir% . Please update location and restart script
- Echo to continue with Backup.
- pause
- exit
- ::Resets timer and Checks for BackupMethod
- :start
- SET RemainingTimer=%Timer%
- echo.
- echo Starting Back up of MineCraft World - %WorldNam%
- echo.
- IF /i %UseIncr%==yes (goto VBScheck) ELSE (goto startfull)
- ::Checks for old temporary directory
- :startfull
- IF EXIST "%BackupDIR%\%WorldNam%\" (goto tempcleanup) ELSE (goto VBScheck)
- ::Removes Temporary world folder if found.
- :tempcleanup
- echo Old Temporary folder found.
- echo Deleting Temporary Folder before backup.
- rd /s/q "%BackupDIR%\%WorldNAM%"
- goto VBScheck
- ::Checks to see if Script for forcing server save is enabled
- :VBScheck
- IF /i %UseVBS%==yes (goto VBS) ELSE (goto backupmethod)
- ::Uses VBS Script to force command input of save-all into server
- :VBS
- echo Forcing Server to save world
- cd /d "%VBSDir%"
- saveall.vbs
- IF %VBSDelay% LEQ 0 (echo.) ELSE (ECHO Waiting for %VBSDelay% seconds before starting backup)
- IF %VBSDelay% LEQ 0 (goto backupmethod) ELSE IF /i %UseSleep%==yes (%SleepEXE%\sleep.exe %VBSDelay%) ELSE (PING -n %VBSDelay% 127.0.0.1 >nul)
- goto backupmethod
- ::Check to see which backup method should be used. Full or Incremental.
- :backupmethod
- IF /i %UseIncr%==yes (goto startincr) ELSE (goto tempcopy)
- ::-----------START INCREMENTAL BACKUP CODE------------------------::
- ::Check to see if this is the intial Incremental run.
- :startincr
- ::SET WorldNamDate=%WorldNAM%-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%---%TIME:~0,2%%TIME:~3,2%
- for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%
- for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%e
- SET WorldNamDate=%worldNAM%-%Date1%---%Time1%
- IF %IncrBootRun%==1 (goto incrboot) ELSE IF %IncrCounter% GEQ %IncrCounterMax% (goto incrboot) ELSE IF EXIST "%WorldDIR%\%WorldNam%\_IncrBackupRestored" (goto incrboot) ELSE (goto incrpass)
- ::Initial Incremental run creates some folders and resets the counter for the incremental backups.
- ::Also runs check to see if a world backup has been restored since last run.
- :incrboot
- ECHO Starting Initial Run of Backup. New, dated folder will be created and Incr Backups will be stored there until Script restarted.
- ECHO.
- SET IncrBootRun=0
- for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date2=%dateformat1%-%dateformat2%-%dateformat3%
- for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time2=%%d%%e
- SET WorldNamIncrDate=%worldNAM%-%Date2%---%Time2%
- SET IncrCounter=1
- md "%BackupDIR%\%WorldNamIncrDate%
- IF EXIST "%WorldDIR%\%WorldNam%\_IncrBackupRestored" (goto incrdelworld) ELSE (goto incrfirstpass)
- ::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.
- ::Also removes tagged folder in worlddir. Should only reappear if user restores another backup.
- :incrdelworld
- ECHO Restored Backup found. Must delete cache to insure proper backup.
- ECHO.
- rd /s/q "%BackupDIR%\IncrBackupCache\%WorldNAM%"
- rd /s/q "%WorldDIR%\%WorldNam%\_IncrBackupRestored"
- goto incrfirstpass
- ::First Pass will update Cached world directory and master compressed file. Also creates Master file in dated folder.
- ::Also creates the folder _IncrBackupRestored so it can be checked for after a restored backup.
- :incrfirstpass
- ECHO This is a new run of backup script. Updating cache files and creating initial backup.
- ECHO.
- 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)
- md "%BackupDIR%\IncrBackupCache\%WorldNam%\_IncrBackupRestored"
- "%_7zipdir%\7z.exe" u "%BackupDIR%\IncrBackupCache\IncrMaster_%WorldNam%.7z" -up0q0r2x2y2z1w2 "%BackupDIR%\IncrBackupCache\%WorldNAM%" -ms=off
- xcopy "%BackupDIR%\IncrBackupCache\IncrMaster_%WorldNam%.7z" "%BackupDIR%\%WorldNamIncrDate%\" /Q/Y
- IF %useftp%==yes (
- cd /d "%ftpwinscpdir%"
- 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"
- )
- IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
- ::Passes after the first one will create Incremental files in the last dated world backup directory.
- ::They will only reflect changes made that differ from the Master file. Thus greatly speeding up the entire process.
- :incrpass
- for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date3=%dateformat1%-%dateformat2%-%dateformat3%
- for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time3=%%d%%e
- SET IncrCounterDate=%IncrCounter%__%Date3%---%Time3%
- ECHO Updating MineCraft world to working Directory. Only new files will be transferred.
- 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)
- ECHO Compressing New Files to Incr. 7z file.
- "%_7zipdir%\7z.exe" u "%BackupDIR%\IncrBackupCache\IncrMaster_%WorldNam%.7z" -up0q0r2x2y2z1w2 -up3q3r2x2y2z0w2!"%BackupDIR%\%WorldNamIncrDate%\incr_#%IncrCounterDate%.7z" "%BackupDIR%\IncrBackupCache\%WorldNam%" -ms=off
- SET /a IncrCounter=IncrCounter+1
- IF %useftp%==yes (
- cd /d "%ftpwinscpdir%"
- start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamIncrDate%\incr_#%IncrCounterDate%.7z"" ""%ftpdirectory%/%WorldNamIncrDate%/""" "exit"
- )
- IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
- ::------------END INCREMENTAL BACKUP CODE----------------------------::
- ::------------START FULL BACKUP CODE---------------------------------::
- ::Copies the world folder from the server to a temporary directory for processing. Also Sets the backup file name.
- :tempcopy
- echo Copying MineCraft world to temporary working Directory
- IF /i %BackupAll%==yes (xcopy "%WorldDIR%" "%BackupDIR%\%WorldNam%" /E/I/Q/H/Y %exclude%) ELSE (xcopy "%WorldDIR%\%WorldNam%" "%BackupDIR%\%WorldNam%" /S/I/Q/Y)
- cd /d "%BackupDIR%"
- ::SET WorldNamDate=%WorldNAM%-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%---%TIME:~0,2%%TIME:~3,2%
- for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%
- for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%e
- SET WorldNamDate=%worldNAM%-%DATE1%---%Time1%
- IF /i %Method%==7zip (goto 7zipgood) ELSE IF /i %Method%==rar (goto rargood) ELSE (goto methodtest)
- ::7z.exe method. Compresses files then waits for 5 seconds using Sleep or Ping
- :7zipgood
- echo Compressing using 7zip
- "%_7zipdir%\7z.exe" a "%BackupDIR%\%WorldNamDate%.7z" "%BackupDIR%\%WorldNAM%"
- IF %useftp%==yes (
- cd /d "%ftpwinscpdir%"
- start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamDate%.7z"" ""%ftpdirectory%/""" "exit"
- )
- IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
- ::rar.exe method. Compresses files then waits for 5 seconds using Sleep or Ping
- :rargood
- cd /d "%BackupDIR%"
- echo Compressing using WinRAR
- rar.exe a -m5 -- "%WorldNamDate%" "%WorldNAM%"
- IF %useftp%==yes (
- cd /d "%ftpwinscpdir%"
- start /wait winscp.exe /console /command "open %ftpprotocol%://""%ftploginname%"":""%ftploginpass%""@%ftpurlport% %ftpswitch%" "put -speed=%ftpspeed% ""%BackupDIR%\%WorldNamDate%.rar"" ""%ftpdirectory%/""" "exit"
- )
- IF /i %UseSleep%==yes (goto mapdelaysleep) ELSE (goto mapdelayping)
- ::---------------------END FULL BACKUP CODE------------------------------::
- ::Delay of 5 seconds added to be sure Files Copied. Sleep method
- ::Then checks whether to use Cartograph or Overviewer or neither
- :mapdelaysleep
- IF /i %UseIncr%==yes (SET TempWorld=%BackupDIR%\IncrBackupCache\%WorldNAM%) ELSE (SET TempWorld=%BackupDIR%\%WorldNAM%)
- IF /i %BackupAll%==yes (SET TempWorldDir=%Tempworld%\%WorldNAM%) ELSE (SET TempWorldDir=%TempWorld%)
- cd /d %SleepEXE%
- sleep 5
- IF /i %UseCart%==yes (goto carttimecheck) ELSE IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
- ::Delay of 5 seconds added to be sure Files Copied. Ping method.
- ::Then checks whether to use Cartograph or Overviewer or neither
- :mapdelayping
- IF /i %UseIncr%==yes (SET TempWorld=%BackupDIR%\IncrBackupCache\%WorldNAM%) ELSE (SET TempWorld=%BackupDIR%\%WorldNAM%)
- IF /i %BackupAll%==yes (SET TempWorldDir=%Tempworld%\%WorldNAM%) ELSE (SET TempWorldDir=%TempWorld%)
- PING -n 5 127.0.0.1 >nul
- IF /i %UseCart%==yes (goto carttimecheck) ELSE IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
- ::Check to see if this is first run of batch file. If so, note this and then run cartograph.
- ::Otherwise Check to see if cartograph should be ran based on user selected time. If not, skip cartograph this run.
- :carttimecheck
- IF %CartFirstRun%==1 (goto cartboot) ELSE IF %RemainingCartTimer% GEQ %CartTimer% (goto cartobadfilecheck) ELSE IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
- :cartboot
- SET CartFirstRun=0
- goto cartobadfilecheck
- ::Checks for Temporary File that's been locking up Cartograph
- :cartobadfilecheck
- IF EXIST "%TempWorldDir%\tmp_chunk.dat" (goto deletebadfile) ELSE (goto cartostart)
- ::Deletes Temporary File that's been locking up Cartograph
- :deletebadfile
- del /f "%TempWorldDir%\tmp_chunk.dat"
- echo Temporary file that causes Cartograph lockups found and deleted.
- goto cartostart
- ::User selected to use cartograph. Runs Cartograh then checks to see if user would also like to run Overviwer.
- :cartostart
- echo Creating map image using Cartographer
- echo Process may take a long time. Be patient.
- echo.
- cd /d %CartDIR%
- Cartograph_G_Renderer.exe custom "%TempWorldDir%" output "%CartOutputDIR%\%WorldNamDate%.png" %CartMap%
- SET RemainingCartTimer=0
- IF /i %UseOVWR%==yes (goto OVWR) ELSE (goto endbackup)
- ::Check to see if this is first run of batch file. If so, note this and then run overviewer.
- ::Otherwise Check to see if overviewer should be ran based on user selected time. If not, skip overviewer this run.
- :OVWR
- IF %OVWRFirstRun%==1 (goto OVWRBoot) ELSE IF %RemainingOVWRTimer% GEQ %OVWRTimer% (goto OVWRStart) ELSE (goto endbackup)
- :OVWRBoot
- SET OVWRFirstRun=0
- goto OVWRStart
- ::User selected to use Overviewer. Should we run the EXE or Python Version?
- :OVWRStart
- echo Creating map image using OverViewer
- echo Process takes a very long time. Get a sandwich.
- echo.
- IF /i %OVWRmethod%==exe (goto OVWRexestart) ELSE IF /i %OVWRmethod%==python (goto OVWRpythonstart) ELSE (goto OVWRError)
- ::A method that doesn't exist was entered. We are notified and allowed to continue backup process after input.
- :OVWRError
- ECHO You have entered an invalid Method (Currently %OVWRmethod%) Must be exe or python
- ECHO Change the Method and then restart the backup process or press enter to continue.
- pause
- goto endbackup
- ::Python method was selected. Overviewer will now be ran using the selected options. Run timer will then be reset.
- :OVWRpythonstart
- cd /d %OVWRDIR%
- Python gmap.py --cachedir="%OVWRCACHEDIR%" -p "%Procs%" "%TempWorldDir%" "%OVWROUTDIR%"
- SET RemainingOVWRTimer=0
- IF /i %OVWRuseftp%==yes (goto startftp) ELSE (goto endbackup)
- ::EXE method was selected. Overviwer will now be ran using selected options. Run timer will then be reset.
- :OVWRexestart
- cd /d %OVWRDIR%
- gmap.exe --cachedir="%OVWRCACHEDIR%" -p "%Procs%" "%TempWorldDir%" "%OVWROUTDIR%"
- SET RemainingOVWRTimer=0
- IF /i %OVWRuseftp%==yes (goto startftp) ELSE (goto endbackup)
- ::Attempts to kill WinSCP in case it was still running or stuck from last time.
- ::Starting the FTP Upload Process. It is opened as a seperate process and is not waited for because it can take a long time.
- :startftp
- ECHO Starting FTP Upload of Overviewer. Process will open in a new window and backup batch will continue to run without waiting.
- taskkill /im winscp.exe
- cd /d "%ftpwinscpdir%"
- start winscp.exe /console /command "open %OVWRftpprotocol%://""%OVWRftploginname%"":""%OVWRftploginpass%""@%OVWRftpurlport% %OVWRftpswitch%" "synchronize remote -delete -criteria=both -speed=%OVWRftpspeed% ""%OVWROUTDIR%"" ""%OVWRftpdirectory%""" "exit"
- goto endbackup
- ::All processes are complete. Check if we should delete the temporary folder or not.
- :endbackup
- IF /i %UseIncr%==yes (goto backupcomplete) ELSE (goto tempdelete)
- ::Full backups have temporary folder removed everytime.
- :tempdelete
- echo Deleting Temporary Folder
- rd /s/q "%BackupDIR%\%WorldNAM%"
- goto backupcomplete
- ::Notifies user backup is complete then starts Timer to next backup.
- :backupcomplete
- cls
- IF /i %UseIncr%==yes (ECHO Incremental Backup #%IncrCounter% of %IncrCounterMax% Of) ELSE (ECHO Full Backup Of)
- for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%
- for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%e
- ECHO %WorldNAM% COMPLETED On %Date1%---%Time1%
- goto RemainingLoop
- ::Checks if timer has counted down to 0. If so restarts backup
- :RemainingLoop
- IF %RemainingTimer% gtr 0 (goto OneMoreMinuteMom) ELSE (goto Start)
- ::Notifies user of remaining time then checks whether to use sleep.exe or ping method.
- :OneMoreMinuteMom
- IF /i %UseOVWR%==yes (SET /a OVWRStatus=OVWRTimer-RemainingOVWRTimer)
- IF /i %UseCart%==yes (SET /a CartStatus=CartTimer-RemainingCartTimer)
- ECHO.
- ECHO: %RemainingTimer% more minutes until next backup...
- ECHO.
- IF /i %UseOVWR%==yes (ECHO: %OVWRStatus% more minutes until next Overviewer Run...)
- IF /i %UseCart%==yes (ECHO: %CartStatus% more minutes until next Cartograph Run...)
- IF /i %UseSleep%==yes (goto sleeptimer) ELSE (goto pingtimer)
- ::Uses sleep timer to countown 60 seconds then subtracts 1 from user selected time between backup and Overviewer minutes.
- :sleeptimer
- cd /d %SleepEXE%
- sleep 60
- SET /a RemainingTimer=RemainingTimer-1
- IF /i %UseOVWR%==yes (SET /a RemainingOVWRTimer=RemainingOVWRTimer+1)
- IF /i %UseCart%==yes (SET /a RemainingCartTimer=RemainingCartTimer+1)
- GOTO RemainingLoop
- ::Uses ping timer to countown 60 seconds then subtracts 1 from user selected time between backup and Overviewer minutes.
- :pingtimer
- PING -n 60 127.0.0.1 >nul
- SET /a RemainingTimer=RemainingTimer-1
- IF /i %UseOVWR%==yes (SET /a RemainingOVWRTimer=RemainingOVWRTimer+1)
- IF /i %UseCart%==yes (SET /a RemainingCartTimer=RemainingCartTimer+1)
- GOTO RemainingLoop
- ::Should never be used. Hopefully catches any errors.
- :end
- pause
- Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement