Because of a few vacation days, it has been a while since the last post.
Today I want to bring you a Powershell script, or at least the base, that allows for automatic and randomized restores using the Veeam Backup and Replication software.
Now the question would be, why would I want an automated randomized restore?
When you are part or own a service-provider who not only checks the backups of customers on a daily base, you will probably also want to do a restore of a few insignificant files/folders every X amount of weeks as this will prove to the customer that their data is safe and it will prove to you that there has been no corruption or other issues that might prevent a restore before it is too late.
So I made the base of a Powershell script that allows me to have something to build on while automating this.
This script allows for use on a device with Veeam Backup and Replication on it to automatically restore a randomized (you provide the options) file or folder on a randomized server with a randomized checkpoint/backup-date selected.
Below I will post the Powershell script and explain how this part works.
Requirements for the script to avoid issues:
- It only works with Veeam Backup and Replication
- Do not have disks imported in Veeam Backup and Replication that use backup files that do not exist anymore. This gives the script a chance to use a restore point from the imported disk which will end up failing because of missing backup files
- It needs the Veeam Powershell addon, which gets installed automatically with Veeam Backup and Replication
Variables you HAVE to create or fill in at the start of the script:
1. $Basefolder determines where the script will put its temporary files.
2. $VBRAccountname determines what Veeam account the script will use if it does not find a local account it can use for the VM
3. Exclusions.txt is a text file you will have to create and put next to the script. In this .txt you will have to specify what kind of job names will be excluded from the restores. This could be partial names. Example: Jobname1|Jobname2|Partialjobname1|Jobname3
4. RestoreLocations.txt is a text file you will have to create and put next to the script. In this .txt you will have to specify what kind of paths have a chance to be recovered. One of these paths to folders/files will be chosen randomly and be restored. Write down these locations with only 1 on each line.
What does the script do:
- Retrieves the names of all backup jobs, excludes given exclusions (Exclusions.txt) and puts them in a temporary .txt file
- Selects a random job
- Retrieves all servers and their restore points within that job
- Selects a random server + restore point
- Selects a random folder/file path (RestoreLocations.txt)
- Creates a restore job
- Searches whether within Veeam there is a credential containing a local account (Searches for accounts with the server name selected to restore). If this does not exist, it uses the domainname\accountname filled in at $VBRAccountname
- Puts in the account credentials and starts the restore job
- After the restore has ended, it will stop the restore job
- It will then write all information into its output and deletes the temporary .txt files
This is a great start to build up from.
Whether adding more specific information, changing the way the restoring works (Perhaps have it automatically import a backup disk) or changing any of the existing parts of the Powershell script .. this might be the first step to automating more of your daily tasks.
May it inspire someone into working less.
Categories: Powershell, Script, Veeam, Backup
Patrick Berger AKA Powershellder.
[ i ] Parallax section below. Click on the section below to upload image. Don't worry if it looks weird in the Weebly editor. It'll look normal on your published site.
To edit or delete your image, press the "toggle" button below. Then, hover over your image until a popup appears with the "edit" and "delete" options. If you don't want a white content section, leave it blank. It will disappear on your live website.