Advertisement
Nocturnalverse

Save Backup Batchfile for Windows/7zip

Aug 15th, 2018 (edited)
3,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.39 KB | None | 0 0
  1. @echo off
  2. :: Version 2021-09-16-1345
  3. :: You should read the comments in this file. I won't help you figure things out. Ain't nobody got time for that.
  4. :: By using this batch file you acknowledge that it's not my fault if you manage to screw something up.
  5. :: Copy this entire thing to a text file, save it, and change the extension to .bat instead of .txt.
  6. :: Example: Rename NoMansSkyBackup.txt to NoMansSkyBackup.bat
  7. :: You'll have to manually delete excess backups from your _backupFolder. Saves for some games can eat up a lot of space.
  8. :: I'll keep this pastebin updated with whatever template I'm using.
  9.  
  10. :: For the zip function to work you will need to install 7zip. It's safe. It's good. It's free. It's open source.
  11. :: You can remove that bottom section and the files will be copied to folder named TempSavesBackup in your backup folder.
  12. :: This script checks for that folder and exits if it exists.
  13. :: https://www.7-zip.org/
  14.  
  15. :: You must set three variables, _sourceFolder, _backupFolder, and _7zPath. Then you are done.
  16. :: The variables represent the source directory of the save files,
  17. :: the destination directory for the zip file,
  18. :: and the location of your 7zip installation.
  19.  
  20. :: Exists solely for text printed on the screen. It doesn't matter what you put here.
  21. set _gameName=No Man's Sky
  22.  
  23. :: _sourceFolder is the path to your game's saves.
  24. :: Just change the path to whatever it needs to be.
  25. set _sourceFolder=C:\Users\JSmith\AppData\Roaming\HelloGames\NMS\st_99999999999999999
  26.  
  27. :: _backupFolder is where the save data will be copied to and, from there, moved into a zip file.
  28. :: You may need to make sure the path actually exists by creating the folders before you run this batch file.
  29. set _backupFolder=C:\Users\JSmith\Documents\Save Backups\NoMansSkyBackup
  30.  
  31. :: _7zPath is where you installed 7zip.
  32. :: The default installation directory is: C:\Program Files\7-Zip
  33. set _7zPath=C:\Programs\7-Zip
  34.  
  35. :: STOP. No further changes needed.
  36.  
  37. :: EXIT potentially. Rudimentary path and previous attempt validation.
  38. :: If the temporary directory this batch file creates already exists in backupFolder, warn the user and exit.
  39. :: This is to preserve save data if there is some error after copying it.
  40. IF EXIST "%_backupFolder%\TempSavesBackup" (
  41. echo ##################################################################
  42. echo ERROR: The folder TempSavesBackup is in your backup directory.
  43. echo        This means that the folder was not deleted as it should have been during last execution.
  44. echo        There is probably save data in that folder. Save or delete the files at your discretion.
  45. echo ##################################################################
  46. echo:
  47. echo Source      : %_sourceFolder%
  48. echo Destination : %_backupFolder%
  49. echo:
  50. pause
  51. exit
  52. )
  53.  
  54. :: Date and time formatting: YYYY_MM_DD_HH_MM
  55. set hour=%time:~0,2%
  56. if "%hour:~0,1%" == " " set hour=0%time:~1,1%
  57. set _filename=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%_%time:~6,2%_Saves.zip
  58.  
  59. :: Display source and destination
  60. echo Backing up all "%_gameName%" saves...
  61. echo:
  62. echo Source Folder: %_sourceFolder%
  63. echo Destination: %_backupFolder%\%_filename%
  64. echo:
  65.  
  66. :: Forces exit if the copy fails.
  67. :: This preserves any Read Only status and copies _sourceFolder contents _backupFolder\TempSavesBackup
  68. :: Also verifies that they are identical to the source as they are copied.
  69. :: You can manually add a folder to the end of this path if you find it more convenient.
  70. :: Ex. @Xcopy /i /s /e /v /k "%_sourceFolder%" "%_backupFolder%\TempSavesBackup\st_999999999999999999"
  71. @Xcopy /i /s /e /v /k "%_sourceFolder%" "%_backupFolder%\TempSavesBackup"
  72. echo:
  73. if "%ERRORLEVEL%" == "0" (
  74. echo         Copy Succeeded!
  75. ) else (
  76. echo ##########################
  77. echo ##### Copy FAILED! #######
  78. echo ##########################
  79. echo:
  80. echo:
  81. echo Would you like to clean up the TempSavesBackup folder?
  82. echo There may be save data there.
  83. echo You will have to delete it manually if you choose no.
  84. echo:
  85. @RD /s "%_backupFolder%\TempSavesBackup"
  86. echo:
  87. goto CopyFail
  88. )
  89.  
  90. :: Everything below here can be deleted if you don't want 7zip.
  91. :: You should keep the pause unless you are confident.
  92. :: You will have a TempSavesBackup folder in your _backupFolder directory with your save data.
  93. :: If you run this batch file and this folder still exists, the batch file will abort.
  94.  
  95. :: This moves the _backupFolder\TempSavesBackup folder's contents into a zip file and then removes the folder.
  96. @"%_7zPath%\7z" a -sdel "%_backupFolder%\%_filename%" "%_backupFolder%\TempSavesBackup\*"
  97. RD "%_backupFolder%\TempSavesBackup"
  98. echo:
  99. if "%ERRORLEVEL%" == "0" (
  100. echo         Zip Succeeded!
  101. ) else (
  102. echo ##########################
  103. echo ##### Zip FAILED! ########
  104. echo ##########################
  105. )
  106. :CopyFail
  107. echo:
  108. IF EXIST "%_backupFolder%\TempSavesBackup" (
  109. echo ##################################################################
  110. echo ERROR: The folder TempSavesBackup is still in your backup directory.
  111. echo        This means that the folder was not deleted as it should have been.
  112. echo        Files might still be there that should have been moved by 7zip.
  113. echo        You should probably figure out what went wrong, and save or delete the folder at your descretion.
  114. echo ##################################################################
  115. ) else (
  116. echo         TempSavesBackup was removed properly!
  117. )
  118. echo:
  119. :: Require a key press to close the command window.
  120. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement