added some validations

This commit is contained in:
rick
2019-08-03 21:17:48 +02:00
parent 1a394337c7
commit aa812c456c
2 changed files with 20 additions and 5 deletions

View File

@@ -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.
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/`

View File

@@ -1,12 +1,30 @@
#!/bin/bash
#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);
do
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
done
#own data for backupuser
chown -R rick-monitoring:rick-monitoring /home/rick-monitoring/backup
chown -R ${backupuser}:${backupuser} ${backuppath}