Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName System.Windows.Forms
- # uses several other scripts to maintain a week of incremental backups taken every time the server restarts with a new
- # GUI popup status bar to track the steps between boots. Replaces the previous 'runme.bat' file moving everything into powershell.
- # References to dependencies for successful use:
- # Periodic reboot schedule update to DayZ config: https://pastebin.com/1KVDnc4D
- # Powershell for daily dayz incremental backups https://pastebin.com/ibf8ephZ
- # Powershell to limit incremental zips to one week https://pastebin.com/muwsXgG8
- # Powershell to clean zips older than the desired retention period https://pastebin.com/muwsXgG8
- # Powershell to analyze output zip and display summary to powershell console https://pastebin.com/wDntDwJT
- # 20250126 edit: PowerShell doesn't use goto, that was copied from the original .bat in error. I've converted it to a while true
- # loop. I also added a double line write-host to help visually see the different loop output on the powershell console.
- # Create a custom PowerShell object for the form
- $formObject = [PSCustomObject]@{
- Form = $null
- Label = $null
- ProgressBar = $null
- UpdateProgress = {
- param($progress)
- if ($this.ProgressBar -ne $null) {
- $this.ProgressBar.Value = $progress
- }
- }
- UpdateLabel = {
- param($text)
- if ($this.Label -ne $null) {
- $this.Label.Text = $text
- }
- }
- }
- # Method to initialize the form
- function Initialize-Form {
- $formObject.Form = New-Object System.Windows.Forms.Form
- $formObject.Form.Text = 'Progress Window'
- $formObject.Form.Size = New-Object System.Drawing.Size(300,200)
- $formObject.Form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- $formObject.Form.TopMost = $true
- $formObject.Label = New-Object System.Windows.Forms.Label
- $formObject.Label.Text = 'Starting...'
- $formObject.Label.AutoSize = $true
- $formObject.Label.Location = New-Object System.Drawing.Point(10,20)
- $formObject.Form.Controls.Add($formObject.Label)
- $formObject.ProgressBar = New-Object System.Windows.Forms.ProgressBar
- $formObject.ProgressBar.Style = "Continuous"
- $formObject.ProgressBar.Minimum = 0
- $formObject.ProgressBar.Maximum = 100
- $formObject.ProgressBar.Location = New-Object System.Drawing.Point(10,50)
- $formObject.ProgressBar.Size = New-Object System.Drawing.Size(260,23)
- $formObject.Form.Controls.Add($formObject.ProgressBar)
- $formObject.Form.Show()
- }
- # Method to dispose of the form
- function Dispose-Form {
- if ($formObject.Form -ne $null) {
- $formObject.Form.Close()
- $formObject.Form.Dispose()
- }
- }
- # Change directory to where DayZ server is located
- Set-Location -Path "C:\dayz-server"
- #:goon (this was pronounced 'go on')
- while ($true) {
- # Initialize the form
- Initialize-Form
- $i = 0
- $text = "Cleaning zips..."
- $updateLabel = { param($text) $formObject.Label.Text = $text }
- $updateProgress = { param($progress) $formObject.ProgressBar.Value = $progress }
- & $updateLabel -text "Processing: $i%"
- & $updateProgress -progress $i
- [System.Windows.Forms.Application]::DoEvents()
- # Prune then Back-up DayZ between executions
- Write-Host "Cleaning zips..."
- & "c:\users\administrator\documents\clean-zips.ps1"
- $i = 50
- $text = "Incremental backup..."
- $updateLabel = { param($text) $formObject.Label.Text = $text }
- $updateProgress = { param($progress) $formObject.ProgressBar.Value = $progress }
- & $updateLabel -text "Processing: $i%"
- & $updateProgress -progress $i
- [System.Windows.Forms.Application]::DoEvents()
- # Write-Host "Backing up..."
- & "c:\users\administrator\documents\dayz-bak.ps1"
- $i = 100
- $text = "Check for updates..."
- $updateLabel = { param($text) $formObject.Label.Text = $text }
- $updateProgress = { param($progress) $formObject.ProgressBar.Value = $progress }
- & $updateLabel -text "Processing: $i%"
- & $updateProgress -progress $i
- [System.Windows.Forms.Application]::DoEvents()
- # Check for updates
- # Write-Host "Checking for updates..."
- & "c:\dayz-server\UpdateDayz-onceaday.ps1"
- # Cleanup
- Dispose-Form
- # Run the DayZ server
- Write-Host "Running the server..."
- Write-Host "====================="
- Start-Process -FilePath "DayZServer_x64.exe" -ArgumentList "-config=serverDZ.cfg", "-port=2302", "--dologs", "-adminlog", "-netlog", "-freezecheck", "-profiles=c:\dayz-server\DayZServerprofiles" -Wait
- # Loop back to start if the server crashes or stops
- # goto :goon
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement