equal
deleted
inserted
replaced
1 #!/bin/sh |
1 #!/bin/bash |
2 |
2 |
3 set -e |
3 set -e |
4 |
4 |
5 SNAPSIZE='500M' |
5 SNAPSIZE='500M' |
6 |
6 |
30 |
30 |
31 exit 1 |
31 exit 1 |
32 |
32 |
33 } |
33 } |
34 |
34 |
|
35 cleanup() { |
|
36 |
|
37 # if you have problems removing volumes then you may have the 'udisks' |
|
38 # package installed; see: |
|
39 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549691#74 |
|
40 # https://bugzilla.redhat.com/show_bug.cgi?id=577798#c5 |
|
41 # https://www.redhat.com/archives/linux-lvm/2010-August/msg00029.html |
|
42 lvs "$vg/$lvs" >/dev/null 2>&1 && lvremove -f "$vg/$lvs" |
|
43 |
|
44 } |
|
45 |
35 while getopts "s:" opt; do |
46 while getopts "s:" opt; do |
36 case $opt in |
47 case $opt in |
37 s) |
48 s) |
38 SNAPSIZE="$OPTARG" |
49 SNAPSIZE="$OPTARG" |
39 ;; |
50 ;; |
48 p=${p#/dev/} |
59 p=${p#/dev/} |
49 vg=${p%/*} |
60 vg=${p%/*} |
50 lv=${p##*/} |
61 lv=${p##*/} |
51 lvs="snap.${lv}" |
62 lvs="snap.${lv}" |
52 |
63 |
|
64 trap cleanup EXIT |
|
65 |
53 [ -n "${vg}" -a -n "${lv}" -a "${vg}" != "${p}" -a "${lv}" != "${p}" ] || usage |
66 [ -n "${vg}" -a -n "${lv}" -a "${vg}" != "${p}" -a "${lv}" != "${p}" ] || usage |
54 |
67 |
55 d=$(date +%Y%m%d%H%M%S) |
68 d=$(date +%Y%m%d%H%M%S) |
56 lvcreate -n"$lvs" -L"$SNAPSIZE" -s "$vg/$lv" |
69 lvcreate -n"$lvs" -L"$SNAPSIZE" -s "$vg/$lv" |
57 if e2fsck -fp "/dev/$vg/$lvs"; then |
70 if e2fsck -fp "/dev/$vg/$lvs"; then |
58 tune2fs -C 1 -T "$d" "/dev/$vg/$lv" |
71 tune2fs -C 1 -T "$d" "/dev/$vg/$lv" |
59 waittime=1 # second |
|
60 tries=60 |
|
61 i=1 |
|
62 # if you have problems removing volumes then you may have the 'udisks' |
|
63 # package installed; see: |
|
64 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549691#74 |
|
65 # https://bugzilla.redhat.com/show_bug.cgi?id=577798#c5 |
|
66 # https://www.redhat.com/archives/linux-lvm/2010-August/msg00029.html |
|
67 lvremove -f "$vg/$lvs" |
|
68 else |
72 else |
69 die fsck returned nonzero: this may indicate filesystem corruption on the origin volume. The snapshot has not been removed. |
73 die fsck returned nonzero: this may indicate filesystem corruption on the origin volume. |
70 fi |
74 fi |