Update install-AdHoc-Backup.ps1
This commit is contained in:
parent
dcbbf35392
commit
6ac4c16c37
@ -13,15 +13,11 @@ $BackupScriptName = "AdHoc-Backup.ps1"
|
||||
# Nome del file di configurazione
|
||||
$ConfigFileName = "backup.conf"
|
||||
|
||||
# (OPZIONALE) Base URL da cui scaricare i file
|
||||
# Metti l'URL del tuo webserver / share http se li distribuisci così
|
||||
$DownloadBaseUrl = "" # es. "https://intranet/polo/scripts"
|
||||
|
||||
# Elenco dei file da scaricare in modalità "installa lo script"
|
||||
$FilesToDownload = @(
|
||||
$BackupScriptName,
|
||||
$ConfigFileName
|
||||
)
|
||||
# Qui mettiamo direttamente i tuoi link
|
||||
$DownloadMap = @{
|
||||
"AdHoc-Backup.ps1" = "https://gitea.poloinformatico.it/Mattia/Backup-AdHoc/raw/branch/main/AdHoc-Backup.ps1"
|
||||
"backup.conf" = "https://gitea.poloinformatico.it/Mattia/Backup-AdHoc/raw/branch/main/backup.conf"
|
||||
}
|
||||
|
||||
# ==========================
|
||||
# FUNZIONI DI SUPPORTO
|
||||
@ -40,10 +36,6 @@ function Download-File {
|
||||
[string]$Url,
|
||||
[string]$Destination
|
||||
)
|
||||
if ([string]::IsNullOrWhiteSpace($Url)) {
|
||||
Write-Warning "URL non impostato per $Destination, salto il download."
|
||||
return
|
||||
}
|
||||
try {
|
||||
Write-Host "Scarico $Url -> $Destination"
|
||||
Invoke-WebRequest -Uri $Url -OutFile $Destination -UseBasicParsing
|
||||
@ -164,17 +156,11 @@ function Install-AdHocBackup {
|
||||
Write-Host "== INSTALLAZIONE SCRIPT BACKUP ==" -ForegroundColor Cyan
|
||||
Ensure-Folder -Path $InstallRoot
|
||||
|
||||
foreach ($f in $FilesToDownload) {
|
||||
$dest = Join-Path $InstallRoot $f
|
||||
if (-not [string]::IsNullOrWhiteSpace($DownloadBaseUrl)) {
|
||||
$url = ($DownloadBaseUrl.TrimEnd('/')) + "/" + $f
|
||||
foreach ($entry in $DownloadMap.GetEnumerator()) {
|
||||
$fileName = $entry.Key
|
||||
$url = $entry.Value
|
||||
$dest = Join-Path $InstallRoot $fileName
|
||||
Download-File -Url $url -Destination $dest
|
||||
} else {
|
||||
# Se non abbiamo URL, non sovrascriviamo: assumiamo che lo script sia già nella stessa cartella
|
||||
if (-not (Test-Path $dest)) {
|
||||
Write-Warning "File $f non trovato e nessun URL impostato. Copialo manualmente in $InstallRoot."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configPath = Join-Path $InstallRoot $ConfigFileName
|
||||
@ -208,7 +194,8 @@ function Create-BackupScheduledTask {
|
||||
return
|
||||
}
|
||||
|
||||
# Ora di esecuzione
|
||||
Write-Host ""
|
||||
Write-Host "Impostazione orario di esecuzione" -ForegroundColor Cyan
|
||||
$hour = Read-Host "Inserisci l'ora di esecuzione (0-23) [default 22]"
|
||||
if ([string]::IsNullOrWhiteSpace($hour)) { $hour = 22 }
|
||||
$minute = Read-Host "Inserisci i minuti (0-59) [default 30]"
|
||||
@ -226,7 +213,6 @@ function Create-BackupScheduledTask {
|
||||
}
|
||||
|
||||
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$backupScriptPath`""
|
||||
# Eseguiamo come SYSTEM con privilegi alti
|
||||
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
||||
|
||||
@ -234,7 +220,7 @@ function Create-BackupScheduledTask {
|
||||
|
||||
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
|
||||
|
||||
Write-Host "Pianificazione '$taskName' creata in modalità $Mode." -ForegroundColor Green
|
||||
Write-Host "Pianificazione '$taskName' creata in modalità $Mode alle $hour`:$minute." -ForegroundColor Green
|
||||
}
|
||||
|
||||
function Show-ScheduleMenu {
|
||||
@ -263,10 +249,9 @@ function Edit-BackupConfig {
|
||||
Ensure-DefaultConfig -ConfigPath $ConfigPath
|
||||
}
|
||||
|
||||
# Descrizioni in italiano per aiutare l'utente
|
||||
$Descriptions = [ordered]@{
|
||||
"BackupRoot" = "Cartella radice dove vanno archivi, log e tool."
|
||||
"LocalRetentionDaysFiles"= "Giorni di conservazione FILE in locale."
|
||||
"LocalRetentionDaysFiles" = "Giorni di conservazione FILE in locale."
|
||||
"LocalRetentionDaysDb" = "Giorni di conservazione DATABASE in locale."
|
||||
"RemoteRetentionDays" = "Giorni di conservazione su destinazione remota (rclone)."
|
||||
"KeepLocalArchives" = "true = tiene una copia locale dopo l'upload."
|
||||
@ -274,13 +259,13 @@ function Edit-BackupConfig {
|
||||
"EnableRcloneUpload" = "true = dopo il backup carica su cloud tramite rclone."
|
||||
"ArchiveSources" = "Elenco cartelle/sorgenti da salvare, separate da | (pipe)."
|
||||
"EnableSqlBackup" = "true = fa anche i backup dei database SQL Server."
|
||||
"SqlInstance" = "Nome o indirizzo dell'istanza SQL Server (es. localhost\SQLEXPRESS)."
|
||||
"SqlUseWindowsAuth" = "true = usa l'utente Windows corrente; false = usa SqlUser/SqlPassword."
|
||||
"SqlInstance" = "Nome/istanza SQL Server (es. localhost\SQLEXPRESS)."
|
||||
"SqlUseWindowsAuth" = "true = usa utente Windows; false = usa SqlUser/SqlPassword."
|
||||
"SqlUser" = "Utente SQL (se SqlUseWindowsAuth=false)."
|
||||
"SqlPassword" = "Password SQL (se SqlUseWindowsAuth=false)."
|
||||
"DbInclude" = "Elenco DB da includere (se vuoto li prende tutti tranne gli esclusi)."
|
||||
"DbExclude" = "DB da escludere quando DbInclude è vuoto."
|
||||
"SqlCompressStage" = "true = comprime i .bak in uno .7z."
|
||||
"SqlCompressStage" = "true = comprime i .bak in .7z."
|
||||
"SqlDropBakAfterZip" = "true = elimina i .bak dopo la compressione."
|
||||
"SevenZipCompressionLevel" = "0..9 livello di compressione 7z (1=veloce, 9=max)."
|
||||
"RcloneRemoteDest" = "Destinazione rclone: REMOTO:percorso."
|
||||
@ -325,9 +310,9 @@ do {
|
||||
Write-Host "==============================" -ForegroundColor DarkCyan
|
||||
Write-Host " INSTALL ADHOC BACKUP - MENU"
|
||||
Write-Host "==============================" -ForegroundColor DarkCyan
|
||||
Write-Host "1) Installa / aggiorna script"
|
||||
Write-Host "2) Crea pianificazione (giornaliera/settimanale)"
|
||||
Write-Host "3) Modifica configurazione backup.conf"
|
||||
Write-Host "1) Installa / aggiorna script (scarica da gitea)"
|
||||
Write-Host "2) Crea pianificazione (giornaliera/settimanale, con orario)"
|
||||
Write-Host "3) Modifica configurazione backup.conf (guidata)"
|
||||
Write-Host "0) Esci"
|
||||
$sel = Read-Host "Seleziona"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user