cause with big containers we need way to much diskspace for clones. also the backup job runs at night were no one uses these containers so they can be stopped without a problem
36 lines
913 B
Bash
Executable File
36 lines
913 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
|
|
|
|
#only backup container which contain a 1 at the end of the line
|
|
for container in $(${lxccmd} list --format csv -c n | grep "1$");
|
|
do
|
|
${lxccmd} stop ${container}
|
|
${lxccmd} export ${container} ${backuppath}$(date +%Y_%m_%d)-lxc-${container}.tar.gz --instance-only --optimized-storage
|
|
${lxccmd} start ${container}
|
|
done
|
|
|
|
#housekeeping - keep last 14 days
|
|
find ${backuppath} -mtime +14 -exec rm -f {} \;
|
|
|
|
#own data for backupuser
|
|
chown -R ${backupuser}:${backupuser} ${backuppath}
|