Instantly share code, notes, and snippets.

Embed
What would you like to do?
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}.tar.gz
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup
done
@bmullan

This comment has been minimized.

Copy link

bmullan commented Nov 26, 2018

Drew...

You might consider adding the compliment of this lxc-backup.sh script that does the "restore".

Brian

@peterbladen

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