Toolbox

I just used the cv4pve-autosnap and that worked great: https://github.com/Corsinvest/cv4pve-autosnap
Better than the usual ZFS snapshot scripts, as it makes use of the PVE API, so data integrity is kept, as it will fsfreze and flush caches before snapshotting (at least when enabling the qemu guest agent for all guests).
 
Last edited:
Just installed cv4pve-autosnap again to one of my servers. In case you need en example:

1.) Install cv4pve-autosnap:
Code:
apt update && apt install unzip wget
cd /tmp
wget https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.14.6/cv4pve-autosnap-linux-x64.zip
unzip /tmp/cv4pve-autosnap-linux-x64.zip -d /usr/local/bin
rm cv4pve-autosnap-linux-x64.zip
chown root:root /usr/local/bin/cv4pve-autosnap
chmod 750 /usr/local/bin/cv4pve-autosnap
You might want to download another zip file matching your architecture or OS. Also make sure to download the latest release. You can find them here: https://github.com/Corsinvest/cv4pve-autosnap/releases

2.) Test if it works: cv4pve-autosnap --version

3.) Setting up a token
cv4pve-autosnap uses the PVE API to create and purge snapshots, so you need define the IP and a user + password or alternatively a token.
I prefer a token for that. First you have to go to "Datacenter -> Permissions -> Roles" in the webUI and create a new Role. I called my role "Autosnap". Give that role these privileges: VM.Audit, VM.Snapshot, Datastore.Audit, Pool.Allocate.
Then add a new token for user root@pam at "Datacenter -> Permissions -> Users". I called my token "autosnap" so the full token is "root@pve!autosnap". Save that token secret for later, its your password for authentification.
Then go to "Datacenter -> Permissions -> Add -> API token permission" and assign the Role "Autosnap" to "root@pve!autosnap" with "/" as path.

4.) Test if everything is working by creating a snapshot and purging it
cv4pve-autosnap --max-perc-storage 80 --host=127.0.0.1 --api-token 'root@pam!autosnap=YourSecret' --vmid=all --timeout=1800 snap --label='test' --keep=1
cv4pve-autosnap --host=127.0.0.1 --api-token 'root@pam!autosnap=YourSecret' --vmid=all clean --label='test' --keep=0

5.) Create a cronjob to create hourly snapshots:
Run crontab -e and add the following there:
Code:
# hourly autosnap of all guests (keep for 1 day):
0 * * * * /usr/local/bin/cv4pve-autosnap --max-perc-storage 80 --host=127.0.0.1 --api-token 'root@pam!autosnap=YourSecret' --vmid=all --timeout=1800 snap --label='hourly' --keep=24 > /var/log/cv4pve-autosnap.log 2>&1
# try a daily update of cv4pve-autosnap
0 0 * * * /usr/local/bin/cv4pve-autosnap app-upgrade > /var/log/cv4pve-autosnap.log 2>&1
There are a lot of options to choose from. Some, like snapshots with RAM dumps, aren't even listed in the documentation: https://github.com/Corsinvest/cv4pve-autosnap
The "--max-perc-storage 80" for example means it will only snapshot if the storage isn't filled up more than 80%, with is useful for ZFS, as a ZFS pool should always have 20% of free space.
 
Just installed cv4pve-autosnap again to one of my servers. In case you need en example:

1.) Install cv4pve-autosnap:
Code:
apt update && apt install unzip wget
cd /tmp
wget https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.14.6/cv4pve-autosnap-linux-x64.zip
unzip /tmp/cv4pve-autosnap-linux-x64.zip -d /usr/local/bin
rm cv4pve-autosnap-linux-x64.zip
chown root:root /usr/local/bin/cv4pve-autosnap
chmod 750 /usr/local/bin/cv4pve-autosnap
You might want to download another zip file matching your architecture or OS. Also make sure to download the latest release. You can find them here: https://github.com/Corsinvest/cv4pve-autosnap/releases

2.) Test if it works: cv4pve-autosnap --version

3.) Setting up a token
cv4pve-autosnap uses the PVE API to create and purge snapshots, so you need define the IP and a user + password or alternatively a token.
I prefer a token for that. First you have to go to "Datacenter -> Permissions -> Roles" in the webUI and create a new Role. I called my role "Autosnap". Give that role these privileges: VM.Audit, VM.Snapshot, Datastore.Audit, Pool.Allocate.
Then add a new token for user root@pam at "Datacenter -> Permissions -> Users". I called my token "autosnap" so the full token is "root@pve!autosnap". Save that token secret for later, its your password for authentification.
Then go to "Datacenter -> Permissions -> Add -> API token permission" and assign the Role "Autosnap" to "root@pve!autosnap" with "/" as path.

4.) Test if everything is working by creating a snapshot and purging it
cv4pve-autosnap --max-perc-storage 80 --host=127.0.0.1 --api-token 'root@pam!autosnap=YourSecret' --vmid=all --timeout=1800 snap --label='test' --keep=1
cv4pve-autosnap --host=127.0.0.1 --api-token 'root@pam!autosnap=YourSecret' --vmid=all clean --label='test' --keep=0

5.) Create a cronjob to create hourly snapshots:
Run crontab -e and add the following there:
Code:
# hourly autosnap of all guests (keep for 1 day):
0 * * * * /usr/local/bin/cv4pve-autosnap --max-perc-storage 80 --host=127.0.0.1 --api-token 'root@pam!autosnap=YourSecret' --vmid=all --timeout=1800 snap --label='hourly' --keep=24 > /var/log/cv4pve-autosnap.log 2>&1
# try a daily update of cv4pve-autosnap
0 0 * * * /usr/local/bin/cv4pve-autosnap app-upgrade > /var/log/cv4pve-autosnap.log 2>&1
There are a lot of options to choose from. Some, like snapshots with RAM dumps, aren't even listed in the documentation: https://github.com/Corsinvest/cv4pve-autosnap
The "--max-perc-storage 80" for example means it will only snapshot if the storage isn't filled up more than 80%, with is useful for ZFS, as a ZFS pool should always have 20% of free space.
does it work with ceph as well. couldnt fine more information about ?
 
Its using the API to create snapshots, so all storages should work that support snapshots. So should work with ZFS, ceph, LVM-Thin, qcow2 and so on.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!