You are not logged in.
Hi folks. So I've come to really appreciate the snapshot feature of virtualbox, and in general just the idea of sandboxing an environment I can play in, and recover from any I do (goof) on the system. Well my only problem is remembering to take the actual snapshots. So here's a quick dirty tutorial on how to set up the VBoxManage feature to do this for me!
So first what is a snapshot? From the VirtualBox "Man Page"
"This command is used to control snapshots from the command line. A snapshot consists of a complete copy of the virtual machine settings, copied at the time when the snapshot was taken, and optionally a virtual machine saved state file if the snapshot was taken while the machine was running. After a snapshot has been taken, VirtualBox creates differencing hard disk for each normal hard disk associated with the machine so that when a snapshot is restored, the contents of the virtual machine's virtual hard disks can be quickly reset by simply dropping the pre-existing differencing files."
I'm assuming you've installed Virtualbox to your machine. And I'm assuming you're using Windows as the host machine. (Don't judge me! I *DO* have a machine with a dedicated Bunsen install!)
1. First you should add the C:\Program Files\Oracle\VirtualBox path to your Windows Machine. To do this:
A. Click on the Windows Button.
B. Click on Control Panel.
C. Click on System.
D. Click on Advanced System Settings. (maybe on the left menu)
E. This will bring up the System Properties menu. Click on the Advanced tab.
F. At the bottom, click the "Environment Variables" button
G. Look under the System Variables scroll box and scroll down to where it says Path.
H. Select it, and click Edit...
I. Under the Variable value add the addition of: C:\Program Files\Oracle\VirtualBox
J. Make sure you separate the last path with the ; character. Make sure not to delete the other path options already there.
2. Okay so that will let you now run commands from the VirtualBox directory without having to CD over to it, or specify the full path
just for convenience. So now we'll use Microsoft's Task Scheduler to set up a simple task to create the snapshot.
Click on Start, and either search for "Task Scheduler" or go to control panel> administrative tools > task scheduler.
3. The main menu has lots of options but don't be daunted, it's simple once you're familiar with it. On the left window, right click
on the "Task Scheduler Library", and select New Folder.
4. Name the folder something like VirtualBox. Once it's created, right click on that newly created directory and create one more new directory. Name this one something
specific to which VM you want to have the task run for. For example if you have 3 VM's, you can create three separate directories, under the main "VirtualBox" directory.
5. So let's walk through the task creation for one. Select one of the VM specific folders you made and on the right "Actions" pane, select
"Create Task"
6. When opened, You'll be on the "General" tab. Type a name for your task. Because I'm doing snapshots, I named mine SnapShot (so original).
Make sure the Author is your logged user. Type a description if you'd like. (may help, keeping the different VM's unique)
7. Just as a failsafe, I would check the "Run with highest privileges".
8. Make sure the "Configure For" dropdown has the OS you're running selected.
9. We're all done here, so click "Triggers" tab, and click new. On the top of the menu you'll see a drop down labled "Begin the task" This is all manner of triggers that we can
specify how you want your snapshot task to begin. I put mine on a schedule, but other options include "On Logon", "On Startup" or "On Event" etc... and even more exist.
You can really delve deep and specify very precisely how you want this snapshot to be triggered. A lot of it has to do with Event ID's that I don't really even want to be
bothered with. To keep things simple, I'd just go for "On a Schedule".
10. Choose how often you want it to run, and how often you want it to repeat, etc.
11. Once you have the schedule of it's running worked out, move to the Actions tab. The only actions that I have on mine were "Run a Program", "Send an Email" and "Display a Message"Welp.
Run a program sounds about right. It gives you a browse option as to what program you want to start. So, for our backups we need to select the VBoxManage.exe.
It's by default, located in C:\Program Files\Oracle\VirtualBox\VBoxManage.exe Select this.
12. Below, you need to specify a few specific options. The main command to take the snap shot is VBoxManage snapshot "<name_of_your_VM" take "<Back_Up_Name"
So in the box labeled "Add Arguments" We'd include the snapshot "<name_of_your_VM" take "<Back_Up_Name" portion of the command.
13. The box "Start in" I'm not sure what it's about..so let's just ignore it and leave it blank. Move onto Settings Tab...Almost done!
Nothing here really *needs* to be changed, but I just like the extra protection of having the option of forcing it to stop if it continues for a long time.
Anyway that should be all! Click Ok and try it out by trying to manually run it.
let me know if this works for you, or if you have a different way to do this, or other options that you pass to the VBoxManage Command.
I'm still looking for a way to auto run the delete option, so I can delete the prior oldest snapshots.
Last edited by Horizon_Brave (2016-04-13 18:57:55)
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline
^ Wow, what a nicely written post/how-to/tutorial!
A while ago, an openSuSE linux system that I used had a similar snapshot mechanism "snapper".
And it was very handy to rollback to a previous "working" snapshot.
Great work BTW!
Offline
Thanks, let me know if it works for you. Its how I got it working on my system. I just need to find a way to use the delete option so I can have it delete the oldest snapshot before taking another. I'll follow up with it later this week most likely.
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline
Well. you're an active member of this community forum, and I appreciate your industrious work-product.
I meant to praise your efforts. However, I don't use VirtualBox, and I won't break Bunsenlabs, the way
that openSuSE broke my system while using the "snapper" package. I have installed "snapper" but I am
using it extremely carefully. It is designed for btrfs filesystems, while my system uses ext4.
Read and review the documentation on "snapper". Maybe there are hints as to development designs that
will show the mechanism you could use without reverse engineering.
Or, just use the "snapper" package for your system hardware.
Last edited by jalexander9 (2016-04-12 14:18:21)
Offline
Update:
So, after really playing around with the snapshot features of Virtualbox, I found it can really...really screw up your versioning control. It seems you MUST delete the previous snapshots in reverse order. And like wise, never ever delete them manually from their folder. You must always use the vboxmanage.exe or go through the gui. And even then it seems like people are getting errors. The virtualbox support blog seems to be rife with these type of errors, that involve hung VM's, and undeletable snapshots. Even going back years and years.... To avoid this cluster****, I'll take the more heavy handed approach.
Virtualbox does indeed offer the snapshots for "easy" backups. But it seems the problem is that it's very easy for one linking snapshot to cause another linking snapshot to break. This is because to save space, the snapshot only includes the delta or the difference between right now and when you first created the .vdi hard disk. So in a way the snapshot is linked permanently to that master .vdi disk. Where it get's really hairy is when when boot your VM using the snapshot, and create another snapshot, you're now linked as a child to the parent snapshot, which is in turn linked to the core .vdi. Now think about if you want to restore your VM from the first (parent) snapshot, you'd have to restore to the parent, then create a snapshot there, and delete the child. It can get complicated and seems very easy for mistakes to happened.
My current Auto "SnapShot" is now basically to create a complete clone of the VM. So instead of dealing with those pesky disk differences between the parent .vdi, I just create a carbon copy of the drive as it is right now, and be done with it. I suppose the title should be "Auto Virtualbox Cloning" now.
For space reasons, I have it set so I delete the last previous _bk.vdi file that was created on the previous backup each time. He's the steps in the next post, so as not to create one long ass post
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline
Auto Cloning Your VirtualBox VM Using TaskScheduler
1. First you should add the C:\Program Files\Oracle\VirtualBox path to your Windows Machine. To do this:
A. Click on the Windows Button.
B. Click on Control Panel.
C. Click on System.
D. Click on Advanced System Settings. (maybe on the left menu)
E. This will bring up the System Properties menu. Click on the Advanced tab.
F. At the bottom, click the "Environment Variables" button
G. Look under the System Variables scroll box and scroll down to where it says Path.
H. Select it, and click Edit...
I. Under the Variable value add the addition of: C:\Program Files\Oracle\VirtualBox
J. Make sure you separate the last path with the ; character. Make sure not to delete the other path options already there.
2. Okay so that will let you now run commands from the VirtualBox directory without having to CD over to it, or specify the full path just for convenience. So now we'll use Microsoft's Task Scheduler to set up a simple task to create the snapshot.
Click on Start, and either search for "Task Scheduler" or go to control panel> administrative tools > task scheduler.
3. The main menu has lots of options but don't be daunted, it's simple once you're familiar with it. On the left window, right click
on the "Task Scheduler Library", and select New Folder.
4. Name the folder something like VirtualBox. Once it's created, right click on that newly created directory and create one more new directory. Name this one something specific to which VM you want to have the task run for. For example if you have 3 VM's, you can create three separate directories, under the main "VirtualBox" directory.
5. So let's walk through the task creation for one. Select one of the VM specific folders you made and on the right "Actions" pane, select "Create Task"
6. When opened, You'll be on the "General" tab. Type a name for your task. Because I'm doing snapshots, I named mine SnapShot (so original). Make sure the Author is your logged user. Type a description if you'd like. (may help, keeping the different VM's unique)
7. Just as a failsafe, I would check the "Run with highest privileges".
8. Make sure the "Configure For" dropdown has the OS you're running selected.
9. We're all done here, so click "Triggers" tab, and click new. On the top of the menu you'll see a drop down labeled "Begin the task" This is all manner of triggers that we can specify how you want your snapshot task to begin. I put mine on a schedule, but other options include "On Logon", "On Startup" or "On Event" etc... and even more exist.
You can really delve deep and specify very precisely how you want this cloning to be triggered. A lot of it has to do with Event ID's that I don't really even want to be bothered with. To keep things simple, I'd just go for "On a Schedule".
10. Choose how often you want it to run, and how often you want it to repeat, etc.
11. Once you have the schedule of it's running worked out, move to the Actions tab. The only actions that I have on mine were "Run a Program", "Send an Email" and "Display a Message" ....Welp. Run a program sounds about right. It gives you a browse option as to what program you want to start.
So now, unless you have seriously a crap ton of storage space, you should want to clean up your previous cloned disks. Because I just want to keep one backup copy, I have it so each time this task is run, it deletes the previous backed up disk. You can of course specify how many versions back you want to keep. (two to three sounds right) Just remember these are not the small 2 MB snapshots, these are full disk clones that may take gigs of space.
To have the deletion occur, use
forfiles
in the text field of "Program/Script"
The text field labeled "Add Arguments" needs to have something like:
-p "C:\Users\<YOUR_USER_NAME>\Documents\VirtualBox\BunsenLabs3\" -m BunsenLabs3_bk.vdi /c "cmd /c del @file"
Okay so first in quotes, after the -p , you need to specify the path to the image that you want deleted. then the -m is where you specify which image you want erased. Note that you CAN use the wildcards * and ? .
The * specifies anything, so the -m *.vdi /C will delete all .vdi files.
The ? specifies a specific varying character. So you can have -m BunsenLabs_Jan??.vdi to remove all of your January backups.
Also make note that for the TaskScheduler application you need to have the double quotes around the full path of your image directory. But if you want to run this from the Windows cmd line, don't use the quotes. But for our purposes for scheduler, keep 'em in.
12. So, now we have our clean up step, now let's create the new clone. Click "New" to create a 2nd action. Keep the "Start a Program" option selected. This time for our backups we need to select the VBoxManage.exe for the Program/Script option.
It's, by default, located in C:\Program Files\Oracle\VirtualBox\VBoxManage.exe So paste that into the text box.
Below, you need to specify a few specific options.
The main command to take the clone is
clonemedium "C:\Users\<YOUR_USER_NAME>\Documents\VirtualBox\BunsenLabs3\BunsenLabs3.vdi" "C:\Users\<YOUR_USER_NAME>\Documents\VirtualBox\BunsenLabs3\BunsenLabs3_bk.vdi"
Note that the 2nd path is where you want to stash the clone. Use whatever folder/location you want. I just store mine in the same directory as the original. Also feel free to name it whatever you wish, but for the earlier described deletion portion, you should probably stick with an easily searchable and matchable name.
13. The box "Start in" I'm not sure what it's about..so let's just ignore it and leave it blank. Move onto Settings Tab...Almost done!
Nothing here really *needs* to be changed, but I just like the extra protection of having the option of forcing it to stop if it continues for a long time.
Anyway that should be all! Click Ok and try it out by trying to manually run it.
Last edited by Horizon_Brave (2016-04-13 18:50:56)
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline