Create lxc-apt-upgrade

This commit is contained in:
Thorsten Spille 2022-03-27 14:29:44 +02:00 committed by GitHub
parent 1454b54174
commit c1be4bf967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

43
lxc-apt-upgrade Normal file
View File

@ -0,0 +1,43 @@
!/bin/bash
#
# Updates all running lxc containers on a proxmox host
PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"
prog="$(basename "$0")"
usage() {
cat >&2 <<-EOF
usage: $prog [-h] [-e EXCLUDELIST]
installs a preconfigured lxc container on your proxmox server
-e EXCLUDELIST list of container ids to exclude from backup (separator: |)
-h displays this help text
---------------------------------------------------------------------------
(C) 2021 lxc-update by bashclub (https://github.com/bashclub)
---------------------------------------------------------------------------
EOF
exit $1
}
condition="grep running"
while getopts "hi:s:c:" opt; do
case $opt in
h) usage 0 ;;
e) condition="$condition | grep -vE '$OPTARG'" ;;
*) usage 1 ;;
esac
done
shift $((OPTIND-1))
ctlist=$(pct list | $condition | cut -d' ' -f1)
for ct in $ctlist; do
for vol in $(pct config $ct | grep -E "^rootfs|^mp[0-9]+" | cut -d ' ' -f2 | cut -d',' -f1); do
snapvols="$snapvols $(pvesm path $vol | cut -d'/' -f2-)";
done
zfs-auto-snapshot --quiet --syslog --label=lxc-auto-update --keep=2 --pre-snapshot=$(pct shutdown $ct && while [[ "$(pct status $ct)" == "status: running" ]];do sleep .1; echo "waiting for shutdown of ct $ct"; done) --post-snapshot=$(pct start $ct) $snapvols
pct exec $ct /usr/bin/apt update
pct exec $ct -- bash -c "DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt -y -qq dist-upgrade"
snapvols=
done