Let’s Deep Dive Into Proxmox CV4PVE-AutoSnap Snapshots
Recently, we looked at 2 new ways to take snapshots of virtual machines and containers on PVE including a brief look at Proxmox CV4PVE-AutoSnap. We looked at a basic script that could take snapshots but not remove them. And we also took a look at cv4pve-autosnap. Cv4pve-autosnap on Proxmox is a tried and tested tool that, with a little bit of configuration, can take snapshots of individual servers or entire nodes. In recent versions, you can utilize the PVE API which makes using cv4pve-autosnap much more secure. In older versions, you would typically store passwords in a text file.
Install Proxmox CV4PVE-AutoSnap
Installing CV4PVE-AutoSnap is fast and best done on a separate virtual server or container. In this guide, we will install a fresh copy of CV4PVE-AutoSnap and take a closer look at the different features that can be used. Assuming you are on a server you can install CV4PVE-AutoSnap on. Issue the commands below.
apt update && apt install unzip wget -y
cd /tmp
wget https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.15.0/cv4pve-autosnap-linux-x64.zip
unzip /tmp/cv4pve-autosnap-linux-x64.zip -d /usr/local/bin
Proxmox API Snapshots
The most secure way to use CV4PVE-AutoSnap is by using the PVE API to issue commands to take snapshots. This way you don’t expose any passwords. Create an API user as below on each host you want to take snapshots on.
1)
Datacentre >> Roles >> Create >> add a new Role
Role Name: SnapshotUsr
Privilages: VM.Audit, VM.Snapshot, Datastore.Audit, Pool.Allocate.
2)
Next in Datacenter >> Permissions >> Users add a new API token for root@pam. Save the token details. You will need them shortly.
Token Name: Snapshots
3)
Datacenter >> Permissions >> Add >> API token permissions and assign the Role you created to "root@APIUSER" with "/" as the path.
Assigning the role to the API token will look similar to the below image. We now have an API user to use with CV4PVE-AutoSnap. But ensure you have copied the token and username for the next section.
We already know from our article, 2 New Ways To Automate Proxmox Snapshots that at this point we can combine our API user and API token together with our node details and, if needed, our VMID to take an automated Snapshot. We can then place that command into a cronjob and run that on a schedule. But what else can we do with CV4PVE?
CV4PVE Commands
There are several flags that can be used when issuing commands with CV4PVE. To build your custom command first start off with the base command. /usr/local/bin/cv4pve-autosnap.
/usr/local/bin/cv4pve-autosnap
The next part of the command is different for API users and users using a password. We are using the API so we would next append our host and API details.
- –host=10.210.250.1
- –api-token ‘root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229’
So now our command will look like this.
/usr/local/bin/cv4pve-autosnap --host=10.210.250.1 --api-token 'root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229'
And finally, we append our snapshot requirements. In a basic form, we want to specify a VMID, a label for the snapshot and how many snapshots CV4PVE will keep for the server.
- –vmid=70002 snap
- –label=TestSnap
- –keep=2
After this, our basic command to take a snapshot looks like this.
/usr/local/bin/cv4pve-autosnap --host=10.210.250.1 --api-token 'root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229' --vmid=70002 snap --label=TestSnap --keep=2
So, let’s give that command a go on our test node. We can see that running that command gives us another snapshot of our CT in Proxmox and it’s also removed the previous snapshot, as we are using the –keep=2 flag to keep the last two snapshots.
Take Snapshots of all Proxmox Virtual Machines and CTs on the node
We can modify the command slightly to take a snapshot of all servers on the node. So to do this we just change the –vmid=111 flag for –vmid=all
/usr/local/bin/cv4pve-autosnap --host=10.210.250.1 --api-token 'root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229' --vmid=all snap --label=TestSnap --keep=2
In the output for the command, we can see that CV4PVE has taken a snapshot of all servers on our test node.
----- VM 70003 lxc running -----
Create snapshot: autoTestSnap250127210123
VM execution 00:00:00.5303591
----- VM 70004 lxc running -----
Create snapshot: autoTestSnap250127210123
VM execution 00:00:00.5313848
Total execution 00:00:02.7746188
Include Active RAM In Snapshots
The commands so far do not include the active processes in the memory or the RAM. To include RAM in the Snapshot you append the –state flag. To ensure consistency, ensure the Qemu guest agent is installed and working.
/usr/local/bin/cv4pve-autosnap --host=10.210.250.1 --api-token 'root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229' --vmid=70002 snap --label=TestSnap --state --keep=2
Exclude a VM or CT from Snapshots
If we use the command to take a snapshot of all virtual machines on the server, we can also exclude virtual machines using the – flag and the VMID. That would look like this. –vmid=”all,-70004″. Which would exclude virtual machine 70004 from snapshots.
/usr/local/bin/cv4pve-autosnap --host=10.210.250.1 --api-token 'root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229' --vmid="all,-70004" snap --label=TestSnap --keep=2
List Snapshots Per Server
The VMID flag followed by the state command will return a list of snapshots for that VPS Server.
cv4pve-autosnap --host=10.210.250.1 --api-token 'root@pam!Snapshots=c981401e-8574-49b5-8400-990fb3acd229' --vmid=70002 status
So, did you find any useful CV4PVE-AutoSnap commands we have missed? Let us know in the comments!