commit 211a17ac573e36f915b4ca9679b9f648d03cdc90
parent e80c84930c0207274ccce0cb597729b02a37da6a
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Fri, 28 Nov 2025 23:38:03 +0100
feat(intel): add lxc-snapshot script
Diffstat:
1 file changed, 61 insertions(+), 0 deletions(-)
diff --git a/debian_postinstall.sh b/debian_postinstall.sh
@@ -156,3 +156,64 @@ cat <<EOF > /etc/exports
/srv/nfs/csi-snac 10.0.0.0/24(rw,insecure,sync,no_root_squash)
/srv/nfs/csi-thelounge 10.0.0.0/24(rw,insecure,sync,no_root_squash)
EOF
+
+# Install lxc snapshot cronjob
+cat <<EOF > /usr/local/bin/lxc-snapshot.sh
+#!/usr/bin/env bash
+#
+# Script for LXC container backup
+#
+# set -o errexit
+# set -o nounset
+set -o xtrace
+
+BACKUP_PATH=/srv/nfs/backup/lxc
+
+ctx=($(lxc-ls))
+
+for c in "${ctx[@]}"; do
+ snap_name="snap-$c"
+
+ # Create complete clone (not just snapshot)
+ # https://linuxcontainers.org/lxc/manpages/man1/lxc-copy.1.html
+ lxc-copy --name $c --newname $snap_name --allowrunning -o-
+
+ # Create tar archive in BACKUP_PATH with unix timestamp
+ tar -cjf "$BACKUP_PATH/${c}_$(date +%s).tar.bz2" "/srv/lxc/$snap_name"
+
+ # Cleanup the clone
+ lxc-destroy $snap_name
+done;
+
+# Prune snapshots older than 5 days
+find "$BACKUP_PATH/" -type f -mtime +5 -exec rm -f {} \;
+EOF
+
+chmod +x /usr/local/bin/lxc-snapshot.sh
+
+cat <<EOF > /etc/systemd/system/lxc-snapshot.timer
+[Unit]
+Description=Take lxc snapshots
+
+[Timer]
+Unit=snapshot.service
+OnCalendar=Mon-Sun 04:27
+
+[Install]
+WantedBy=timers.target
+EOF
+
+cat <<EOF > /etc/systemd/system/lxc-snapshot.service
+[Unit]
+Description=Take lxc snapshots
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c '/usr/local/bin/lxc-snapshot.sh'
+
+[Install]
+WantedBy=multi-user.target
+EOF
+
+systemctl daemon-reload
+systemctl enable lxc-snapshot.timer