Created
July 2, 2018 21:25
-
-
Save user890104/ddd0534874fec8292ad5e3c0f09a009d to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
log_dt() { | |
date '+%d.%m.%y %H:%M:%S' | |
} | |
DAY_OF_WEEK=$(date +%u) | |
if [ $DAY_OF_WEEK -eq 1 ] | |
then | |
SUFFIX=weekly | |
else | |
SUFFIX=daily | |
fi | |
SNAPSHOT=backup-cron | |
cd /mnt/backup-tmp | |
for CONTAINER in $(lxc list --format csv --columns n) | |
do | |
log_dt; echo Backing up container ${CONTAINER} | |
log_dt; echo Delete old snapshot ${CONTAINER}/${SNAPSHOT} | |
lxc delete ${CONTAINER}/${SNAPSHOT} | |
log_dt; echo Make new snapshot ${CONTAINER} ${SNAPSHOT} | |
lxc snapshot ${CONTAINER} ${SNAPSHOT} | |
log_dt; echo Delete old image ${CONTAINER}_${SNAPSHOT} | |
lxc image delete ${CONTAINER}_${SNAPSHOT} | |
log_dt; echo Publish snapshot ${CONTAINER}/${SNAPSHOT} to image ${CONTAINER}_${SNAPSHOT} | |
lxc publish ${CONTAINER}/${SNAPSHOT} --alias ${CONTAINER}_${SNAPSHOT} | |
log_dt; echo Delete new snapshot ${CONTAINER}/${SNAPSHOT} | |
lxc delete ${CONTAINER}/${SNAPSHOT} | |
log_dt; echo Export image ${CONTAINER}_${SNAPSHOT} to archive ${CONTAINER}_${SUFFIX} | |
lxc image export ${CONTAINER}_${SNAPSHOT} ${CONTAINER}_${SUFFIX} | |
log_dt; echo Delete new image ${CONTAINER}_${SNAPSHOT} | |
lxc image delete ${CONTAINER}_${SNAPSHOT} | |
log_dt; echo Upload archive ${CONTAINER}_${SUFFIX}.tar.gz to FTP and delete it when done | |
ncftpput -DD backup /lxd ${CONTAINER}_${SUFFIX}.tar.gz | |
log_dt; echo Backup of container ${CONTAINER} complete | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment