This commit is contained in:
2023-12-20 16:32:38 +01:00
commit 02bbcc3878
4 changed files with 66 additions and 0 deletions

32
backup-lxd.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Basic shell script to backup required LXD parts ##
## Backup and restore LXD config ##
## Today's date ##
if [[ $1 = '' ]]
then
echo "use $0 virtual-machine|container"
exit
fi
NOW=$(date +'%m-%d-%Y')
echo $(date) "Starting backup of LXD ..."
## Dump LXD server config ##
echo $(date) "Making backup of lxd.config ..."
lxd init --dump > "/nfs/nas/LXD-Backup/lxd.config.${NOW}"
## Dump all instances list ##
echo $(date) "Making backup of lxd.instances.list ..."
lxc list > "/nfs/nas/LXD-Backup/lxd.instances.list.${NOW}"
## Make sure we know LXD version too ##
echo $(date) "Making backup of lxd.version ..."
snap list lxd > "/nfs/nas/LXD-Backup/lxd-version.${NOW}"
## Backup all container Instances
for i in $(lxc list type=$1 -c n --format csv)
do
echo $(date) "Making backup of ${i} ..."
lxc export "${i}" "/nfs/nas/LXD-Backup/${i}-backup-$(date +'%m-%d-%Y').tar.xz" --optimized-storage
done
echo $(date) "Backup of LXD ended."