Written on 2. Januar 2023

Synology Active Backup for Business – Letztes Backup auf USB Laufwerk

Hier ist ein PowerShell-Skript, das verwendet werden kann, um das letzte Active Backup for Business Backup vom Synology auf ein externes USB-Laufwerk zu kopieren:

Synology – Active Backup for Business
# Set the path to the 7-zip executable
$sevenZipExe = "C:\Program Files-Zipz.exe"

# Set the path to the USB drive
$usbDrive = "E:"

# Set the path to the location where the backup should be saved on the USB drive
$backupPath = "$usbDrive\Backups"

# Set the path to the log file
$logFile = "$backupPath\Backup_Log.txt"

# Create the backup path on the USB drive if it doesn't already exist

if (!(Test-Path -Path $backupPath))
{
    New-Item -ItemType Directory -Path $backupPath
}

# Create the log file if it doesn't already exist
if(!(Test-Path $logFile))
{
    New-Item -ItemType File -Path $logFile
}

# Set the path to the location of the folders to be backed up
$sourcePath = "\\synology\ActiveBackupData\VM-vSphere-Task-1"

# Get the newst folder in the source path
$newestFolder = Get-ChildItem -Path $sourcePath | Sort-Object LastWriteTime -Descending | Select-Object -First 1

# Set the name for the backup file
$backupFileName = "$($newestFolder.Name)_Backup_$(Get-Date -Format yyyy-MM-dd).zip"

# Write log
Add-Content -Path $logFile -Value "$(Get-Date): Starting backup process"

# Remove old folders in the backup path
Get-ChildItem -Path $backupPath -Directory | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Remove-Item -Recurse | Add-Content -Path $logFile

# Create a zip archive of the newst folder and save it to the USB drive
& $sevenZipExe a -tzip "$backupPath$backupFileName" "$sourcePath$newestFolder" | Add-Content -Path $logFile

# Confirm that the backup was created successfully and add a message to the log file
if (Test-Path -Path "$backupPath$backupFileName")
{
    Add-Content -Path $logFile -Value "$(Get-Date): Backup of newest folder successfully saved to $backupPath$backupFileName on USB drive"
}
else 
{
    Add-Content -Path $logFile -Value "$(Get-Date): Error: Backup of newest folder failed to save to $backupPath$backupFileName on USB drive."
}

Das Skript geht davon aus, dass der Quellpfad \\synology\ActiveBackupData\VM-vSphere-Task-1 und der Zielpfad E:\Backups ist. Diese Pfade müssen an die spezifische Konfiguration angepasst werden.

Das Skript erstellt zunächst eine Liste aller Backups im Quellordner, sortiert diese dann nach Datum in absteigender Reihenfolge und wählt das neueste Backup aus. Anschließend konstruiert es die vollständigen Pfade für die Quelle und das Ziel des neuesten Backups und verwendet 7-Zip, um den Ordner/die Datei zu archivieren und zu kopieren.

Falls nützlich, kann das Skript erweitert werden, um die Protokolldatei per E-Mail zu senden:

# Set SMTP server and port
$smtpServer = "smtp.stangneth.com"
$smtpPort = 587

# Set the sender address
$sender = "backup@stangneth.com"

# Set the email address for the recipient
$recipient = "logs@stangneth.com"

# Set the subject and body of the E-Mail
#subject = "Backup Log-File"
$body = "Attached the latest backup log!"

# Send the email with log as attachement
Send-MailMessage -SmtpServer $smtpServer -Port $smtpPort -Usessl -From $sender -To $recipient -Subject $subject -Body $body -Attachments $logFile

Keine Kommentare zu Synology Active Backup for Business – Letztes Backup auf USB Laufwerk

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert