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_user="backup" # rsync target user
target_key='/home/xyz/.ssh/rsync' # rsync key target_key='/home/xyz/.ssh/rsync' # rsync key
#Docker #Docker
docker_enabled=false # will you use docker backup
docker_images=false # backup docker images
#Docker volumes #Docker volumes
#Rsync #Rsync
#Daily cron #Daily cron

24
main.sh
View File

@ -22,6 +22,11 @@ source "$config"
echo "Configuration file loaded" >&2 echo "Configuration file loaded" >&2
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
function makedir { function makedir {
timestamp=$(date +%Y%m%d_%H%M) timestamp=$(date +%Y%m%d_%H%M)
mkdir /tmp/backify-$timestamp mkdir /tmp/backify-$timestamp
@ -97,6 +102,23 @@ function push {
fi 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 { function runbackup {
if [ "enabled" = true] then if [ "enabled" = true] then
# step 1 : create directory # step 1 : create directory
@ -107,6 +129,8 @@ function runbackup {
vhostbackup vhostbackup
# step 4: log backup # step 4: log backup
logbackup logbackup
# step 5: docker backup
dockerbackup
# archive data # archive data
echo "Creating backup archive..." >&2 echo "Creating backup archive..." >&2
tar -czvf /opt/backify-$timestamp.tar.gz $tmpdir tar -czvf /opt/backify-$timestamp.tar.gz $tmpdir