Created
April 13, 2023 23:11
-
-
Save leskovia/0479790155e44df47957db8ca290a337 to your computer and use it in GitHub Desktop.
Copy running lxc containers to reserv host
This file contains hidden or 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 | |
#Set destination host | |
DHOST="lxchost2" | |
#Get list of running LXD containers | |
LXD_CONTAINERS=$(lxc list -c n,s --format csv | grep RUNNING | awk -F, '{print $1}') | |
LOGFILE="/var/log/lxcbackup.log" | |
LOCKFILE="/var/log/backuplxd.lock" | |
if [ -f %LOCKFILE ]; then | |
echo "Already running" >> $LOGFILE | |
exit 1 | |
fi | |
touch $LOCKFILE | |
date +"# Start Backup %T %D" >> $LOGFILE | |
#Iterate through list of LXD containers | |
for CONTAINER in $LXD_CONTAINERS | |
do | |
CONT="$CONTAINER;" | |
#Check blacklist | |
if grep -q $CONT /usr/local/scripts/not_copy_list.txt; | |
then | |
echo "# Skip blacklisted $CONTAINER" >> $LOGFILE | |
else | |
echo "#" lxc copy --refresh $CONTAINER $DHOST:$CONTAINER >> $LOGFILE | |
date +"# begin copy at %T" >> $LOGFILE | |
echo "-------" >> $LOGFILE | |
lxc copy --refresh $CONTAINER $DHOST:$CONTAINER 2>> $LOGFILE | |
lxc config set $DHOST:$CONTAINER boot.autostart 0 2>> $LOGFILE | |
echo "-------" >> $LOGFILE | |
fi | |
done | |
date +"# Ending backup %T %D" >> $LOGFILE | |
echo "-----------------------------" >> $LOGFILE | |
rm $LOCKFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment