-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·29 lines (24 loc) · 984 Bytes
/
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
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage: ./backup.sh [backup-dir]"
exit 1
fi
MOUNT_DIR=/mnt/docker-backup
BACKUP_DIR=$1
for volume in $(docker volume ls -q); do
# skip the volumes that just have that id, no name
if [ $(wc -m <<< "$volume") = "65" ]; then
continue
fi
MOUNTPOINT=$(docker volume inspect --format="{{ .Mountpoint }}" "$volume")
MOUNT_DESTINATION="${MOUNT_DIR}/${volume}"
BACKUP_DESTINATION="${BACKUP_DIR}/${volume}"
mkdir -p "$MOUNT_DESTINATION"
mkdir -p "$BACKUP_DESTINATION"
echo "backing up $volume to $BACKUP_DESTINATION"
mount --bind "$MOUNTPOINT" "$MOUNT_DESTINATION"
#rsync -azR --delete -e "/usr/bin/ssh -i /root/.ssh/rsyncbackup_id_rsa -o \"PasswordAuthentication no\"" "/.${MOUNT_DESTINATION}" [email protected]:/srv/backup/hpi_backup/docker/ || (/root/umount-volumes.sh "$MOUNT_DESTINATION"; exit 1)
cp -R ${MOUNT_DESTINATION}/* "${BACKUP_DESTINATION}/"
umount "$MOUNT_DESTINATION"
rmdir "$MOUNT_DESTINATION"
done