Skip to content

Instantly share code, notes, and snippets.

@grmontesino
Created February 5, 2022 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grmontesino/8ec29cd16cf3d893dde808f35f079304 to your computer and use it in GitHub Desktop.
Save grmontesino/8ec29cd16cf3d893dde808f35f079304 to your computer and use it in GitHub Desktop.
Incremental pvmove
#! /bin/bash
####
# pvmove data in configurables sized extents amount
# More info about motivation and concept in
# https://grmontesino.blogspot.com/2022/02/incremental-pvmove.html
#
# Usage: incremental_pvmove.sh <LV> <Origin PV> <Dest. PV> []
####
LV="$1"
ORIG_PV="$2"
DEST_PV="$3"
EXTENTS="${4:-25000}"
START=$(lvs --noheadings -ao devices $LV | grep -oP "$ORIG_PV\(\K\d+(?=\))")
while true; do
SIZE=$(lvs --noheadings --separator "|" -ao devices,seg_size_pe $LV \
| grep "$ORIG_PV" | head -1 | cut -d"|" -f2)
[ ${SIZE:=0} -gt $EXTENTS ] || EXTENTS=$SIZE
if [ $EXTENTS -le 0 ]; then
echo "* Finished!"
break
fi
echo "* pvmove ${ORIG_PV}:${START}+${EXTENTS} $DEST_PV"
pvmove ${ORIG_PV}:${START}+${EXTENTS} $DEST_PV
START=$((START+EXTENTS))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment