Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-TimeStamp {
  2.    
  3.     return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
  4.    
  5. }
  6.  
  7. # Set this to the path to your Steam install
  8. $SteamPath = "C:\Program Files (x86)\Steam\"
  9. # Set this to your Steam ID number
  10. $SteamID = "xxxxxxx"
  11.  
  12. #Build the path to the MHW userdata folder
  13. $SaveFile = $SteamPath + "userdata\" + $SteamID + "\582010\remote\SAVEDATA1000"
  14.  
  15. #Path you wish to backup to.  By default to the root of your SteamID folder in Steam's Userdata folder.
  16. $BackupPath = $SteamPath + "userdata\" + $SteamID + "\MHWBackup"
  17. $LogFile = $BackupPath + "\BackupLog.log"
  18. $LastFileHash = $BackupPath + "\LastSaveHash.txt"
  19.  
  20. $SHA256 = Get-FileHash -Path $SaveFile
  21. if(Test-Path $LastFileHash) {
  22.     $LastBackupHash = Get-Content $LastFileHash
  23. }
  24. else {
  25.     $LastBackupHash = ""
  26. }
  27.  
  28. Write-Output "$(Get-TimeStamp) Hash of current save is $($SHA256.Hash)" | Out-File -FilePath $Logfile -Append
  29.  
  30. if ($SHA256.Hash -ne $LastBackupHash) {
  31.     Write-Output "$(Get-TimeStamp) hash of last save is $LastBackupHash.  Performing backup of new save file." | Out-File -FilePath $LogFile -Append
  32.     $Timestamp = Get-Date -Format "yyyyMMdd_HHmmss-"
  33.     #Compress a copy of the current save file to the backup path
  34.     Compress-Archive -Path $SaveFile -Destinationpath ($BackupPath + "\" + $TimeStamp + "Backup.zip") -CompressionLevel Optimal
  35.     Write-Output "$(Get-TimeStamp) Backed up to $BackupPath\$TimeStamp`Backup.zip" | Out-File -FilePath $Logfile -Append
  36.     #Update the LastFileHash
  37.     $SHA256.Hash | Out-File -FilePath $LastFileHash -Force
  38. }
  39. else {
  40.     Write-Output "$(Get-TimeStamp) Hash of last save is $LastBackupHash.  No changes to save file, no backup needed." | Out-File -FilePath $Logfile -Append
  41. }
  42.  
  43. Write-Output "$(Get-TimeStamp) Backup process complete." | Out-File -FilePath $Logfile -Append
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement