Files
lxc_backup/lxc_backup.sh
2019-08-05 20:26:05 +02:00

32 lines
799 B
Bash
Executable File

#!/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'
lxccmd='/snap/bin/lxc'
#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 [ $? -ne 0 ]
then
echo "Please set a valid user within this script"
exit 2
fi
for container in $(${lxccmd} list --format csv -c n | grep -v backup);
do
${lxccmd} copy ${container} ${container}-backup
${lxccmd} export ${container}-backup ${backuppath}$(date +%Y_%m_%d)-${container}.tar.gz --optimized-storage
${lxccmd} delete ${container}-backup
done
#own data for backupuser
chown -R ${backupuser}:${backupuser} ${backuppath}