Keep custom Proxmox LXC template up to date
This script fully clones LXC 999
(Debian Based Container) to the storage named SSD-Storage
starts it and installs updates. Afterwards it will dump a Backup to the storage named NAS
mounted in /mnt/pve/NAS
and copies it with a meaningfull name in the local
template cache.
Every Sunday this script will archive a copy of the template and name it with the current date, the last 4 archived images will be kept.
If you want to reuse this script edit the storages, e.g. if you only have the local storage replace SSD-Storage
and NAS
with local
, also replace /mnt/pve/NAS/dump/
with /var/lib/vz/
. Also be sure to that ID 9876
is not taken and your custom template is ID 999
, or replace the ID’s accordingly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
rm -rf /mnt/pve/NAS/dump/vzdump-lxc-9876*
pct clone 999 9876 --full --hostname "custom-debian-intermediate-stage" --storage SSD-Storage
pct start 9876
pct exec 9876 -- bash -c 'apt-get update && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get clean -y && history -c'
pct stop 9876
vzdump 9876 --compress gzip --mode stop --storage NAS
mv /mnt/pve/NAS/dump/vzdump-lxc-9876*.tar.gz /var/lib/vz/template/cache/debian-bullseye-custom_arm64.tar.gz
rm /mnt/pve/NAS/dump/vzdump-lxc-9876*.log
pct destroy 9876 --purge
if [[ $(date +%u) -eq 7 ]]; then
cp /var/lib/vz/template/cache/debian-bullseye-custom_arm64.tar.gz "/var/lib/vz/template/cache/debian-bullseye-custom_arm64_$(date +'%Y.%m.%d').tar.gz"
fi
if [[ $(ls -1 /var/lib/vz/template/cache/debian-bullseye-custom_arm64_* | wc -l) -gt 4 ]]; then
rm "$(ls -t /var/lib/vz/template/cache/debian-bullseye-custom_arm64_* | tail -1)"
fi
exit 0
Gist-Source: Keep-custom-Proxmox-LXC-template-up-to-date.md