summarylogtreecommitdiffstats
path: root/btrfs_create_filesystem_snapshot
blob: 5d9375489af448b025876f75b7f1ae71b42134d0 (plain)
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
#!/bin/bash

set -e

mkdir -p /mnt/urbackup_snaps

SNAP_ID=$1
SNAP_MOUNTPOINT="$2"
SNAP_NAME="$3"
SNAP_ORIG_PATH="$4"
SNAP_DEST=/mnt/urbackup_snaps/$SNAP_ID

TYPE=$(df -T -P | egrep " ${SNAP_MOUNTPOINT}\$" | head -n 1 | tr -s " " | cut -d" " -f2)

if [[ $TYPE == "" ]]
then
        if btrfs subvolume list -o "$SNAP_MOUNTPOINT" > /dev/null 2>&1
        then
                TYPE="btrfs"
        fi
fi

if [[ $TYPE == "btrfs" ]]
then
        btrfs subvolume snapshot -r "$SNAP_MOUNTPOINT" "$SNAP_DEST"
else
        echo "Cannot create snapshot of file system with type $TYPE"
        exit 1
fi

echo "SNAPSHOT=$SNAP_DEST"

exit 0