You are welcome. Glad to hear that it is working again and useful to you.I am looking at PBS, but i haven't read enough of the docs yet to work out if I can use my NFS NAS as the backup storage back-end.
#!/bin/bash
# backup-start | backup-end | backup-abort | log-end | pre-stop | pre-restart | post-restart | job-start | job-end | job-abort
# If varable DUMPDIR is empty it might be a PBS backup
[ -z "${DUMPDIR}" ] && exit 0
cd "${DUMPDIR}"
MAXFILES=$(grep "prune-backups:" /etc/vzdump.conf | awk -F"=" '{print $2}')
case "${1}" in
backup-end)
PVENODENAME=$(hostname)
VM_FNAM_OLD=$(basename ${TARGET})
VM_FNAM_NEW=$(basename ${TARGET} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'-"$4"-"$5}')
VM_FNAM_DUP=$(basename ${TARGET} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'"}')
VM_TYPE=$(basename ${TARGET} | awk -F "-" '{print $2}')
mv "${VM_FNAM_OLD}" "${VM_FNAM_NEW}"
case "${VM_TYPE}" in
lxc)
NUMFILES=$(ls -1 ${VM_FNAM_DUP}*.tar* | wc -l)
if [[ $MAXFILES =~ ^-?[0-9]+$ ]] && [ ${NUMFILES} -gt ${MAXFILES} ]; then
echo "-- maxfiles set to ${MAXFILES} but ${NUMFILES} present. Deleting the older ones."
ls ${VM_FNAM_DUP}*.tar* | head -n $((${NUMFILES}-${MAXFILES})) | xargs rm
fi
;;
qemu)
NUMFILES=$(ls -1 ${VM_FNAM_DUP}*.vma* | wc -l)
if [[ $MAXFILES =~ ^-?[0-9]+$ ]] && [ ${NUMFILES} -gt ${MAXFILES} ]; then
echo "-- maxfiles set to ${MAXFILES} but ${NUMFILES} present. Deleting the older ones."
ls ${VM_FNAM_DUP}*.vma* | head -n $((${NUMFILES}-${MAXFILES})) | xargs rm
fi
;;
esac
;;
log-end)
LOG_FNAM_OLD=$(basename ${LOGFILE})
LOG_FNAM_NEW=$(basename ${LOGFILE} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'-"$4"-"$5}')
LOG_FNAM_DUP=$(basename ${TARGET} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'"}')
mv "${LOG_FNAM_OLD}" "${LOG_FNAM_NEW}"
NUMFILES=$(ls -1 ${LOG_FNAM_DUP}*.log | wc -l)
if [[ $MAXFILES =~ ^-?[0-9]+$ ]] && [ ${NUMFILES} -gt ${MAXFILES} ]; then ls ${LOG_FNAM_DUP}*.log | head -n $((${NUMFILES}-${MAXFILES})) | xargs rm; fi
;;
esac
Next question -
Inside the hook script, ${HOSTNAME} gets me the name of the VM being backed up
Outside the hook script, $HOSTNAME gets me the name of the PVE node.
I have worked this out so that I can now include the name of the PVE node in the dump file. New variable PVENODENAME added, and no, it's likely not the most efficent thing to create this variable every time the script runs, but it does work
#!/bin/bash
# backup-start | backup-end | backup-abort | log-end | pre-stop | pre-restart | post-restart | job-start | job-end | job-abort
# If varable DUMPDIR is empty it might be a PBS backup
[ -z "${DUMPDIR}" ] && exit 0
cd "${DUMPDIR}"
MAXFILES=$(grep "prune-backups:" /etc/vzdump.conf | awk -F"=" '{print $2}')
case "${1}" in
backup-end)
PVENODENAME=$(hostname)
VM_FNAM_OLD=$(basename ${TARGET})
VM_FNAM_NEW=$(basename ${TARGET} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'-"$4"-"$5}')
VM_FNAM_DUP=$(basename ${TARGET} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'"}')
VM_TYPE=$(basename ${TARGET} | awk -F "-" '{print $2}')
mv "${VM_FNAM_OLD}" "${VM_FNAM_NEW}"
case "${VM_TYPE}" in
lxc)
NUMFILES=$(ls -1 ${VM_FNAM_DUP}*.tar* | wc -l)
if [[ $MAXFILES =~ ^-?[0-9]+$ ]] && [ ${NUMFILES} -gt ${MAXFILES} ]; then
echo "-- maxfiles set to ${MAXFILES} but ${NUMFILES} present. Deleting the older ones."
ls ${VM_FNAM_DUP}*.tar* | head -n $((${NUMFILES}-${MAXFILES})) | xargs rm
fi
;;
qemu)
NUMFILES=$(ls -1 ${VM_FNAM_DUP}*.vma* | wc -l)
if [[ $MAXFILES =~ ^-?[0-9]+$ ]] && [ ${NUMFILES} -gt ${MAXFILES} ]; then
echo "-- maxfiles set to ${MAXFILES} but ${NUMFILES} present. Deleting the older ones."
ls ${VM_FNAM_DUP}*.vma* | head -n $((${NUMFILES}-${MAXFILES})) | xargs rm
fi
;;
esac
;;
log-end)
PVENODENAME=$(hostname)
LOG_FNAM_OLD=$(basename ${LOGFILE})
LOG_FNAM_NEW=$(basename ${LOGFILE} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'-"$4"-"$5}')
LOG_FNAM_DUP=$(basename ${TARGET} | awk -F "-" '{print $1"-"$2"-'${PVENODENAME}'-"$3"-'${HOSTNAME}'"}')
mv "${LOG_FNAM_OLD}" "${LOG_FNAM_NEW}"
NUMFILES=$(ls -1 ${LOG_FNAM_DUP}*.log | wc -l)
if [[ $MAXFILES =~ ^-?[0-9]+$ ]] && [ ${NUMFILES} -gt ${MAXFILES} ]; then ls ${LOG_FNAM_DUP}*.log | head -n $((${NUMFILES}-${MAXFILES})) | xargs rm; fi
;;
esac
how to use your script?Here is the latest version of my script. Not tested with PVE6 but should work there too. I've taken into account the change from maxfiles to prune-backups in vzdump.conf, so please consider this. And yes, it would be more useful to respect prune-backups from VM/container's config, but this is a task for you guys out there as I'm too lazy for this and not using this script anymore, as mentioned
No.Hello,
is it possible to have multiple vzdump configs
Yes. Instead of configuring the retention inso I can actually have different retention policies for different storages
/etc/vzdump.conf
, you can configure it directly on the backup storage in Datacenter > Storage > Edit > Backup Retention
The setting from thefrom what I understand, this applies to all of vzdump on that node. so when I set a retention for keep last 2 it will do that for all the vzdump operations on that node even though I want one vzdump storage to have a keep last of 4 and the other one of 2.
/etc/vzdump.conf
will be used for all storages that don't configure an explicit retention themselves.Protected backups will not be considered for removal during pruning, that's the very purpose of it.further I assume the protected flag won't work as the backups get deleted via a regular rm command?
the naming schema won't change to include the name in the near future, but you can set notes for your backups since a while now and there, you can include the name: https://pve.proxmox.com/pve-docs/chapter-vzdump.html#vzdump_notesany chance this will be added into the offical build - I find the naming pretty bad when trying to find a particular backup you need to lookup the vm id.
With sed it's easy, so I did it in my scriptHello,
it's possible to modify vzdump script for add to a backup name like:
vzdump-qemu-100-2016_05_20-15_10_00.vma.lzo
tha name of VM like:
vzdump-qemu-100-VMname-2016_05_20-15_10_00.vma.lzo
When a server crash or when purge old backup or when manage backup disk space it's difficult to understand what a backup refer to.
Can you implement in future release of Proxmox this feature?
Thank you