Root check and docker image integration

This commit is contained in:
gospodar 2023-02-10 20:33:42 +01:00
parent 55aac75163
commit 234fe510db
2 changed files with 29 additions and 3 deletions

View File

@ -25,6 +25,8 @@ target_host="127.0.0.1" # rsync target host
target_user="backup" # rsync target user
target_key='/home/xyz/.ssh/rsync' # rsync key
#Docker
docker_enabled=false # will you use docker backup
docker_images=false # backup docker images
#Docker volumes
#Rsync
#Daily cron

24
main.sh
View File

@ -22,6 +22,11 @@ source "$config"
echo "Configuration file loaded" >&2
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
function makedir {
timestamp=$(date +%Y%m%d_%H%M)
mkdir /tmp/backify-$timestamp
@ -97,6 +102,23 @@ function push {
fi
}
function dockerbackup {
if [ "docker_enabled" = true] then
if [ "docker_images" = true] then
echo "Backing up Docker images..." >&2
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
do container_name=$i
echo -n "$container_name - "
container_image=`docker inspect --format='{{.Config.Image}}' $container_name`
mkdir -p $tmpdir/containers/$container_name
save_dir="$tmpdir/containers/$container_name/$container_name-image.tar"
docker save -o $save_dir $container_image
echo "Finished" >&2
done
fi
fi
}
function runbackup {
if [ "enabled" = true] then
# step 1 : create directory
@ -107,6 +129,8 @@ function runbackup {
vhostbackup
# step 4: log backup
logbackup
# step 5: docker backup
dockerbackup
# archive data
echo "Creating backup archive..." >&2
tar -czvf /opt/backify-$timestamp.tar.gz $tmpdir