After that happened I was determined to figure out how to regularly back up the world so that I would lose at most a day’s worth of activity. The solution I came up with requires the following:
- 7-Zip Archiving Tool
- The forfiles command in Windows
- The Task Scheduler in Windows
- A couple of homemade batch files
for /F "tokens=1-4 delims=/ " %%i IN ('date /t') DO (set DT_DAY=%%iset DT_MM=%%jset DT_DD=%%kSET DT_YYYY=%%l) "c:\program files\7-Zip\7z.exe" a "c:\minecraft\backups\world_%DT_YYYY%_%DT_MM%_%DT_DD%.7z" "c:\minecraft\world" -sswEdit: Thanks to Stanchez's comment below, I found out about the "-ssw" switch in 7-zip. This allows 7-zip to archive files that are currently locked by other programs, meaning you don't have to shut down Minecraft to perform a backup. Thanks for the advice!
I’ll go ahead and break down this batch script line-by-line. The first five lines are for creating a date stamp in YYYY_MM_DD format for the archive file name. For example, if this were to run for June 1st, 2011, the date stamp would read “2011_06_01”. The line with “c:\program files\7-Zip\7z.exe” in it is the actual command to archive the world folder. The syntax of the command is as follows:
“c:\path\to\7-zip\executable” a “c:\path\to\folder\to\hold\backups\backupname_%DT_YYYY%_%DT_MM%_%DT_DD%.7z "c:\path\to\minecraft\world\folder" -ssw
forfiles /P "c:\minecraft\backups" /M *.7z /D -7 /C "cmd /C del @PATH"
- The /P flag specifies the directory to look in for files.
- The /M flag specifies a mask to use. In our case, 7-zip files.
- The /D flag specifies a timeframe for last-modified. Here we are looking for files older than 7 days.
- The /C flag specifies what command to run against the resulting set of files. Here I am asking to delete each files that meets the requirements above. The @PATH variable provides the full path of each file that meets requirements.





