Sunday, 24 August 2025
  5 Replies
  59 Visits
0
Votes
Undo
Hello,
I use proxmox in order to manage some VMs in my dedicated server. I also use the snapshot function in order to avoid the disaster and chaos.

Eg the simple snapshot proccess like https://www.oreilly.com/api/v2/epubs...6b91d5f2ed.png

Does anyone know how to create/configure the automatic snapshots xreation function and the auto delete (eg after 10 days)?
You can use the following script to automatically take daily snapshots of your running VMs on Proxmox and remove older snapshots to save disk space. Set it up as a daily cron job on each node you wish to back up. The script will create a new snapshot each day, and then remove any snapshots older than the number of days you specify.


#!/bin/bash
keep_last="1";
local_server="$proxmox_local_server"
keep=$(( $keep_last + 1 ))
get_vm_list (){
pvesh get /nodes/$local_server/qemu --noborder|grep -w "running"|grep -v "vmid"|awk '{ print $2 }'|sort -n
}

get_snapshots_list(){
pvesh get /nodes/$local_server/qemu/$virtual_machine/snapshot --noborder |grep -vw description|grep -vw "You are here!"|awk '{ print $1 }'|awk '{ print $1 }'|sort -nr|tail -n +$keep
}

take_snapshot(){
pvesh create /nodes/$local_server/qemu/$virtual_machine/snapshot --snapname snap-`date "+%F-%H-%M"`

}

delete_snapshot (){
for snap in `get_snapshots_list`
do
pvesh delete /nodes/$local_server/qemu/$virtual_machine/snapshot/$snap
done;
}

###
for virtual_machine in `get_vm_list`;
do
take_snapshot
delete_snapshot
done;


Change $proxmox_local_server to the hostname of the server as is in proxmox and keep_last="1" to the days you want to keep

Remember that snapshots can take up substantial disk space depending on your daily data changes. I prefer to keep a single daily snapshot and rely on remote backups using Proxmox Backup Server for long-term storage and disaster recovery. This approach helps minimize local disk usage while still providing reliable backups.
5 days ago
·
#110
0
Votes
Undo
You can use the following script to automatically take daily snapshots of your running VMs on Proxmox and remove older snapshots to save disk space. Set it up as a daily cron job on each node you wish to back up. The script will create a new snapshot each day, and then remove any snapshots older than the number of days you specify.


#!/bin/bash
keep_last="1";
local_server="$proxmox_local_server"
keep=$(( $keep_last + 1 ))
get_vm_list (){
pvesh get /nodes/$local_server/qemu --noborder|grep -w "running"|grep -v "vmid"|awk '{ print $2 }'|sort -n
}

get_snapshots_list(){
pvesh get /nodes/$local_server/qemu/$virtual_machine/snapshot --noborder |grep -vw description|grep -vw "You are here!"|awk '{ print $1 }'|awk '{ print $1 }'|sort -nr|tail -n +$keep
}

take_snapshot(){
pvesh create /nodes/$local_server/qemu/$virtual_machine/snapshot --snapname snap-`date "+%F-%H-%M"`

}

delete_snapshot (){
for snap in `get_snapshots_list`
do
pvesh delete /nodes/$local_server/qemu/$virtual_machine/snapshot/$snap
done;
}

###
for virtual_machine in `get_vm_list`;
do
take_snapshot
delete_snapshot
done;


Change $proxmox_local_server to the hostname of the server as is in proxmox and keep_last="1" to the days you want to keep

Remember that snapshots can take up substantial disk space depending on your daily data changes. I prefer to keep a single daily snapshot and rely on remote backups using Proxmox Backup Server for long-term storage and disaster recovery. This approach helps minimize local disk usage while still providing reliable backups.


Thanks for helping with this. Good to see people helping people . .
5 days ago
·
#111
0
Votes
Undo
That was great!!! How do you manage the available disk space for snapshots? I configured proxmox to 14 snapshots and then I faced disk space issues.
5 days ago
·
#112
0
Votes
Undo
That was great!!! How do you manage the available disk space for snapshots? I configured proxmox to 14 snapshots and then I faced disk space issues.


If you are getting the disk space shortage after keeping 14 snapshots, it is better to reduce the snapshot retention to 1 -3, or you will need to use Proxmox backup server for long retention.
That was great!!! How do you manage the available disk space for snapshots? I configured proxmox to 14 snapshots and then I faced disk space issues.


Hi,

We only keep one daily snapshot, and we also use Proxmox Backup (highly recommended). For disk space monitoring, we have Zabbix monitoring Proxmox nodes, including LVM stuff, and we do not oversell

Short-lived snapshots are usually pretty small because they only have the data that has changed since the moment the snapshot was taken, so hourly or daily snapshots are very disk space efficient. We reserve 10% of the node disk space for snapshots, and usually it is more than enough. Just be careful to delete the old snapshots in a regular and automatic way; a forgotten snapshot can consume the entire disk space and crash an LVM thin volume.
  • Page :
  • 1
There are no replies made for this post yet.
Submit Your Response
© 2025 hostsocial.io