Useful bash scripts for backing things up, analysing bits, etc etc
Container backups
Somewhat stolen from here and updated to work with current LXC/LXD whatever it is I have installed.
If in doubt, the snapshot process does take quite a while with my containers, not sure if that's just my ancient boot drive or the size of the containers. If you'd like more information, you might be able to add -l INFO
to the lxc snapshot
command.
#!/usr/bin/env bash
set -ex
BACKUP_DIR=/lstore/Backups/Servers/Containers
HOSTS=($(lxc list -c n,s --format csv | grep RUNNING | sed 's/[,].*//'))
for HOST in "${HOSTS[@]}"
do
echo "Backing up container '$HOST'"
BACKUP_NAME=${HOST}_$(date +"%Y-%m-%d")
echo "Generating snapshot..."
lxc snapshot ${HOST} auto-backup
echo "Publishing snapshot as image... '$BACKUP_NAME'"
lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
echo "Exporting image..."
lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz
echo "Tidying up"
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup
done