Last active
November 2, 2024 03:22
-
-
Save dinomite/b516e835b09ea08526ff17114979900f to your computer and use it in GitHub Desktop.
Simple script to backup LXC containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/