backupmanagement
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
backupmanagement [2024/12/30 23:44] – Darren | backupmanagement [2024/12/30 23:47] (current) – old revision restored (2024/12/25 10:57) Darren | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== VM Backup and Snapshot Retention Script ====== | + | ====== |
- | === Purpose | + | === Overview |
- | This PowerShell | + | This script automates the process of backing |
- | * Backing | + | |
- | * Retaining snapshots | + | |
- | * Logging the entire process | + | |
- | * Sending email notifications upon success or failure.\\ | + | |
- | * Providing a Windows-like progress box for user feedback. | + | |
- | === Features ===\\ | + | ==== Features ==== |
- | * **INI-Based Configuration**: | + | * Automated VM snapshot creation. |
- | * **Snapshot | + | * Retention |
- | * **Automated Backup**: Uses `RoboCopy` to back up VM files to a remote or local destination.\\ | + | * Configurable backup paths and options. |
- | * **Email Notifications**: | + | * Dynamic inclusion |
- | * **Progress Box**: Displays a Windows-like GUI progress bar during the backup process. | + | * Detailed logging of operations. |
+ | | ||
---- | ---- | ||
- | === Prerequisites ===\\ | + | === Prerequisites === |
- | - **PowerShell Version**: Ensure PowerShell 5.1 or later is installed.\\ | + | - **System Requirements: |
- | - **Hyper-V | + | * Windows Server or Windows 10/11 with Hyper-V installed. |
- | - **INI File Configuration**: | + | * PowerShell 5.0 or later. |
- | - **Windows Forms Assembly**: The script uses `System.Windows.Forms` for the progress box. This is included by default on Windows. | + | |
- | ---- | + | |
+ | * Administrative privileges to manage VMs and access file paths. | ||
- | === Configuration === | + | - **Dependencies: |
+ | * '' | ||
- | == INI File ==\\ | + | - **Configuration |
- | 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\\ | + | === Configurable Options === |
- | [Settings]\\ | + | All configurations are stored in the '' |
- | RetentionDays | + | |
- | LocalPath | + | |
- | RemotePath | + | |
- | LogPath | + | |
- | RoboOpts = /MIR /E /FFT /Z /XA:H /W:5 /compress ; Options for RoboCopy | + | |
- | [VMs]\\ | + | ==== Example INI File ==== |
- | VM1 = TestVM1\\ | + | <code ini> |
- | VM2 = TestVM2\\ | + | [Settings] |
- | VM3 = TestVM3 | + | RetentionDays = 7 |
+ | LocalPath = C:\VMBackups | ||
+ | RemotePath | ||
+ | LogPath | ||
+ | RoboOpts | ||
- | [Email]\\ | + | [VMs] |
- | To = admin@example.com ; Email address to send notifications to\\ | + | VM1 = MyVirtualMachine1 |
- | From = backup@example.com ; Email address to send notifications from\\ | + | VM2 = MyVirtualMachine2 |
- | SMTPServer | + | VM3 = MyVirtualMachine3 |
- | 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 | + | |
- | == Explanation of INI File Sections == | + | ==== Sections |
+ | - **[Settings]** | ||
+ | - **RetentionDays**: | ||
+ | - **Default: | ||
+ | - **Example: | ||
- | [Settings]: | + | - **LocalPath**: Local directory where the VM files are stored. |
+ | - **Example: | ||
- | RetentionDays: | + | - **RemotePath**: Remote destination directory |
- | LocalPath: Directory containing VM files.\\ | + | - **Example:** '' |
- | RemotePath: | + | |
- | LogPath: Location of the log files.\\ | + | |
- | RoboOpts: Options for RoboCopy. Adjust according to your needs.\\ | + | |
- | [VMs]: | + | |
- | List of VM names to back up.\\ | + | - **LogPath**: |
- | [Email]: | + | - **Example:** '' |
- | SMTP settings | + | - **RoboOpts**: |
- | Authentication is optional; if omitted, the script attempts to send emails without it.\\ | + | - **Default: |
- | === Script Usage === | + | - **Example: |
- | == Steps to Run the Script | + | - **[VMs]** |
+ | - List of VMs to be backed up. Each entry should be in the format '' | ||
+ | - **Example: | ||
+ | <code ini> | ||
+ | [VMs] | ||
+ | VM1 = MyVirtualMachine1 | ||
+ | VM2 = MyVirtualMachine2 | ||
+ | VM3 = MyVirtualMachine3 | ||
+ | </ | ||
- | Download and Save the Script: Save the PowerShell script as Sync_VMs.ps1 in C:\Program Files\SyncVM. | + | ---- |
- | Edit the INI File: Open C:\Program Files\SyncVM\options.ini in a text editor and configure the settings as per your environment. | + | === Script Functionality === |
- | Run the Script: Open PowerShell as an Administrator and run the script: | + | ==== 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 '' | ||
- | powershell\\ | + | |
- | Copy code\\ | + | - The script uses RoboCopy to transfer |
- | powershell | + | - Configurable options for RoboCopy allow fine-tuning of backup behavior. |
- | Monitor the Progress: A progress box will appear, showing the VM currently being backed up and the overall progress. | + | |
- | Check Logs: Logs are saved in the directory specified by the LogPath | + | - **Logging** |
+ | - All operations | ||
+ | - Log entries include timestamps and descriptions of actions performed. | ||
- | bash\\ | + | ---- |
- | Copy code\\ | + | |
- | C: | + | |
- | Review Notifications: | + | |
- | === How It Works === | + | === How to Use === |
- | INI File Parsing: | + | ==== Step 1: Configure the INI File ==== |
+ | 1. Open the '' | ||
+ | 2. Modify the parameters in the '' | ||
+ | 3. Save the file. | ||
- | Reads all configurable settings (paths, retention, VMs, email) from the .ini file.\\ | + | ==== Step 2: Run the Script ==== |
- | Validates required fields and provides defaults for optional fields.\\ | + | 1. Open a PowerShell window with administrative privileges. |
- | Snapshot Retention: | + | 2. Navigate to the directory containing the script. |
+ | 3. Execute the script: | ||
+ | <code powershell> | ||
+ | .\BackupScript.ps1 | ||
+ | </ | ||
+ | 4. The script will automatically read the '' | ||
- | Identifies snapshots older than the retention period and deletes them.\\ | + | ==== Step 3: Review Logs ==== |
- | Backup Process: | + | * Check the log files in the directory specified by '' |
- | Creates a checkpoint (snapshot) for each VM.\\ | + | ---- |
- | Uses RoboCopy to back up files from the local path to the remote path.\\ | + | |
- | Removes the checkpoint after backup completion.\\ | + | |
- | Progress Box: | + | |
- | Displays a GUI progress bar that updates with each VM.\\ | ||
- | Error Handling: | ||
- | |||
- | Logs errors and sends detailed error reports via email.\\ | ||
=== Troubleshooting === | === Troubleshooting === | ||
- | == Common | + | ==== Common |
+ | - **Error:** " | ||
+ | - **Cause:** RoboCopy options are not split correctly. | ||
+ | - **Solution: | ||
- | INI File Not Found: Ensure the .ini file exists at the specified | + | - **Error:** " |
+ | - **Cause:** Insufficient permissions to access VM files or remote path. | ||
+ | - **Solution: | ||
- | Hyper-V Cmdlets Not Found: Make sure the Hyper-V PowerShell module is installed. | + | |
+ | - **Cause:** VM name in the INI file does not match an existing VM. | ||
+ | | ||
- | Progress Box Does Not Appear: Verify that System.Windows.Forms is available in your PowerShell environment. | + | ---- |
- | Email Fails to Send: | + | === Advanced Usage === |
- | Check SMTP server, port, username, and password in the [Email] section | + | ==== Customizing RoboCopy Options ==== |
- | Ensure | + | - The '' |
- | == Debugging Tips == Run the script in verbose | + | - Example Options: |
+ | - ''/ | ||
+ | - ''/ | ||
+ | - ''/ | ||
+ | - ''/ | ||
- | powershell\\ | + | ==== Adding or Removing VMs ==== |
- | Copy code\\ | + | - **To add a VM:** |
- | powershell | + | 1. Add a new entry in the '' |
- | Review | + | - Example: '' |
+ | 2. Save the INI file. | ||
- | === Example Output === | + | - **To remove a VM:** |
+ | 1. Delete the corresponding entry in the '' | ||
+ | 2. Save the INI file. | ||
- | == Progress Box == The progress box will display the following: | + | ---- |
- | diff\\ | + | === Maintenance and Updates |
- | Copy code\\ | + | - **Log Management: |
- | VM Backup Progress\\ | + | - **INI File Updates:** Review and update the INI file as necessary to reflect changes in the VM environment. |
- | Processing VM: TestVM1\\ | + | - **Script Updates:** Check for script updates to ensure compatibility with the latest systems and features. |
- | [========== ] 33%\\ | + | |
- | == Email Notification == Example success email: | + | |
- | arduino\\ | + | ---- |
- | Copy code\\ | + | |
- | Subject: [VM Backup] Backup Successful | + | |
- | + | ||
- | The VM backup process completed successfully. Logs are attached.\\ | + | |
- | Example failure email: | + | |
- | + | ||
- | yaml\\ | + | |
- | Copy code\\ | + | |
- | Subject: [VM Backup] Backup Failed | + | |
- | + | ||
- | The VM backup process encountered errors:\\ | + | |
- | - Error processing VM: TestVM1 | + | |
- | - Error processing VM: TestVM2 | + | |
- | === Advanced Configuration === | + | |
- | + | ||
- | == Adjust RoboCopy Options == Modify the RoboOpts setting in the .ini file to customize the backup behavior. For example: | + | |
- | + | ||
- | /MIR: Mirrors the source directory to the destination (deletes files not in the source).\\ | + | |
- | /Z: Enables restartable mode.\\ | + | |
- | /compress: Compresses data during transfer.\\ | + | |
- | == Adding New VMs == Add new VMs under the [VMs] section in the .ini file: | + | |
- | + | ||
- | ini\\ | + | |
- | Copy code\\ | + | |
- | [VMs]\\ | + | |
- | VM4 = NewVM\\ | + | |
- | VM5 = AnotherVM\\ | + | |
- | === Maintenance === | + | |
- | + | ||
- | Update INI File: Keep the .ini file updated with correct paths and VM names.\\ | + | |
- | Log Review: Regularly review log files to ensure backups are successful.\\ | + | |
- | Script Updates: Periodically review and update the script for compatibility with new PowerShell or Hyper-V versions.\\ | + | |
- | yaml\\ | + | |
- | Copy code | + | |
- | + | ||
- | --- | + | |
- | + | ||
- | ### Notes\\ | + | |
- | - This DokuWiki content follows DokuWiki formatting conventions such as `======` for headings, `*` for bullet points, and `----` for horizontal lines.\\ | + | |
- | - Copy and paste the content directly into a DokuWiki page editor. | + | |
- | Let me know if you need further assistance! | + | === Contact and Support === |
+ | For questions or issues, please contact the script author or system administrator. | ||
/var/www/wiki.darrenwindle.co.uk/public_html/data/attic/backupmanagement.1735602298.txt.gz · Last modified: 2024/12/30 23:44 by Darren