Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-TimeStamp {
- return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
- }
- # Set this to the path to your Steam install
- $SteamPath = "C:\Program Files (x86)\Steam\"
- # Set this to your Steam ID number
- $SteamID = "xxxxxxx"
- #Build the path to the MHW userdata folder
- $SaveFile = $SteamPath + "userdata\" + $SteamID + "\582010\remote\SAVEDATA1000"
- #Path you wish to backup to. By default to the root of your SteamID folder in Steam's Userdata folder.
- $BackupPath = $SteamPath + "userdata\" + $SteamID + "\MHWBackup"
- $LogFile = $BackupPath + "\BackupLog.log"
- $LastFileHash = $BackupPath + "\LastSaveHash.txt"
- $SHA256 = Get-FileHash -Path $SaveFile
- if(Test-Path $LastFileHash) {
- $LastBackupHash = Get-Content $LastFileHash
- }
- else {
- $LastBackupHash = ""
- }
- Write-Output "$(Get-TimeStamp) Hash of current save is $($SHA256.Hash)" | Out-File -FilePath $Logfile -Append
- if ($SHA256.Hash -ne $LastBackupHash) {
- Write-Output "$(Get-TimeStamp) hash of last save is $LastBackupHash. Performing backup of new save file." | Out-File -FilePath $LogFile -Append
- $Timestamp = Get-Date -Format "yyyyMMdd_HHmmss-"
- #Compress a copy of the current save file to the backup path
- Compress-Archive -Path $SaveFile -Destinationpath ($BackupPath + "\" + $TimeStamp + "Backup.zip") -CompressionLevel Optimal
- Write-Output "$(Get-TimeStamp) Backed up to $BackupPath\$TimeStamp`Backup.zip" | Out-File -FilePath $Logfile -Append
- #Update the LastFileHash
- $SHA256.Hash | Out-File -FilePath $LastFileHash -Force
- }
- else {
- Write-Output "$(Get-TimeStamp) Hash of last save is $LastBackupHash. No changes to save file, no backup needed." | Out-File -FilePath $Logfile -Append
- }
- Write-Output "$(Get-TimeStamp) Backup process complete." | Out-File -FilePath $Logfile -Append
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement