HyperCloud PoSH – Custom Backup Script

H

HyperCloud PoSH

Have you ever wanted backup your Hyper-V virtual machines directly to a cloud provider with minimal effort? HyperCloud PoSH does just that. By “installing” this script with the addition of rClone, you can set up task scheduler to automatically export each one of your virtual machines to your cloud provider on any time schedule you may desire. In my use case HyperCloud PoSH exports all of my virtual machines to a folder nightly and have rClone move them to my Google Drive account where they are archived. Please note that certain cloud providers have a file size limit, for example Amazon Cloud being a maximum of 25GB per file. I suggest using GSuite where Google Drive has a maximum file size of 5TB per file. This is very useful for exporting large virtual machines. HyperCloud PoSH works with all cloud providers that rClone supports.

rClone moves data from C:\Exports\(date) folder to the “HyperAuto” folder in the root directory of gdrive.

All logging goes into the C:\Scripts\Logs\ folder.

If you are a season Windows Server Pro, all you have to do is put HyperCloud PoSH into your C:\Scripts folder and add the script location to the Windows Task Scheduler.

If you are not a seasoned user of Windows, no problem. I’ll show you the basics of getting this setup and working.

This script also assumes that you have rClone already installed onto your server with a cloud destination setup and rClone added to PATH.

Step 1: Adding rClone to global PATH variable

In order for HyperCloud PoSH to function properly, we need to setup rClone to be in the system environment variables. This is needed to execute “rclone” in any folder on PoSH.

To do this, open Explorer and right click on “This PC” selecting “Properties”.

Once you have done this the system properties box will open. Click “Environment Variables…” then under “System variables” edit the “Path” variable and add the location of your rClone folder to the end. For my server rClone.exe is located in the C:\Users\root\rclone directory.

Step 2: Creating folders and adding HyperCloud PoSH

We need a place to put this script. Lets create the directory C:\Scripts where we will copy and paste the above script into a PowerShell format. Lets call it rClone.ps1. Also, while we are in the folder, we also need to create the sub-folder Logs. This is where our logs of the script will go.

Step 3: Setting up Task Scheduler

Fist open Task Scheduler. You can find it by opening run and typing “taskschd.msc” Once you are in the main screen, click on “Task Scheduler Library” under “Task Scheduler (Local)”. Create a new task with the following properties, while modifying the configuration to match your system users.

Depending on how you want the backups done you can change the frequency and time that the script runs. I prefer to run it after midnight at 1:00 AM every day.

On the next tab “Actions” we now need to point task scheduler to run PowerShell and execute our script.

It is also good practice to set it up so that if the script runs longer than a day to stop the task. Lets do that in the “Settings” tab.

Testing

Before setting and forgetting this script, lets verify that everything is in working order, it is easiest to do this through PowerShell and manually running the script to see if there are any errors in real time, but if you would like you can just run the script through task scheduler by right clicking on the new task and clicking “Run”

Conclusion

I hope this script worked for you as it has made my life so much easier, utilizing the light weight rclone program along with hyper-v’s native exporting function.

Please don’t hesitate to leave a comment for any assistance you may need.

Check out this other handy tutorial for fixing an import error for Hyper-V!