Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Param (
- [Parameter(Mandatory)][String] $World="Navezgane",
- [Parameter(Mandatory)][String] $SaveName,
- [Int] $Seconds=300,
- [Int] $Retention=10
- )
- Function Start-Countdown {
- Param(
- [Int32]$Seconds = 10,
- [string]$Message = "Pausing for 10 seconds..."
- )
- ForEach ($Count in (1..$Seconds)) {
- Write-Progress -Id 1 -Activity $Message -Status "Waiting for $Seconds seconds, $($Seconds - $Count) left" -PercentComplete (($Count / $Seconds) * 100)
- Start-Sleep -Seconds 1
- }
- Write-Progress -Id 1 -Activity $Message -Status "Completed" -PercentComplete 100 -Completed
- }
- $startDTM=Get-Date
- $jobid=Get-Date $startDTM -f "yyyyMMdd-HHmmss"
- $root="$($env:USERPROFILE)\AppData\Roaming\7DaysToDie"
- $saves="$($root)\Saves\$($World)"
- $backups="$($root)\Backups\$($World)"
- $source="$($saves)\$($SaveName)"
- $targetroot="$($backups)\$($SaveName)"
- Write-Host "Backups will save in $targetroot every $Seconds seconds" -f white
- Write-Host "Press CRTL+C to Exit" -f yellow
- while(1){
- $now=Get-Date
- $id=Get-Date $now -f "yyyyMMdd-HHmmss"
- $label=Get-Date $now -f "MM/dd/yyyy hh:mm:ss"
- $target="$($targetroot)\$($SaveName)_$($id)"
- Write-Host "[$($label)] Backing up to $($World)\$($SaveName)_$($id).zip ... " -NoNewLine
- $null=robocopy $source $target /MIR /NFL /NDL /NJH /NJS /R:5 /W:5
- Compress-Archive -Path $target\* -CompressionLevel Optimal -DestinationPath "$($target).zip"
- if(Test-Path "$($target).zip") {
- Write-Host "SUCCESS" -f green
- Remove-Item $target -Recurse -Force
- } else {
- Write-Host "FAILED" -f red
- }
- # Clean up old archives
- Get-ChildItem -Path $targetroot -Recurse -Include *.zip | sort CreationTime -desc | select -skip $Retention | Foreach-Object { del $_.FullName }
- Start-Countdown -Seconds $Seconds -Message "Press CRTL+C to Exit"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement