Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- :: By using this batch file you acknowledge that it's not my fault if you manage to screw something up.
- :: You should read the comments in this file.
- :: Copy this entire thing to a text editor and save it as the type "all files" and add a .bat extension on the end.
- :: Example: ValheimBackup.bat
- :: You'll have to manually delete excess backups.
- :: 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.
- :: https://www.7-zip.org/
- :: You need to 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.
- :: _sourceFolder probably just needs a user name change.
- :: It will have a Valheim Folder inside it.
- :: You can probably just change the user name part of the path to whatever your directory is called.
- set _sourceFolder=C:\Users\FakeUserName\AppData\LocalLow\IronGate
- :: _backupFolder is where the settings and save data will be copied to and, from there, moved into a zip file.
- :: You can probably just change the user name part of the path here as well.
- set _backupFolder=C:\Libraries\FakeUserName\Documents\Save Backups\Valheim Backup
- :: _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.
- :: Remove this section if you remove the 7zip section.
- 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 on the previous execution.
- echo You should probably figure out what went wrong and save or delete the folder at your descretion.
- 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 Valheim save...
- echo:
- echo Source Folder: %_sourceFolder%
- echo Destination: %_backupFolder%\%_filename%
- echo:
- :: This preserves any Read Only status and copies COTW's saves and settings folders and contents to backupFolder\TempSavesBackup
- :: Also verifies that they are identical to the source as they are copied.
- :: Forces exit if the copy fails.
- @Xcopy /i /s /e /v /k "%_sourceFolder%" "%_backupFolder%\TempSavesBackup"
- ::@Xcopy /i /s /e /v /k "%_sourceFolder%" "%_backupFolder%\TempSavesBackup"
- echo:
- if "%ERRORLEVEL%" == "0" (
- echo Copy Succeeded!
- ) else (
- echo ##########################
- echo ##### Copy FAILED! #######
- echo ##########################
- echo:
- pause
- exit
- )
- :: Any section below here can be deleted if you don't want it.
- :: If you do delete this 7zip portion, go back up to the top and delete that validation section.
- :: You will still end up with a TempSavesBackup folder in your backupFolder directory to do with as you please.
- :: This moves the newly created 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 ##########################
- )
- 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 discretion.
- echo ##################################################################
- ) else (
- echo TempSavesBackup was removed properly!
- )
- echo:
- :: Require a key press to close the command window.
- pause
Add Comment
Please, Sign In to add comment