Guest User

MXL Save Backup

a guest
Jan 29th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ::WRITTEN BY DUXA 8/14/2018
  2. ::ORIGINAL CREDIT: https://www.reddit.com/r/MonsterHunter/comments/973xjq/i_wrote_a_script_to_automatically_backup_monster/
  3. ::MODIFIED FOR MEDIAN XL Σ BY ROBOTLEGS/VELVETEA 26/1/2019
  4. ::VERSION 1.5.1 UPDATED 26/1/2019 BY ROBOTLEGS/VELVETEA (FOR MEDIAN XL Σ)
  5. ::NOTE: THIS CODE IS COPYRIGHTED BY DUXA. IF YOU MODIFY AND DISRIBUTE IT, YOU ARE OBLIGATED TO PROVIDE ORIGINAL CREDIT AND LINK.
  6.  
  7. ::WHAT NEEDS TO BE DONE IF THIS DOES NOT WORK FOR YOU THE FIRST TIME
  8. ::     Edit the PATH variable below to your save folder. (Default: %Appdata%\MedianXL\save)
  9.  
  10. :: OPTIONAL: You can make Windows Scheduler run this script at whatever interval you want.
  11. ::     If CHK below is set to 1 it will only back up saves if there was an actual change to the file.
  12. ::     Alternatively you can run this script in the background while you play without scheduling it. Set TIMER=1
  13. ::     It will ask you how often you want to do backups (in minutes), then just minimize it and let it do backups
  14. ::     while you play.
  15.  
  16. ::     If you have 7zip installed it will be used. If you have WinRar then it will be used. If you have neither
  17. ::     the standard zip will be used. The backups are stored in BACKUPPATH path below. You can change it to whatever
  18. ::     location you want. Note that a log is kept, so that you can go back and see when backups were done. The log is
  19. ::     in the same directory as the backups. Also two text files containing previous/current checksums are kept
  20. ::     there too. They are simple txt files taking up 1kb in space. They are only created if CHK is set to 1.
  21.  
  22. :: For any questions, PM me on Discord (Robotlegs#4829) or Reddit (/u/__VelveTea)
  23.  
  24. @echo off
  25. SETLOCAL EnableDelayedExpansion
  26. ::================================CHANGE THESE AS NEEDED=====================================
  27.  
  28. ::Location of the saves
  29. set PATH=%Appdata%\MedianXL\save
  30. ::Location to save the backups to
  31. set BACKUPPATH=%USERPROFILE%\Documents\Median XL Backups
  32. ::Log path
  33. set LOGPATH=%BACKUPPATH%
  34. ::FLAG to do a backup only if save has changed, set to 0 if want to backup no matter what
  35. set /a CHK=1
  36. ::If you dont want to schedule it and instead would like to use this script as something you run while you play
  37. ::in the background then set TIMER=1. It will ask you how often you want to run it (in minutes).
  38. set /a TIMER=0
  39. ::Date format - Possible options are US, EU, YMD. Examples: US 08/17/2018 | EU 17/08/2018 | YMD 2018/08/17
  40. set DATEFORMAT=EU
  41. ::If you are not using default path for 7zip or WinRar you can change them here
  42. ::It is ok to not have either, then standard zip format will be used if thats the case
  43. ::Reasons to use 7zip - Better compression, free (WILL BE PREFERRED OVER WINRAR IF INSTALLED)
  44. ::Reasons to use WinRar - Has 5% baked in recovery in case recovery is needed
  45. set SZIPPATH=C:\Program Files\7-Zip
  46. set WRARPATH=C:\Program Files\WinRAR
  47.  
  48. ::============DO NOT CHANGE ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING================
  49. if %DATEFORMAT% == US goto DATEVALID
  50. if %DATEFORMAT% == EU goto DATEVALID
  51. if %DATEFORMAT% == YMD goto DATEVALID
  52. cls
  53. color 0C
  54. echo Invalid date format %DATEFORMAT%
  55. echo Must be either US, EU or YMD
  56. echo.
  57. pause
  58. goto END
  59. :DATEVALID
  60. if %DATEFORMAT% == US set DF=MM-dd-yyyy_HH-mm-ss
  61. if %DATEFORMAT% == EU set DF=dd-MM-yyyy_HH-mm-ss
  62. if %DATEFORMAT% == YMD set DF=yyyy-MM-dd_HH-mm-ss
  63. set /a USESZIP=0
  64. set /a USEWRAR=0
  65. if exist "%SZIPPATH%" (set /a USESZIP=1)
  66. if %USESZIP% EQU 1 goto SKIPWINRAR
  67. if exist "%WRARPATH%" (set /a USEWRAR=1)
  68. :SKIPWINRAR
  69. if %TIMER% == 0 goto SKIPTIMER
  70.  
  71. set /p CLK="How often do you want to backup (enter minutes): "
  72. set /a SECS=%CLK%*60
  73. :SKIPTIMER
  74. if %USESZIP% == 0 goto CHECKWRAR
  75. if exist "%SZIPPATH%\7z.exe" (set SZIPPATH=%SZIPPATH%\7z.exe) else (set SZIPPATH=%SZIPPATH%\7za.exe)
  76. if exist "%SZIPPATH%" (color 0A & echo Found 7zip & goto CHECKPATH)
  77. cls
  78. color 0E
  79. echo WARNING!
  80. echo Cannot find 7-zip in %SZIPPATH%
  81. echo Download it from https://www.7-zip.org/download.html
  82. echo.
  83. echo Checking for WinRar
  84.  
  85. :CHECKWRAR
  86. if exist "%WRARPATH%\rar.exe" (set /a USEWRAR=1 & set /a USESZIP=0 & echo Found WinRar & color 0D) else (color 0F
  87.     echo Could not find 7zip or Winrar
  88.     echo Falling back to standard zip
  89.     set /a USESZIP=0
  90.     set /a USEWRAR=0)
  91.  
  92. :CHECKPATH
  93. if exist "%PATH%" goto CHECKBACKUPPATH
  94. cls
  95. echo ERROR!
  96. echo Cannot find %PATH%
  97. pause
  98. goto END
  99.  
  100. :CHECKBACKUPPATH
  101. if exist "%BACKUPPATH%" goto RUN
  102. mkdir "%BACKUPPATH%"
  103. if exist "%BACKUPPATH%" goto RUN
  104. cls
  105. echo ERROR!
  106. echo Cannot create %BACKUPPATH%
  107. echo To store backups in
  108. echo Need Admin rights?
  109. pause
  110. goto END
  111.  
  112. :RUN
  113. title Median XL Save Backup - Original by Duxa (/u/Chrushev) for MHW - Modified for MXL by Robotlegs (/u/__VelveTea) 1.5.1 - 29/1/2019
  114. if not exist "%SystemRoot%\system32\WindowsPowerShell\v1.0\PowerShell.exe" (set /a PWRSH=0) else (set /a PWRSH=1)
  115. if not exist "%BACKUPPATH%\MXL_last_cksum.txt" goto BACKUP
  116. if %CHK% == 0 goto BACKUP
  117.  
  118. "%SystemRoot%\system32\CertUtil" -hashfile "%PATH%\remote\SAVEDATA1000" MD5 > "%BACKUPPATH%\MXL_curr_cksum.txt"
  119.    
  120. for /f "tokens=1*delims=:" %%G in ('%SystemRoot%\system32\findstr /n "^" "%BACKUPPATH%\MXL_last_cksum.txt"') do if %%G equ 2 (
  121.     set PREV=%%H)
  122.     set PREV=%PREV: =%
  123.     echo Previous: %PREV%
  124.    
  125. for /f "tokens=1*delims=:" %%G in ('%SystemRoot%\system32\findstr /n "^" "%BACKUPPATH%\MXL_curr_cksum.txt"') do if %%G equ 2 (
  126.     set CURR=%%H)
  127.     set CURR=%CURR: =%
  128.     echo Current:  %CURR%
  129.  
  130. if "%PREV%" == "%CURR%" (
  131.     echo Checksums match. New backup not needed.
  132.     echo %date% %time% - Backup requested, file is same as last time. NOT backing up. >> "%LOGPATH%\MXL_saves_log.txt"
  133.     echo If you would like to backup either way, please set CHK=0 in the file. >> "%LOGPATH%\MXL_saves_log.txt"
  134.     echo Previous: %PREV% >> "%LOGPATH%\MXL_saves_log.txt"
  135.     echo Current:  %CURR% >> "%LOGPATH%\MXL_saves_log.txt"
  136.     echo. >> "%LOGPATH%\MXL_saves_log.txt"
  137.     goto TIMERCHECK
  138. )
  139.  
  140. :BACKUP
  141. if %CHK% == 1 "%SystemRoot%\system32\CertUtil" -hashfile "%PATH%\remote\SAVEDATA1000" MD5 > "%BACKUPPATH%\MXL_last_cksum.txt"
  142.  
  143. if %PWRSH% == 1 (for /f %%d in ('%SystemRoot%\system32\WindowsPowerShell\v1.0\PowerShell.exe get-date -format "{%DF%}"') do set FILENAME=MXL_Save_%%d) else (goto ALTDATE)
  144.  
  145. goto SKIPALTDATE
  146. :ALTDATE
  147. if 20 NEQ %date:~0,2% (set d=%date:~4,10%) else (set d=%date%)
  148. if / == %date:~2,1% (set d=%date%)
  149. if - == %date:~2,1% (set d=%date%)
  150. set tm=%time:~0,8%
  151. set d=%d:/=-% & set tm=%tm::=-%
  152. set tm=%tm:.=-%
  153. set FILENAME=MXL_Save_%d%_%tm%
  154. set FILENAME=%FILENAME: =%
  155. :SKIPALTDATE
  156. if %USESZIP% == 1 ("%SZIPPATH%" a -y "%BACKUPPATH%\%FILENAME%" "%PATH%")
  157. if %USESZIP% == 1 goto NEXT
  158. if %USEWRAR% == 1 ("%WRARPATH%\rar.exe" a -y -ep1 -rr5 "%BACKUPPATH%\%FILENAME%" "%PATH%")
  159. if %USEWRAR% == 1 goto NEXT
  160. "%SystemRoot%\system32\WindowsPowerShell\v1.0\PowerShell.exe" Compress-Archive -LiteralPath "'%PATH%'" -DestinationPath "'%BACKUPPATH%\%FILENAME%.zip'" -Force
  161. :NEXT
  162. if not exist "%BACKUPPATH%\MXL_curr_cksum.txt" set CURR="N/A - First backup or CHK=0"
  163. if exist "%BACKUPPATH%\%FILENAME%.*" (
  164.     echo Saved %FILENAME% MD5: %CURR%
  165.     echo Saved %FILENAME% MD5: %CURR% >> "%LOGPATH%\MXL_saves_log.txt"
  166.     echo. >> "%LOGPATH%\MXL_saves_log.txt"
  167.     ) else (echo ERROR - CANT CREATE BACKUP "%FILENAME%" >> "%LOGPATH%\MXL_saves_log.txt")
  168. :TIMERCHECK
  169. if %TIMER% == 1 (
  170.     "%SystemRoot%\system32\TIMEOUT" /T %SECS% /NOBREAK
  171.     goto RUN)
  172.  
  173. :END
Add Comment
Please, Sign In to add comment