User Tools

Site Tools


backupmanagement

This is an old revision of the document!


VM Backup and Snapshot Retention Script

=== Purpose ===
This PowerShell script automates the process of:
* Backing up Hyper-V virtual machines (VMs).
* Retaining snapshots for a configurable period.
* Logging the entire process for audit and troubleshooting purposes.
* Sending email notifications upon success or failure.
* Providing a Windows-like progress box for user feedback.

=== Features ===
* INI-Based Configuration: All settings, including email and paths, are configured via an easy-to-edit `.ini` file.
* Snapshot Retention: Removes old snapshots based on the retention period defined in the `.ini` file.
* Automated Backup: Uses `RoboCopy` to back up VM files to a remote or local destination.
* Email Notifications: Notifies the user of the script's success or failure.
* Progress Box: Displays a Windows-like GUI progress bar during the backup process.


=== Prerequisites ===
- PowerShell Version: Ensure PowerShell 5.1 or later is installed.
- Hyper-V Module: The script uses `Checkpoint-VM`, `Get-VMSnapshot`, and `Remove-VMSnapshot`. The Hyper-V PowerShell module must be installed.
- INI File Configuration: The script relies on an `.ini` file for settings.
- Windows Forms Assembly: The script uses `System.Windows.Forms` for the progress box. This is included by default on Windows.


Configuration

== INI File ==
The script uses an `.ini` file located at:
* `C:\Program Files\SyncVM\options.ini`

Below is an example `.ini` file with all available settings:

```ini
[Settings]
RetentionDays = 7 ; Number of days to retain snapshots
LocalPath = C:\HyperV\VMs ; Local directory where VM files are stored
RemotePath = \\BackupServer\Backups ; Remote directory for storing backups
LogPath = C:\HyperV\Logs ; Path to save log files
RoboOpts = /MIR /E /FFT /Z /XA:H /W:5 /compress ; Options for RoboCopy

[VMs]
VM1 = TestVM1
VM2 = TestVM2
VM3 = TestVM3

[Email]
To = admin@example.com ; Email address to send notifications to
From = backup@example.com ; Email address to send notifications from
SMTPServer = smtp.example.com ; SMTP server for sending email
SMTPPort = 587 ; SMTP port (e.g., 587 for TLS, 25 for standard)
SMTPUsername = username@example.com ; Username for SMTP authentication
SMTPPassword = yourpassword ; Password for SMTP authentication
SubjectPrefix = [VM Backup] ; Prefix for email subject lines

/var/www/wiki.darrenwindle.co.uk/public_html/data/attic/backupmanagement.1735602262.txt.gz · Last modified: 2024/12/30 23:44 by Darren

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki