scripts/misc-scripts/migrate-rbd.sh

33 lines
758 B
Bash
Raw Normal View History

2023-08-31 17:55:25 +00:00
#!/bin/sh
#
# Don't use this script, just use rbd migrate X, this doesn't persist any snapshots
sourcepool="$1"
destpool="$2"
destdatapool="${3:-$destpool}"
snapname="${4:-premigrate}"
checkdep() {
if ! which "$1" >/dev/null; then
echo "Missing $1 support"
exit 1
fi
}
checkdep "rbd"
checkdep "jq"
for img in $(rbd -p "$sourcepool" ls); do
if ! rbd -p "$sourcepool" status --format json "$img" | jq -e '.watchers[]'; then
echo "Migrating $img"
if rbd -p "$sourcepool" snap add "$img"@"$snapname"; then
rbd -p "$sourcepool" --dest-pool "$2" --data-pool "$3" clone "$img"@"$snapname" "$img"
rbd -p "$destpool" flatten "$img"
# Cleanup
rbd -p "$sourcepool" snap rm "$img"@"$snapname"
#rbd -p "$sourcepool" rm "$img"
fi
fi
done