Advertisement
Wdrussll1

Valheim Backup Script - Linux

Feb 16th, 2021
1,873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.00 KB | None | 0 0
  1. ### Valheim data backup script
  2. #Created by Wdrussell1/Demon1337/Casey Barrett
  3. ### Backs up the entire appdata folder including characters/world data
  4. ## Note: If you get errors running the script, run the following:
  5. ## Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
  6. #**************************************************************************
  7. ## **************************CONFIGURATION ITEMS***************************
  8. #**************************************************************************
  9. # How many backups to keep before pruning older copies (Default is 10)
  10. NumToKeep=10
  11. # Where to save backups (Default is $HOME/ValheimBackups/)
  12. BackupFolderPath=$HOME/ValheimBackups/
  13. # Server world file location (Default is $HOME/Valheim)
  14. Worldsavelocation=$HOME/Valheim
  15. #**************************************************************************
  16. ## ***********************END OF CONFIGURATION ITEMS***********************
  17. #**************************************************************************
  18. #**************************************************************************
  19. #*******************DO NOT MODIFY ANYTHING BEYOND THIS POINT***************
  20. #**************************************************************************
  21. #**************************************************************************
  22. #**************************************************************************
  23. ## Main Script
  24. #Create the backup folder should it not exist
  25. if [[ ! -d $BackupFolderPath ]]
  26. then
  27.     echo "$BackupFolderPath does not exist on your filesystem."
  28.     mkdir $BackupFolderPath
  29. fi
  30. #
  31. #Get current date and time
  32. Date=$(date +%Y-%m-%d-%H-%M-%S)
  33. #
  34. #Put current date and time in the file name saving the TAR/ZIP in the file location you requested.
  35. tar -czvf $BackupFolderPath$Date.tar.gz $Worldsavelocation
  36. #
  37. #
  38. ##Parsing backups
  39. #Because linux..we have to add 1 to the NumToKeep variable
  40. Sum=`echo "$NumToKeep + 1" | bc`
  41. #
  42. #Removing old backups
  43. ls -dt $HOME/ValheimBackups/* | tail -n +$Sum | xargs rm -rf
  44. #
  45. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement