chiark / gitweb /
remountrocp
authorianmdlvl <ianmdlvl>
Sun, 23 Jul 2006 17:07:19 +0000 (17:07 +0000)
committerianmdlvl <ianmdlvl>
Sun, 23 Jul 2006 17:07:19 +0000 (17:07 +0000)
backup/examples/chiark/settings.sh
backup/lvm
backup/remountrocp [new file with mode: 0755]
backup/snap-common [new file with mode: 0644]
debian/changelog

index e7ac2dc..d8b8713 100755 (executable)
@@ -1,7 +1,10 @@
 # shell script fragment setting options
 # defaults for currently implemented parameters are
+lvm_vg=vg_main
 #lvm_lv=chiark_backup
-#lvm_lvsize_opts=-l <min(no. of free extents in vg, 1.1x total lv size)>
+#lvm_lvsize_opts=
+# -l <min(no. of free extents in vg, 1.1x total lv size)> (lvm)
+# -l <min(no. of free extents in vg, 1.5x total space used)> (remountrocp)
 #lvm_lvtools_opts='-A n'
 #lvm_lvcreate_opts=
 #lvm_lvcreate_args=
index 5389e7b..3d8be29 100755 (executable)
@@ -6,51 +6,12 @@
 #    lvm drop $vardir
 
 set -e
-
-nargs=$#
-opmode="$1"
-vardir="$2"
-device="$3"
-mountpoint="$4"
-
-lvm_lv=chiark-backup
-lvm_lvtools_opts='-A n'
-lvm_lvcreate_opts=
-lvm_lvcreate_args=
-
-test ! -f /etc/chiark-backup/settings.sh || . /etc/chiark-backup/settings.sh
-
-case "$nargs.$opmode" in
-4.snap|2.drop)
-       ;;
-*)
-       cat >&2 <<'END'
-usage: .../lvm snap VARDIR DEV MOUNT
-       .../lvm drop VARDIR
-END
-       exit 1
-       ;;
-esac
-
+snapkind=lvm
+. /usr/share/chiark-backup/snap-common
 
 #---------- clean up anything
 
-snmnt="$vardir/snap-mount"
-umount -v "$snmnt" || true
-test ! -d "$snmnt" || rmdir -- "$snmnt"
-
-set +e
-old_lv_dev="$(readlink $vardir/snap-device)"
-rc=$?
-set -e
-
-if [ $rc = 0 ]; then
-       set +e
-       lvchange    $lvm_lvtools_opts -a n $old_lv_dev
-       lvremove -f $lvm_lvtools_opts      $old_lv_dev
-       set -e
-       rm $vardir/snap-device
-fi
+lvmdropcore
 
 if test "$opmode" = drop; then
        echo 'lvm snap dropped'
@@ -63,25 +24,19 @@ fstype="$(mount | sed -n \
  "s,^$device on $mountpoint type \([a-z0-9][a-z0-9]*\) .*,-t \1 ,p")"
 
 if [ -z "$lvm_lvsize_opts" ]; then
-       vggroup="${device#/dev/}"
-       vggroup="${vggroup%/*}"
-       vgdisplay_out="$(really vgdisplay -c "$vggroup")"
-       extents="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $16}')"
+       vgroup="${device#/dev/}"
+       vgroup="${vgroup%/*}"
+       lvmextentscore1
 
        lvdisplay_out="$(really lvdisplay -c "$device")"
        extents2="$(printf "%s" "$lvdisplay_out" | awk -F: '{print $9}')"
        extents2=$(( $extents2 + ($extents2+9)/10 - 1 ))
 
-       if [ $extents2 -lt $extents ]; then extents=$extents2; fi
-
-       lvm_lvsize_opts="-l $extents"
+       lvmextentscore2
 fi
 
-lvpath="$(dirname "$device")/$lvm_lv"
-
-ln -s -- "$lvpath" "$vardir"/snap-device
+lvmcreatecore1
 
-sync
 lvcreate -s \
        $lvm_lvtools_opts \
        $lvm_lvsize_opts \
diff --git a/backup/remountrocp b/backup/remountrocp
new file mode 100755 (executable)
index 0000000..5e40cc3
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash
+# invoked by backup scripts as
+#    remountrocp snap $vardir $device $mountpoint
+#              remounts $mountpoint readonly
+#              copies data to $vardir/snap-mount
+#              remounts $mountpoint readwrite
+#    remountrocp drop $vardir
+#              deletes $vardir/snap-mount
+
+set -e
+snapkind=remountrocp
+: ${lvm_vg:=}
+remountrocp_fs=ext2
+. ${CHIARK_BACKUP_SHAREDIR:-/usr/share/chiark-backup}/snap-common
+
+#---------- clean up anything
+
+vgroup=$lvm_vg
+lvmdropcore
+
+lastsettings="$vardir/remountrocp-settings"
+test ! -f $lastsettings || . $lastsettings
+
+if test "$opmode" = drop; then
+       test -z "$last_mountpoint" || mount -o remount,rw $last_mountpoint
+       rm -f $lastsettings
+       echo 'remountrocp snap dropped'
+       exit 0
+fi
+
+#---------- create snapshot
+
+if [ -z "$lvm_lvsize_opts" ]; then
+       lvmextentscore1
+
+       df_out="$(really df -P --block-size=$extsize $mountpoint)"
+       extents2="$(printf "%s" "$df_out" | awk '/^\// {print $3}')"
+       extents2=$(( ($extents2*150+99)/100 + 4 ))
+
+       lvmextentscore2
+fi
+
+lvmcreatecore1
+
+cat >$lastsettings.new <<END
+last_mountpoint=$mountpoint
+END
+mv -f $lastsettings.new $lastsettings
+
+lvcreate \
+       $lvm_lvtools_opts \
+       $lvm_lvsize_opts \
+       -n $lvm_lv \
+       $lvm_lvcreate_opts \
+       $vgroup \
+       $lvm_lvcreate_args
+
+mkfs -t $remountrocp_fs "$lvpath"
+mkdir -- "$snmnt"
+mount -t $remountrocp_fs $lvm_mount_opts "$lvpath" "$snmnt"
+
+mount -o remount,ro "$mountpoint"
+trap "mount -o remount,rw $mountpoint; exit 12" 0
+cp -a -- "$mountpoint/." "$snmnt/."
+mount -o remount,rw "$mountpoint"
+trap '' 0
+mount -o remount,ro "$lvpath"
+
+echo 'remountrocp snap activated'
diff --git a/backup/snap-common b/backup/snap-common
new file mode 100644 (file)
index 0000000..c12bc6d
--- /dev/null
@@ -0,0 +1,66 @@
+# sourced by snap/lvm and snap/remountrocp
+
+#---------- common arg parsing
+
+nargs=$#
+opmode="$1"
+vardir="$2"
+device="$3"
+mountpoint="$4"
+
+lvm_lv=chiark-backup
+lvm_lvtools_opts='-A n'
+lvm_lvcreate_opts=
+lvm_lvcreate_args=
+
+test ! -f /etc/chiark-backup/settings.sh || . /etc/chiark-backup/settings.sh
+
+case "$nargs.$opmode" in
+4.snap|2.drop)
+       ;;
+*)
+       cat >&2 <<END
+usage: .../$snapkind snap VARDIR DEV MOUNT
+       .../$snapkind drop VARDIR
+END
+       exit 1
+       ;;
+esac
+
+#---------- common functions
+
+lvmdropcore () {
+       snmnt="$vardir/snap-mount"
+       umount -v "$snmnt" || true
+       test ! -d "$snmnt" || rmdir -- "$snmnt"
+
+       set +e
+       old_lv_dev="$(readlink $vardir/snap-device)"
+       rc=$?
+       set -e
+
+       if [ $rc = 0 ]; then
+               set +e
+               lvchange    $lvm_lvtools_opts -a n $old_lv_dev
+               lvremove -f $lvm_lvtools_opts      $old_lv_dev
+               set -e
+               rm $vardir/snap-device
+       fi
+}
+
+lvmextentscore1 () {
+       vgdisplay_out="$(really vgdisplay -c "$vgroup")"
+       extents="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $16}')"
+       extsize="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $13}')"
+}
+
+lvmextentscore2 () {
+       if [ $extents2 -lt $extents ]; then extents=$extents2; fi
+       lvm_lvsize_opts="-l $extents"
+}
+
+lvmcreatecore1 () {
+       lvpath="/dev/$vgroup/$lvm_lv"
+       ln -s -- "$lvpath" "$vardir"/snap-device
+       sync
+}
index 82615ce..d38c6dc 100644 (file)
@@ -2,7 +2,7 @@ chiark-utils (4.1.1) unstable; urgency=low
 
   * summer sorts the output and identifies hardlink
     targets instead of printing link count.
-  
+  * backup: new `remountrocp' snapshot type.
 
  --