Welcome to mirror list, hosted at ThFree Co, Russian Federation.

find-volume.sh « lvm-scripts « Snapshots « Library « Duplicati - github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ae2029ed4ac57c736b26800f380932eeb43c1b1 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

# This script returns the device on which the volume is mounted
# 
# Input is always:
#  $1 = name of the folder to locate the LVM device for
#
# The script MUST output a line with device="<path>", where path is the lvm id.
# The script MUST output a line with mountpoint="<path>", where path is the device root.
# This ensures that any tools invoked can write info to the console,
#  and this will not interfere with the program functions.


#
# Rename the input
#
NAME=$1

#
# Get the reported mount point for the current folder
#
VOLUME=`df -P "$NAME" | tail -1 | awk '{ print $1}'`
if [ "$?" -ne 0 ] || [ -z "$VOLUME" ]
then
	[[ "$?" -ne 0 ]] && EXIT_CODE=$? || EXIT_CODE=-1
	echo "Error: unable to determine device for $NAME"
	exit $EXIT_CODE
fi

MOUNTPOINT=`df -P "$NAME" | tail -1 | awk '{ print $NF}'`
if [ "$?" -ne 0 ] || [ -z "$MOUNTPOINT" ]
then
	[[ "$?" -ne 0 ]] && EXIT_CODE=$? || EXIT_CODE=-1
	echo "Error: unable to determine mount point for $NAME"
	exit $EXIT_CODE
fi

#
# Get the LVM path for the mapped volume
#

function get_lvmid {
	LVMID=`lvs "$1" --options vg_name,lv_name --noheadings 2>/dev/null | tail -1 | awk '{ print $1 "/" $2}'`
	if [ "$?" -ne 0 ] 
	then
		EXIT_CODE=$?
		echo "Error: Unable to determine volume group (VG) for mapped volume $VOLUME"
		exit $EXIT_CODE
	fi
	export LVMID
}

get_lvmid $VOLUME

#
# Get the LVM path for the mapped volume (second try)
#
if [ -z "$LVMID" ]
then
	VOLUME=`mount | awk '($3 == "'$MOUNTPOINT'") {print $1}'`
	get_lvmid $VOLUME
fi

if [ -z "$LVMID" ]
then
	EXIT_CODE=-1
	echo "Error: unable to determine volume group (VG) for $NAME"
	exit $EXIT_CODE
fi

echo "mountpoint=\"$MOUNTPOINT\""
echo "device=\"$LVMID\""

exit 0