-
Notifications
You must be signed in to change notification settings - Fork 0
/
volumes_backup.sh
executable file
·44 lines (35 loc) · 1.3 KB
/
volumes_backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
START=$SECONDS
# Use the commandline argument as the target directory (by default its ./ )
TARGETDIR=${1:-./}
# Make sure the targetdir has 1 slash at the end by removing any slash first, and then appending it
TARGETDIR=${TARGETDIR%/}
TARGETDIR=${TARGETDIR}/
# Create the targetdir (will be ignored if it already exists)
mkdir -p $TARGETDIR
echo "-> docker compose down"
docker compose down
# loop through each volume
for VOLUME in gitea
do
echo "-> backup volume $VOLUME"
docker run --rm --name="docker_volume_backup_$VOLUME" -v $VOLUME:/volume --log-driver none rboonzaijer/volume-backup backup -c none > ${TARGETDIR}backup_$VOLUME.tar # '-c none' = no compression
done
echo "-> docker compose up -d"
docker compose up -d
echo "-> docker ps --filter \"name=gitea\""
docker ps --filter "name=gitea"
# show how much time this took...
DURATION=$(( SECONDS - START ))
if (( $DURATION > 3600 )) ; then
let "hours=DURATION/3600"
let "minutes=(DURATION%3600)/60"
let "seconds=(DURATION%3600)%60"
echo "Completed in $hours hour(s), $minutes minute(s) and $seconds second(s)"
elif (( $DURATION > 60 )) ; then
let "minutes=(DURATION%3600)/60"
let "seconds=(DURATION%3600)%60"
echo "Completed in $minutes minute(s) and $seconds second(s)"
else
echo "Completed in $DURATION seconds"
fi