summaryrefslogtreecommitdiff
path: root/lxd_auto_snap.sh
blob: fa87eaacefc1645e47fc6d80f49fb7f3ce2cd9de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash

echo "🔄 Starting automatic LXD snapshot for all running containers..."

# Get a list of running container names
containers=$(lxc list --format csv -c ns | awk -F, '$2 == "RUNNING" {print $1}')

if [[ -z "$containers" ]]; then
  echo "❌ No running containers found!"
  exit 1
fi

# Create a snapshot for each container
timestamp=$(date +%Y%m%d-%H%M%S)
for container in $containers; do
  snapshot_name="auto-${timestamp}"
  echo "🟡 Creating snapshot for $container: $snapshot_name"
  lxc snapshot "$container" "$snapshot_name"
done

echo "✅ Snapshot creation complete!"