diff --git a/backup/backup-all.sh b/backup/backup-all.sh index 163b3a1..21f1b0e 100755 --- a/backup/backup-all.sh +++ b/backup/backup-all.sh @@ -1,7 +1,5 @@ #!/bin/bash -# by piscue - echo "Starting docker backup" echo " - backup path: $backup_path" echo " - tar options: $tar_opts" diff --git a/backup/backup-container-data.sh b/backup/backup-container-data.sh index e19f469..0a49fed 100755 --- a/backup/backup-container-data.sh +++ b/backup/backup-container-data.sh @@ -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\/) diff --git a/backup/backup-images.sh b/backup/backup-images.sh index 4b1b2ef..f90d629 100755 --- a/backup/backup-images.sh +++ b/backup/backup-images.sh @@ -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 diff --git a/backup/backup-volumes.sh b/backup/backup-volumes.sh index d361e71..d8cef98 100755 --- a/backup/backup-volumes.sh +++ b/backup/backup-volumes.sh @@ -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 diff --git a/backup/sync-dropbox.sh b/backup/sync-dropbox.sh index 66fab31..b25416e 100644 --- a/backup/sync-dropbox.sh +++ b/backup/sync-dropbox.sh @@ -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 \ No newline at end of file