Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- :: Version 2021-09-16-1345
- :: You should read the comments in this file. I won't help you figure things out. Ain't nobody got time for that.
- :: By using this batch file you acknowledge that it's not my fault if you manage to screw something up.
- :: Copy this entire thing to a text file, save it, and change the extension to .bat instead of .txt.
- :: Example: Rename NoMansSkyBackup.txt to NoMansSkyBackup.bat
- :: You'll have to manually delete excess backups from your _backupFolder. Saves for some games can eat up a lot of space.
- :: I'll keep this pastebin updated with whatever template I'm using.
- :: 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.
- :: You can remove that bottom section and the files will be copied to folder named TempSavesBackup in your backup folder.
- :: This script checks for that folder and exits if it exists.
- :: https://www.7-zip.org/
- :: You must set three variables, _sourceFolder, _backupFolder, and _7zPath. Then you are done.
- :: The variables represent the source directory of the save files,
- :: the destination directory for the zip file,
- :: and the location of your 7zip installation.
- :: Exists solely for text printed on the screen. It doesn't matter what you put here.
- set _gameName=No Man's Sky
- :: _sourceFolder is the path to your game's saves.
- :: Just change the path to whatever it needs to be.
- set _sourceFolder=C:\Users\JSmith\AppData\Roaming\HelloGames\NMS\st_99999999999999999
- :: _backupFolder is where the save data will be copied to and, from there, moved into a zip file.
- :: You may need to make sure the path actually exists by creating the folders before you run this batch file.
- set _backupFolder=C:\Users\JSmith\Documents\Save Backups\NoMansSkyBackup
- :: _7zPath is where you installed 7zip.
- :: The default installation directory is: C:\Program Files\7-Zip
- set _7zPath=C:\Programs\7-Zip
- :: STOP. No further changes needed.
- :: EXIT potentially. Rudimentary path and previous attempt validation.
- :: If the temporary directory this batch file creates already exists in backupFolder, warn the user and exit.
- :: This is to preserve save data if there is some error after copying it.
- IF EXIST "%_backupFolder%\TempSavesBackup" (
- echo ##################################################################
- echo ERROR: The folder TempSavesBackup is in your backup directory.
- echo This means that the folder was not deleted as it should have been during last execution.
- echo There is probably save data in that folder. Save or delete the files at your discretion.
- echo ##################################################################
- echo:
- echo Source : %_sourceFolder%
- echo Destination : %_backupFolder%
- echo:
- pause
- exit
- )
- :: Date and time formatting: YYYY_MM_DD_HH_MM
- set hour=%time:~0,2%
- if "%hour:~0,1%" == " " set hour=0%time:~1,1%
- set _filename=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%_%time:~6,2%_Saves.zip
- :: Display source and destination
- echo Backing up all "%_gameName%" saves...
- echo:
- echo Source Folder: %_sourceFolder%
- echo Destination: %_backupFolder%\%_filename%
- echo:
- :: Forces exit if the copy fails.
- :: This preserves any Read Only status and copies _sourceFolder contents _backupFolder\TempSavesBackup
- :: Also verifies that they are identical to the source as they are copied.
- :: You can manually add a folder to the end of this path if you find it more convenient.
- :: Ex. @Xcopy /i /s /e /v /k "%_sourceFolder%" "%_backupFolder%\TempSavesBackup\st_999999999999999999"
- @Xcopy /i /s /e /v /k "%_sourceFolder%" "%_backupFolder%\TempSavesBackup"
- echo:
- if "%ERRORLEVEL%" == "0" (
- echo Copy Succeeded!
- ) else (
- echo ##########################
- echo ##### Copy FAILED! #######
- echo ##########################
- echo:
- echo:
- echo Would you like to clean up the TempSavesBackup folder?
- echo There may be save data there.
- echo You will have to delete it manually if you choose no.
- echo:
- @RD /s "%_backupFolder%\TempSavesBackup"
- echo:
- goto CopyFail
- )
- :: Everything below here can be deleted if you don't want 7zip.
- :: You should keep the pause unless you are confident.
- :: You will have a TempSavesBackup folder in your _backupFolder directory with your save data.
- :: If you run this batch file and this folder still exists, the batch file will abort.
- :: This moves the _backupFolder\TempSavesBackup folder's contents into a zip file and then removes the folder.
- @"%_7zPath%\7z" a -sdel "%_backupFolder%\%_filename%" "%_backupFolder%\TempSavesBackup\*"
- RD "%_backupFolder%\TempSavesBackup"
- echo:
- if "%ERRORLEVEL%" == "0" (
- echo Zip Succeeded!
- ) else (
- echo ##########################
- echo ##### Zip FAILED! ########
- echo ##########################
- )
- :CopyFail
- echo:
- IF EXIST "%_backupFolder%\TempSavesBackup" (
- echo ##################################################################
- echo ERROR: The folder TempSavesBackup is still in your backup directory.
- echo This means that the folder was not deleted as it should have been.
- echo Files might still be there that should have been moved by 7zip.
- echo You should probably figure out what went wrong, and save or delete the folder at your descretion.
- echo ##################################################################
- ) else (
- echo TempSavesBackup was removed properly!
- )
- echo:
- :: Require a key press to close the command window.
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement