proxmoxclient_go_gui.ps1 aktualisiert
This commit is contained in:
+22
-18
@@ -1,4 +1,4 @@
|
|||||||
# --- Automatisch als Admin neu starten ---
|
# --- Automatic Admin Restart (Self-Elevation) ---
|
||||||
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||||
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
|
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
|
||||||
Start-Process powershell.exe -ArgumentList $arguments -Verb RunAs
|
Start-Process powershell.exe -ArgumentList $arguments -Verb RunAs
|
||||||
@@ -8,7 +8,7 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
|
|||||||
Add-Type -AssemblyName System.Windows.Forms
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
Add-Type -AssemblyName System.Drawing
|
Add-Type -AssemblyName System.Drawing
|
||||||
|
|
||||||
# --- Styling ---
|
# --- Styling & Colors ---
|
||||||
$color_bg = [System.Drawing.Color]::FromArgb(45, 52, 71)
|
$color_bg = [System.Drawing.Color]::FromArgb(45, 52, 71)
|
||||||
$color_sidebar = [System.Drawing.Color]::FromArgb(35, 40, 55)
|
$color_sidebar = [System.Drawing.Color]::FromArgb(35, 40, 55)
|
||||||
$color_text = [System.Drawing.Color]::White
|
$color_text = [System.Drawing.Color]::White
|
||||||
@@ -18,21 +18,20 @@ $color_delete = [System.Drawing.Color]::FromArgb(220, 53, 69)
|
|||||||
$font_main = New-Object System.Drawing.Font("Segoe UI", 10)
|
$font_main = New-Object System.Drawing.Font("Segoe UI", 10)
|
||||||
$font_bold = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold)
|
$font_bold = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold)
|
||||||
|
|
||||||
# --- Pfade ---
|
# --- Files & Paths ---
|
||||||
$jobFile = "$PSScriptRoot\backup_jobs.json"
|
$jobFile = "$PSScriptRoot\backup_jobs.json"
|
||||||
if (-not (Test-Path $jobFile)) { "{}" | Out-File $jobFile -Encoding utf8 }
|
if (-not (Test-Path $jobFile)) { "{}" | Out-File $jobFile -Encoding utf8 }
|
||||||
|
|
||||||
$mainForm = New-Object System.Windows.Forms.Form
|
$mainForm = New-Object System.Windows.Forms.Form
|
||||||
$mainForm.Text = "proxmoxbackupclient_go GUI"
|
$mainForm.Text = "proxmoxbackupclient_go-GUI"
|
||||||
$mainForm.Size = "950, 850"
|
$mainForm.Size = "950, 850"
|
||||||
$mainForm.StartPosition = "CenterScreen"
|
$mainForm.StartPosition = "CenterScreen"
|
||||||
$mainForm.BackColor = $color_bg
|
$mainForm.BackColor = $color_bg
|
||||||
$mainForm.ForeColor = $color_text
|
$mainForm.ForeColor = $color_text
|
||||||
|
|
||||||
# --- Funktionen ---
|
# --- Helper Functions ---
|
||||||
function Get-PhysicalDisks {
|
function Get-PhysicalDisks {
|
||||||
return Get-CimInstance Win32_DiskDrive | ForEach-Object {
|
return Get-CimInstance Win32_DiskDrive | ForEach-Object {
|
||||||
# Hier erzwingen wir die korrekte Schreibweise direkt beim Einlesen
|
|
||||||
$cleanId = $_.DeviceID -replace "PHYSICALDRIVE", "PhysicalDrive"
|
$cleanId = $_.DeviceID -replace "PHYSICALDRIVE", "PhysicalDrive"
|
||||||
@{ ID = $cleanId; Name = "Disk $($_.Index): $($_.Model) ($cleanId)" }
|
@{ ID = $cleanId; Name = "Disk $($_.Index): $($_.Model) ($cleanId)" }
|
||||||
}
|
}
|
||||||
@@ -51,7 +50,7 @@ function Update-List {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- UI Komponenten ---
|
# --- UI Components ---
|
||||||
$labelJob = New-Object System.Windows.Forms.Label
|
$labelJob = New-Object System.Windows.Forms.Label
|
||||||
$labelJob.Text = "Backup Job Name"; $labelJob.Location = "30, 25"; $labelJob.AutoSize = $true; $labelJob.Font = $font_bold
|
$labelJob.Text = "Backup Job Name"; $labelJob.Location = "30, 25"; $labelJob.AutoSize = $true; $labelJob.Font = $font_bold
|
||||||
$txtJobName = New-Object System.Windows.Forms.TextBox
|
$txtJobName = New-Object System.Windows.Forms.TextBox
|
||||||
@@ -107,6 +106,7 @@ $comboInterval.Items.AddRange(@("Daily", "Weekly (Mon)", "Hourly"))
|
|||||||
$comboInterval.SelectedIndex = 0
|
$comboInterval.SelectedIndex = 0
|
||||||
$mainForm.Controls.AddRange(@($lblInterval, $comboInterval))
|
$mainForm.Controls.AddRange(@($lblInterval, $comboInterval))
|
||||||
|
|
||||||
|
# --- Sidebar (Jobs) ---
|
||||||
$listBox = New-Object System.Windows.Forms.ListBox
|
$listBox = New-Object System.Windows.Forms.ListBox
|
||||||
$listBox.Location = "600, 50"; $listBox.Size = "300, 530"; $listBox.BackColor = $color_sidebar; $listBox.ForeColor = "White"
|
$listBox.Location = "600, 50"; $listBox.Size = "300, 530"; $listBox.BackColor = $color_sidebar; $listBox.ForeColor = "White"
|
||||||
$listBox.Add_SelectedIndexChanged({
|
$listBox.Add_SelectedIndexChanged({
|
||||||
@@ -129,7 +129,7 @@ $listBox.Add_SelectedIndexChanged({
|
|||||||
} else { $radioDir.Checked = $true; $txtDirSource.Text = $job.source }
|
} else { $radioDir.Checked = $true; $txtDirSource.Text = $job.source }
|
||||||
})
|
})
|
||||||
|
|
||||||
# --- AKTIONEN ---
|
# --- Actions ---
|
||||||
|
|
||||||
$btnSave = New-Object System.Windows.Forms.Button
|
$btnSave = New-Object System.Windows.Forms.Button
|
||||||
$btnSave.Text = "Save Job"; $btnSave.Location = "30, 680"; $btnSave.Size = "150, 45"; $btnSave.FlatStyle = "Flat"; $btnSave.BackColor = $color_save
|
$btnSave.Text = "Save Job"; $btnSave.Location = "30, 680"; $btnSave.Size = "150, 45"; $btnSave.FlatStyle = "Flat"; $btnSave.BackColor = $color_save
|
||||||
@@ -165,7 +165,7 @@ $btnSave.Add_Click({
|
|||||||
$jobs.PSObject.Properties.Add((New-Object System.Management.Automation.PSNoteProperty($txtJobName.Text, $jobData)))
|
$jobs.PSObject.Properties.Add((New-Object System.Management.Automation.PSNoteProperty($txtJobName.Text, $jobData)))
|
||||||
$jobs | ConvertTo-Json -Depth 10 | Out-File $jobFile -Encoding utf8
|
$jobs | ConvertTo-Json -Depth 10 | Out-File $jobFile -Encoding utf8
|
||||||
Update-List
|
Update-List
|
||||||
[System.Windows.Forms.MessageBox]::Show("Job gespeichert.")
|
[System.Windows.Forms.MessageBox]::Show("Job saved successfully.")
|
||||||
})
|
})
|
||||||
|
|
||||||
$btnRun = New-Object System.Windows.Forms.Button
|
$btnRun = New-Object System.Windows.Forms.Button
|
||||||
@@ -176,9 +176,10 @@ $btnRun.Add_Click({
|
|||||||
|
|
||||||
if ($job.mode -eq "machine") {
|
if ($job.mode -eq "machine") {
|
||||||
$exe = "$PSScriptRoot\pbsmachinebackup.exe"
|
$exe = "$PSScriptRoot\pbsmachinebackup.exe"
|
||||||
$drive = $job.source.Trim()
|
$argString = "-baseurl `"$($job.url)`" -certfingerprint `"$($job.fp)`" -authid `"$($job.token)`" -secret `"$($job.secret)`" -datastore `"$($job.store)`""
|
||||||
# Hier nutzen wir den exakten String-Bau
|
foreach ($d in $job.source.Split(",")) {
|
||||||
$argString = "-baseurl `"$($job.url)`" -certfingerprint `"$($job.fp)`" -authid `"$($job.token)`" -secret `"$($job.secret)`" -datastore `"$($job.store)`" -backupdev $drive"
|
$argString += " -backupdev $($d.Trim())"
|
||||||
|
}
|
||||||
Start-Process $exe -ArgumentList $argString -Wait
|
Start-Process $exe -ArgumentList $argString -Wait
|
||||||
} else {
|
} else {
|
||||||
$exe = "$PSScriptRoot\pbsdirectorybackup.exe"
|
$exe = "$PSScriptRoot\pbsdirectorybackup.exe"
|
||||||
@@ -194,13 +195,12 @@ $btnSchedule.Add_Click({
|
|||||||
$jobs = Get-Content $jobFile | ConvertFrom-Json; $job = $jobs.$jobName
|
$jobs = Get-Content $jobFile | ConvertFrom-Json; $job = $jobs.$jobName
|
||||||
|
|
||||||
$exe = if($job.mode -eq "machine") { "$PSScriptRoot\pbsmachinebackup.exe" } else { "$PSScriptRoot\pbsdirectorybackup.exe" }
|
$exe = if($job.mode -eq "machine") { "$PSScriptRoot\pbsmachinebackup.exe" } else { "$PSScriptRoot\pbsdirectorybackup.exe" }
|
||||||
|
$args = "-baseurl `"$($job.url)`" -certfingerprint `"$($job.fp)`" -authid `"$($job.token)`" -secret `"$($job.secret)`" -datastore `"$($job.store)`""
|
||||||
|
|
||||||
# Der kritische Teil: Der Argument-String für den Scheduler
|
|
||||||
if ($job.mode -eq "machine") {
|
if ($job.mode -eq "machine") {
|
||||||
$dev = $job.source.Trim()
|
foreach ($d in $job.source.Split(",")) { $args += " -backupdev $($d.Trim())" }
|
||||||
$args = "-baseurl `"$($job.url)`" -certfingerprint `"$($job.fp)`" -authid `"$($job.token)`" -secret `"$($job.secret)`" -datastore `"$($job.store)`" -backupdev $dev"
|
|
||||||
} else {
|
} else {
|
||||||
$args = "-baseurl `"$($job.url)`" -certfingerprint `"$($job.fp)`" -authid `"$($job.token)`" -secret `"$($job.secret)`" -datastore `"$($job.store)`" -backupdir `"$($job.source)`""
|
$args += " -backupdir `"$($job.source)`""
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = New-ScheduledTaskAction -Execute $exe -Argument $args -WorkingDirectory $PSScriptRoot
|
$action = New-ScheduledTaskAction -Execute $exe -Argument $args -WorkingDirectory $PSScriptRoot
|
||||||
@@ -216,7 +216,7 @@ $btnSchedule.Add_Click({
|
|||||||
}
|
}
|
||||||
|
|
||||||
Register-ScheduledTask -TaskName "PBS_Backup_$jobName" -Action $action -Trigger $trigger -Principal (New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest) -Force
|
Register-ScheduledTask -TaskName "PBS_Backup_$jobName" -Action $action -Trigger $trigger -Principal (New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest) -Force
|
||||||
[System.Windows.Forms.MessageBox]::Show("Scheduled job created")
|
[System.Windows.Forms.MessageBox]::Show("Job successfully added to Task Scheduler.")
|
||||||
})
|
})
|
||||||
|
|
||||||
$btnDelete = New-Object System.Windows.Forms.Button
|
$btnDelete = New-Object System.Windows.Forms.Button
|
||||||
@@ -224,10 +224,14 @@ $btnDelete.Text = "Delete"; $btnDelete.Location = "190, 680"; $btnDelete.Size =
|
|||||||
$btnDelete.Add_Click({
|
$btnDelete.Add_Click({
|
||||||
$jobName = $listBox.SelectedItem; if (-not $jobName) { return }
|
$jobName = $listBox.SelectedItem; if (-not $jobName) { return }
|
||||||
$jobs = Get-Content $jobFile | ConvertFrom-Json
|
$jobs = Get-Content $jobFile | ConvertFrom-Json
|
||||||
|
if ([System.Windows.Forms.MessageBox]::Show("Are you sure you want to delete job '$jobName'?", "Confirm", "YesNo") -eq "Yes") {
|
||||||
$jobs.PSObject.Properties.Remove($jobName)
|
$jobs.PSObject.Properties.Remove($jobName)
|
||||||
$jobs | ConvertTo-Json | Out-File $jobFile -Encoding utf8
|
$jobs | ConvertTo-Json | Out-File $jobFile -Encoding utf8
|
||||||
if (Get-ScheduledTask -TaskName "PBS_Backup_$jobName" -ErrorAction SilentlyContinue) { Unregister-ScheduledTask -TaskName "PBS_Backup_$jobName" -Confirm:$false }
|
if (Get-ScheduledTask -TaskName "PBS_Backup_$jobName" -ErrorAction SilentlyContinue) {
|
||||||
|
Unregister-ScheduledTask -TaskName "PBS_Backup_$jobName" -Confirm:$false
|
||||||
|
}
|
||||||
Update-List
|
Update-List
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
$mainForm.Controls.AddRange(@($labelJob, $txtJobName, $groupMode, $panelSource, $btnSave, $btnDelete, $btnRun, $btnSchedule, $listBox))
|
$mainForm.Controls.AddRange(@($labelJob, $txtJobName, $groupMode, $panelSource, $btnSave, $btnDelete, $btnRun, $btnSchedule, $listBox))
|
||||||
|
|||||||
Reference in New Issue
Block a user