chiark / gitweb /
do not placate -Wpointer-sign
[chiark-utils.git] / backup / remountrocp
index 5e40cc37cc72976d5a7d827a9830de1f0f296683..04ddd270afff6e73356009a0b28561155543bead 100755 (executable)
@@ -35,7 +35,7 @@ if [ -z "$lvm_lvsize_opts" ]; then
 
        df_out="$(really df -P --block-size=$extsize $mountpoint)"
        extents2="$(printf "%s" "$df_out" | awk '/^\// {print $3}')"
-       extents2=$(( ($extents2*150+99)/100 + 4 ))
+       extents2=$(( ($extents2*150+102399)/102400 + 4 ))
 
        lvmextentscore2
 fi
@@ -55,13 +55,26 @@ lvcreate \
        $vgroup \
        $lvm_lvcreate_args
 
-mkfs -t $remountrocp_fs "$lvpath"
+mkfs -t $remountrocp_fs -q "$lvpath"
+
 mkdir -- "$snmnt"
 mount -t $remountrocp_fs $lvm_mount_opts "$lvpath" "$snmnt"
+echo ' copy filesystem created and mounted'
 
-mount -o remount,ro "$mountpoint"
-trap "mount -o remount,rw $mountpoint; exit 12" 0
-cp -a -- "$mountpoint/." "$snmnt/."
+attempts=10
+while true; do
+       if mount -o remount,ro "$mountpoint"; then break; fi
+       attempts=$(( $attempts - 1 ))
+       if [ $attempts = 0 ]; then
+               echo >&2 'cannot remount readonly'
+               exit 1
+       fi
+       sleep 1
+done
+trap "set +e; mount -o remount,rw $mountpoint; exit 12" 0
+echo ' source remounted readonly, copying...'
+cp -ax -- "$mountpoint/." "$snmnt/."
+echo ' finalising...'
 mount -o remount,rw "$mountpoint"
 trap '' 0
 mount -o remount,ro "$lvpath"