Skip to content

Instantly share code, notes, and snippets.

@dinomite
Last active May 22, 2021 21:20
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinomite/b516e835b09ea08526ff17114979900f to your computer and use it in GitHub Desktop.
Save dinomite/b516e835b09ea08526ff17114979900f to your computer and use it in GitHub Desktop.
Simple script to backup LXC containers
#!/usr/bin/env bash
set -ex
BACKUP_DIR=/path/to/where/backups/should/live
HOSTS=($(lxc list -c n --format csv))
for HOST in "${HOSTS[@]}"
do
BACKUP_NAME=${HOST}-$(date +"%Y-%m-%d")
lxc snapshot ${HOST} auto-backup
lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup
done
@Longshot
Copy link

Awesome :)

One question though.. Will this also re add devices back to the container's config that you've added with:
lxc config device add c1 sharedwww disk source=/wwwdata/ path=/var/www/html/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment