Skip to contentSkip to conversation

vgimportclone: script to import SAN snapshots and clones

PATCH Superseded Mike Snitzer 2 participants 3 messages May 12, 2009 – May 13, 2009 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vgimportclone: script to import SAN snapshots and clones

Revised vgimportclone that should be ready for inclussion in the LVM2 tree. Is installed as 'vgimportclone' and a man page is provided.

--

 WHATS_NEW                |    1 +
 man/Makefile.in          |    4 +-
 man/vgimportclone.8.in   |   32 +++++
 scripts/Makefile.in      |    2 +
 scripts/vgimportclone.sh |  292 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 329 insertions(+), 2 deletions(-)
WHATS_NEW +1 -0
index 3a656ce..acdee84 100644
@@ -1,5 +1,6 @@
 Version 2.02.46 - 
 ================================
+  Add vgimportclone and install it and the man page by default.
   Add make install_lvm2 as complement to device-mapper install.
   Reject missing PVs from allocation in toollib.
   Fix PV datalignment for values starting prior to MDA area. (2.02.45)
man/Makefile.in +2 -2
index 1406dd9..4fde75b 100644
@@ -29,8 +29,8 @@ MAN8=lvchange.8 lvconvert.8 lvcreate.8 lvdisplay.8 lvextend.8 lvm.8 \
 	lvscan.8 pvchange.8 pvck.8 pvcreate.8 pvdisplay.8 pvmove.8 pvremove.8 \
 	pvresize.8 pvs.8 pvscan.8 vgcfgbackup.8 vgcfgrestore.8 vgchange.8 \
 	vgck.8 vgcreate.8 vgconvert.8 vgdisplay.8 vgexport.8 vgextend.8 \
-	vgimport.8 vgmerge.8 vgmknodes.8 vgreduce.8 vgremove.8 vgrename.8 \
-	vgs.8 vgscan.8 vgsplit.8 $(FSADMMAN)
+	vgimport.8 vgimportclone.8 vgmerge.8 vgmknodes.8 vgreduce.8 vgremove.8 \
+	vgrename.8 vgs.8 vgscan.8 vgsplit.8 $(FSADMMAN)
 MAN8CLUSTER=clvmd.8
 MAN8DM=dmsetup.8
 MAN5DIR=${mandir}/man5
man/vgimportclone.8.in new file +32 -0
new file mode 100644
index 0000000..50ee4d7
@@ -0,0 +1,32 @@
+.TH VGIMPORTCLONE 8 "LVM TOOLS #VERSION#" "Red Hat, Inc." \" -*- nroff -*-
+.SH NAME
+vgimportclone \- restore hardware snapshot
+.SH SYNOPSIS
+.B vgimportclone
+[\-n VolumeGroupName]
+[\-l LvmConfigFile]
+[\-i]
+[\-h]
+PhysicalVolume [PhysicalVolume...]
+.SH DESCRIPTION
+.B vgimportclone
+renames the VG and changes the associated VG and PV UUIDs.
+.SH OPTIONS
+.TP
+.I \-n VolumeGroupName
+Rename the snapshot VG to this name.
+.TP
+.I \-l LvmConfigFile
+The template for the config that is used during the VG rename and UUID changes.
+.TP
+.I \-i
+Import exported Volume Groups.
+.TP
+.I \-h
+Print help message
+.SH ENVIRONMENT VARIABLES
+.TP
+\fBLVM_BINARY\fP 
+The LVM2 binary to use.
+Defaults to "lvm".
+
scripts/Makefile.in +2 -0
index 8a03500..e845cca 100644
@@ -20,6 +20,8 @@ include $(top_srcdir)/make.tmpl
 install:
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) lvm_dump.sh \
 		$(sbindir)/lvmdump
+	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) vgimportclone.sh \
+		$(sbindir)/vgimportclone
 ifeq ("@FSADM@", "yes")
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) fsadm.sh \
 		$(sbindir)/fsadm
scripts/vgimportclone.sh new file +292 -0

292 lines not on this page · raw message

#1 lore raw

PATCH 1/1 vgimportclone: script to import SAN snapshots and clones

Quoted 4 lines · Mike Snitzer

Revised vgimportclone that should be ready for inclussion in the LVM2 tree. Is installed as 'vgimportclone' and a man page is provided.

+vgimportclone \- restore hardware snapshot

restore ?

Better to describe what it actually does.

Quoted 4 lines

+[\-n VolumeGroupName]
+[\-l LvmConfigFile]
+[\-i]
+[\-h]

Can we ensure the parameters are in line with the rest of the tools? What are the long forms for those names? (All one-character options should have verbose forms too.)

Is this really optional (indicated by square brackets)? Can we make it compulsory? (As we do in some other tools, even when we can work it out.)
Then it can be positional and not need -n.
- I don't think any tools use -n for VG name.

Quoted 3 lines

+.SH DESCRIPTION
+.B vgimportclone
+renames the VG and changes the associated VG and PV UUIDs.

Longer description?
'changes' to what?

Why would anyone use this script?

Quoted 1 line

+.I \-l LvmConfigFile

I don't think we use 'Lvm' capitalised like that anywhere. What is this parameter for?
If we add it, what other tools might also want to use it and might -l already be in use?

Quoted 1 line

+The template for the config that is used during the VG rename and UUID changes.

Template? Explain.

Quoted 3 lines

+.TP
+.I \-i
+Import exported Volume Groups.

Explain.

Quoted 2 lines

+.I \-h
+Print help message

No need in the current style - covered by lvm(8), which should be referenced. It should be added to the command list on lvm(8) too.

Make sure --version -v and -d and --quiet and -t are accepted too (and passed to any lvm cmds run where appropriate).

man/vgimportclone.8.in line 31

Quoted 5 lines

+.SH ENVIRONMENT VARIABLES
+.TP
+\fBLVM_BINARY\fP

man/vgimportclone.8.in new file +2 -0
+The LVM2 binary to use.
+Defaults to "lvm".

Need to support LVM_SYSTEM_DIR - referenced in lvm(8).

Have an EXAMPLE section too.

scripts/vgimportclone.sh line 17

Quoted 2 lines
scripts/vgimportclone.sh new file +2 -0
+# vgimportclone: This script is used to rename the VG and change the associated
+#                VG and PV UUIDs (primary application being HW snapshot restore)

Oops - that comment is better than the man page:-)

scripts/vgimportclone.sh line 82

Quoted 10 lines
scripts/vgimportclone.sh new file +10 -0
+function usage {
+### display usage message
+    echo "${SCRIPTNAME} - Restore LVM data from a hardware snapshot"
+    echo -e "Usage: ${SCRIPTNAME} [options] disk1 [disk2 ...]"
+    echo -e "\t\t-h\t\t- Display this usage message"
+    echo -e "\t\t-i\t\t- Import any exported volume groups found"
+    echo -e "\t\t-n\t\t- Name for the new volume group(s)"
+    echo -e "\t\t-l [path]\t- location of lvm.conf (default ${LVMCONF})"
+    exit 0
+}

Inconsistent with man page...brackets, abbreviations, descriptions etc.

Quoted 1 line

+ -d)

See above.

Quoted 1 line

+ DEBUG=1

increment?

Quoted 1 line

+ exec 2> ./${SCRIPTNAME}.log

Errr ./ ??? What directory are we in and what file might we be clobbering? (Security blocker.) Better to retain output from earlier runs too and ensure there's a timestamp of the run somewhere (cf. lvmdump).

scripts/vgimportclone.sh line 139

Quoted 2 lines
scripts/vgimportclone.sh new file +2 -0
+        -l)
+            LVMCONF="$2"; shift; shift

Do we even need that arg if we have LVM_SYSTEM_DIR?

scripts/vgimportclone.sh line 195

Quoted 5 lines

+"$AWK" -v DEV=${TMP_LVM_SYSTEM_DIR} -v CACHE=${TMP_LVM_SYSTEM_DIR}/cache \

scripts/vgimportclone.sh new file +4 -0
+                   '/^[[:space:]]*filter/{print ENVIRON["FILTER"];next} \
+                    /^[[:space:]]*scan/{print "scan = [ \"" DEV "\" ]";next} \
+                    /^[[:space:]]*cache_dir/{print "cache_dir = \"" CACHE "\"";next} \
+                    {print $0}' < ${LVMCONF} > ${TMP_LVM_SYSTEM_DIR}/lvm.conf

What if lvm.conf imports other config files?
We can only ever accept config *directories* as arguments, for that reason. Better to use 'dumpconfig' I reckon if the intent is to replicate existing configuration then change a few values.

Quoted 1 line

+"${LVM}" pvscan

Use vgscan not pvscan.

Quoted 1 line

+"${LVM}" vgmknodes

That's a built-in option to vgscan.

Alasdair

#2 lore raw
Quoted 3 lines · Alasdair G Kergon
Quoted 2 lines · Mike Snitzer

Revised vgimportclone that should be ready for inclussion in the LVM2 tree.

I was certainly mistaken with that statement :)

I'll sort out all of your comments and repost.

Quoted 5 lines
Quoted 1 line

+ exec 2> ./${SCRIPTNAME}.log

Errr ./ ??? What directory are we in and what file might we be clobbering? (Security blocker.) Better to retain output from earlier runs too and ensure there's a timestamp of the run somewhere (cf. lvmdump).

Yes, this DEBUG functionality is not safe at all; not sure how I missed this.

Mike