Files
lxc_backup/lxc_backup.sh
rick 8183b65f53 fixed rm command, edit days of keeped backup
-> rm command: {} contains already the full path for deletion
-> days to keep: local nas script delets files which are older than 30
days.. cause of this rsync keeps syncing old files everyday
2019-12-18 22:28:36 +01:00

35 lines
903 B
Bash
Executable File

#!/bin/bash
#this script makes a copy of each container and backups afterwards the copies
#set -x
backuppath='/srv/backUP/lxc/'
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| grep -v "^oo" | grep -v test);
do
${lxccmd} copy ${container} ${container}-backup
${lxccmd} export ${container}-backup ${backuppath}$(date +%Y_%m_%d)-lxc-${container}.tar.gz --optimized-storage
${lxccmd} delete ${container}-backup
done
#housekeeping - keep last 28 days
find ${backuppath} -mtime +28 -exec rm -f {} \;
#own data for backupuser
chown -R ${backupuser}:${backupuser} ${backuppath}