Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple script to backup LXC containers
#!/usr/bin/env bash
set -ex
HOSTS=($(lxc list -c n --format csv))
for HOST in "${HOSTS[@]}"
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}.tar.gz
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup

This comment has been minimized.

Copy link

bmullan commented Nov 26, 2018


You might consider adding the compliment of this script that does the "restore".



This comment has been minimized.

Copy link

peterbladen commented Feb 19, 2019

Drew thanks for the script i added a tidyup option so the directory doesn't get to large, deletes backups older than 14 days

find ${BACKUP_DIR}/ -maxdepth 1 -mtime +14 -type d -exec rm -rv {} ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.