Browse Source

bash backup

master
zeus 3 years ago
parent
commit
3be2fd9cfb
  1. 4
      .gitignore
  2. 1
      src-local/mybackups/README
  3. 58
      src-local/swarmlab_backup_service.sh

4
.gitignore

@ -2,7 +2,11 @@
node_modules
src-local/instance/
src-local/builders/
!./src-local/hybrid/connect/container-stop.sh
!src-local/mybackups/README
src-local/mybackups/
src-local/hybrid/connect/
src-local/hybrid/keys.json
src-local/logs

1
src-local/mybackups/README

@ -0,0 +1 @@
Here you can see all backups

58
src-local/swarmlab_backup_service.sh

@ -0,0 +1,58 @@
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
TARGET="$(readlink "$SOURCE")"
if [[ $TARGET == /* ]]; then
SOURCE="$TARGET"
else
DIR="$( dirname "$SOURCE" )"
SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
fi
done
SRPATH="$( dirname "$SOURCE" )"
SFPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
if [ "$SFPATH" != "$SRPATH" ]; then
RDIR=$SRPATH # relativ path directory
fi
cwdir=$PWD
wdir=$SFPATH
if [[ $# -eq 0 ]] ; then
echo 'no service'
exit 1
fi
if [[ -z "$1" ]] ; then
echo 'no service'
exit 1
fi
service=$1
servicebase=$(echo $service | cut -d'_' -f1)
#volumetmp=$(docker inspect --format "{{json .Mounts }}" $service | jq .[] | jq '.Destination')
#volumetmp=$(docker inspect --format "{{json .Mounts }}" $service | jq .[] | jq '.Destination .Source' | jq . -s)
# $(docker inspect --format '{{json .Mounts }}' microservice-xelatexthesis_masterservice_1 | jq '.[] | {local: .Source, dest: .Destination}')
date=$(date '+%Y-%m-%d-%H-%M')
volume=1
docker inspect --format '{{json .Mounts }}' microservice-xelatexthesis_masterservice_1 | jq -c '.[]' | while IFS=$"\n" read -r line; do
Local=$(echo "$line" | jq -r '.Source')
Dest=$(echo "$line" | jq -r '.Destination')
if [[ $Local == *"$servicebase"* ]]; then
v=v${volume}
docker run --rm --volumes-from $service -v $SFPATH/mybackups:/backup alpine /bin/sh -c "mkdir -p /backup/${service}.${date}; tar -zcvf /backup/${service}.${date}/$v.tar.gz $Dest; echo \"Local:$Local Dest:$Dest\" > /backup/${service}.${date}/$v.info "
((volume++))
fi
done
Loading…
Cancel
Save