Skip to content

Commit

Permalink
mass wip shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
piscue committed Jan 9, 2024
1 parent df6dd3d commit f9e29ac
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
2 changes: 0 additions & 2 deletions backup/backup-all.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

# by piscue

echo "Starting docker backup"
echo " - backup path: $backup_path"
echo " - tar options: $tar_opts"
Expand Down
2 changes: 2 additions & 0 deletions backup/backup-container-data.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

echo "Backing up container data (inspection output)"
echo "--------------------------------------------"
for i in $(docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/)
Expand Down
12 changes: 7 additions & 5 deletions backup/backup-images.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/bash

echo "Backing up container images"
echo "---------------------------"

for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
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 $backup_path/$container_name
save_file="$backup_path/$container_name/$container_name-image.tar"
docker save -o $save_file $container_image
container_image=$(docker inspect --format='{{.Config.Image}}' "$container_name")
mkdir -p "$backup_path"/"$container_name"
save_file="$backup_path"/"$container_name"/"$container_name-image.tar"
docker save -o "$save_file" "$container_image"
echo "OK"
done

Expand Down
12 changes: 7 additions & 5 deletions backup/backup-volumes.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#!/bin/bash

# Path: backup-volumes.sh
# Backup all volumes from docker

echo "Backing up volumes"
echo "------------------"

for volume in `docker volume inspect -f '"{{.Name}}""{{.Mountpoint}}"' $(docker volume ls -q)`
for volume in $(docker volume inspect -f '"{{.Name}}""{{.Mountpoint}}"' $(docker volume ls -q))
do
# Get the volume name and path
volume_name=`echo $volume | cut -f2 -d\"`
volume_path=`echo $volume | cut -f4 -d\"`
volume_name=$(echo "$volume" | cut -f2 -d\")
volume_path=$(echo "$volume" | cut -f4 -d\")

# Create the backup directory
mkdir -p $backup_path/volumes
mkdir -p "$backup_path"/volumes


# Backup the volume
echo -n "$volume_name - "
docker run --rm -v $volume_path:/volume -v $backup_path/volumes:/backup busybox tar -cvzf /backup/$volume_name.tar.gz /volume >/dev/null 2>&1
docker run --rm -v "$volume_path":/volume -v "$backup_path"/volumes:/backup busybox tar -cvzf /backup/"$volume_name".tar.gz /volume >/dev/null 2>&1
echo "OK"
done

Expand Down
42 changes: 22 additions & 20 deletions backup/sync-dropbox.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
#!/bin/bash

for i in $(docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/)
do container_name=$i

# Creating container folder
docker run --rm --user=$(id -u):$(id -g) \
-v $PWD/config:/config \
-v $backup_path:/workdir \
docker run --rm --user="$(id -u)":"$(id -g)" \
-v "$PWD"/config:/config \
-v "$backup_path":/workdir \
peez/dropbox-uploader \
mkdir $container_name
mkdir "$container_name"

# Uploading image
echo "$container_name - image to Dropbox "
# TODO check if the file exists
docker run --rm --user=$(id -u):$(id -g) \
--name dropbox-$container_name-image-backup \
-v $PWD/config:/config \
-v $backup_path:/workdir \
docker run --rm --user="$(id -u)":"$(id -g)" \
--name "dropbox-$container_name-image-backup" \
-v "$PWD"/config:/config \
-v "$backup_path":/workdir \
peez/dropbox-uploader \
upload $container_name/$container_name-image.tar \
$container_name/$container_name-image.tar && \
upload "$container_name"/"$container_name-image.tar" \
"$container_name"/"$container_name-image.tar" && \

# remove local image, TODO creating a condition to know if the file
# uploaded well before deleting
rm -f $backup_path/$container_name/$container_name-image.tar
rm -f "$backup_path"/"$container_name"/"$container_name-image.tar"

# Uploading volume
echo "$container_name - volume to Dropbox "
# TODO check if the file exists
docker run --rm --user=$(id -u):$(id -g) \
--name dropbox-$container_name-volume-backup \
-v $PWD/config:/config \
-v $backup_path:/workdir \
docker run --rm --user="$(id -u)":"$(id -g)" \
--name "dropbox-$container_name-volume-backup" \
-v "$PWD"/config:/config \
-v "$backup_path":/workdir \
peez/dropbox-uploader \
upload $container_name/$container_name-volume.tar.xz \
$container_name/$container_name-volume.tar.xz && \
upload "$container_name"/"$container_name-volume.tar.xz" \
"$container_name"/"$container_name-volume.tar.xz" && \

# remove local volume, TODO creating a condition to know if the file
# uploaded well before deleting
rm -f $backup_path/$container_name/$container_name-volume.tar.xz
done
rm -f "$backup_path"/"$container_name"/"$container_name-volume.tar.xz"
done

0 comments on commit f9e29ac

Please sign in to comment.