added some validations
This commit is contained in:
@@ -4,6 +4,3 @@ Backupscript for LXC Container
|
|||||||
|
|
||||||
This script creates a copy of all running containers, backs them up (via lxc export) and deletes them afterwards.
|
This script creates a copy of all running containers, backs them up (via lxc export) and deletes them afterwards.
|
||||||
Copys are created to prevent database inconsistencies -> copies are way faster than exports
|
Copys are created to prevent database inconsistencies -> copies are way faster than exports
|
||||||
|
|
||||||
Default backuppath for lxd snap installs are `/var/snap/lxd/common/lxd/backups` you can simlink this dir to your favorite backup destination
|
|
||||||
In this script its `/home/rick-monitoring/backup/`
|
|
||||||
|
|||||||
@@ -1,12 +1,30 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#this script makes a copy of each container and backups afterwards the copies
|
#this script makes a copy of each container and backups afterwards the copies
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
backuppath='/home/rick-monitoring/backup/'
|
||||||
|
backupuser='rick-monitoring'
|
||||||
|
|
||||||
|
#some validations
|
||||||
|
if [ ! -d ${backuppath} ]
|
||||||
|
then
|
||||||
|
echo "Please set a backup directory which is accessible by this script"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
id $backupuser > /dev/null 2>&1
|
||||||
|
if [ $? ! -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "Please set a valid user within this script"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
for container in $(lxc list --format csv -c n | grep -v backup);
|
for container in $(lxc list --format csv -c n | grep -v backup);
|
||||||
do
|
do
|
||||||
lxc copy ${container} ${container}-backup
|
lxc copy ${container} ${container}-backup
|
||||||
lxc export ${container}-backup $(date +%Y_%m_%d)-${container}.tar.gz --optimized-storage
|
lxc export ${container}-backup ${backuppath}$(date +%Y_%m_%d)-${container}.tar.gz --optimized-storage
|
||||||
lxc delete ${container}-backup
|
lxc delete ${container}-backup
|
||||||
done
|
done
|
||||||
|
|
||||||
#own data for backupuser
|
#own data for backupuser
|
||||||
chown -R rick-monitoring:rick-monitoring /home/rick-monitoring/backup
|
chown -R ${backupuser}:${backupuser} ${backuppath}
|
||||||
|
|||||||
Reference in New Issue
Block a user