User Guide for VM Backup and Snapshot Retention Script
Overview
This script automates the process of backing up virtual machines (VMs) and managing snapshot retention. It reads configurations from an external INI file, allowing for customizable settings without modifying the script directly. The script uses PowerShell cmdlets and RoboCopy for backup operations and manages snapshots for virtual machines.
Features
Automated VM snapshot creation.
Retention management for old snapshots.
Configurable backup paths and options.
Dynamic inclusion of VMs via the INI file.
Detailed logging of operations.
Fully customizable through an easy-to-use configuration file.
Prerequisites
System Requirements:
Required Permissions:
Dependencies:
Configuration File:
Configurable Options
All configurations are stored in the options.ini
file.
Example INI File
[Settings]
RetentionDays = 7
LocalPath = C:\VMBackups
RemotePath = \\BackupServer\VMs
LogPath = C:\VMLogs
RoboOpts = /MIR /e /FFT /Z /XA:H /W:5 /compress
[VMs]
VM1 = MyVirtualMachine1
VM2 = MyVirtualMachine2
VM3 = MyVirtualMachine3
Sections and Parameters
[Settings]
RetentionDays: Number of days to retain snapshots before deletion. Older snapshots will be automatically removed.
Default: 7
Example: RetentionDays = 14
LocalPath: Local directory where the VM files are stored.
Example: LocalPath = C:\VMBackups
RemotePath: Remote destination directory for backups. Use UNC paths for network locations.
-
LogPath: Directory where log files will be saved.
Example: LogPath = C:\VMLogs
RoboOpts: Customizable options for RoboCopy. These should be formatted as a single string of space-separated options.
Default: /MIR /e /FFT /Z /XA:H /W:5 /compress
Example: RoboOpts = /S /ZB /R:3
[VMs]
List of VMs to be backed up. Each entry should be in the format VMx = VMName
, where x
is a unique identifier and VMName
is the name of the virtual machine.
Example:
[VMs]
VM1 = MyVirtualMachine1
VM2 = MyVirtualMachine2
VM3 = MyVirtualMachine3
Script Functionality
Key Components
Snapshot Management
The script creates a snapshot for each VM listed in the INI file.
Old snapshots are removed based on the retention period defined in the RetentionDays
parameter.
Backup Process
The script uses RoboCopy to transfer VM files from the LocalPath
to the RemotePath
.
Configurable options for RoboCopy allow fine-tuning of backup behavior.
Logging
All operations are logged in a file created in the directory specified by LogPath
.
Log entries include timestamps and descriptions of actions performed.
How to Use
1. Open the ''options.ini'' file in a text editor.
2. Modify the parameters in the ''[Settings]'' and ''[VMs]'' sections as needed.
3. Save the file.
Step 2: Run the Script
1. Open a PowerShell window with administrative privileges.
2. Navigate to the directory containing the script.
3. Execute the script:
.\BackupScript.ps1
4. The script will automatically read the ''options.ini'' file, process VMs, and log the operations.
Step 3: Review Logs
Troubleshooting
Common Errors and Solutions
Error: "Invalid Parameter #3"
Cause: RoboCopy options are not split correctly.
Solution: Ensure RoboOpts
in the INI file is a valid string of space-separated options.
Error: "Access Denied"
Cause: Insufficient permissions to access VM files or remote path.
Solution: Run PowerShell as an administrator and verify permissions for the specified directories.
Error: "VM not found"
Cause: VM name in the INI file does not match an existing VM.
Solution: Verify the VM names in the [VMs]
section of the INI file.
Advanced Usage
Customizing RoboCopy Options
The RoboOpts
parameter allows you to customize the behavior of RoboCopy.
Example Options:
/MIR
: Mirrors the directory structure.
/Z
: Enables restartable mode for interrupted transfers.
/XA:H
: Excludes hidden files.
/R:N
: Specifies the number of retry attempts.
Adding or Removing VMs
To add a VM:
1. Add a new entry in the [VMs]
section of the INI file.
Example: VM4 = MyVirtualMachine4
2. Save the INI file.
To remove a VM:
1. Delete the corresponding entry in the [VMs]
section.
2. Save the INI file.
Maintenance and Updates
Log Management: Periodically clean up old logs in the LogPath
directory to save space.
INI File Updates: Review and update the INI file as necessary to reflect changes in the VM environment.
Script Updates: Check for script updates to ensure compatibility with the latest systems and features.
For questions or issues, please contact the script author or system administrator.