Add some more

This commit is contained in:
Alex D. 2023-08-31 17:55:25 +00:00
parent b3baccf927
commit eebcdd032b
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 50 additions and 0 deletions

18
btrfs-retention.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
#
# BTRFS rolling snapshots
# CC0 ~caskd
: ${SRC:?'Source not defined'}
: ${DEST:?'Destination not defined'}
: ${NAME:?'Name not defined'}
: ${SN:?'Selection name not defined'}
: ${RT:?'Retention time not defined'}
s="$SRC"
d="$DEST/$SN/$NAME"
mkdir -p "${d%/*}"
find "$DEST" -mindepth 1 -maxdepth 1 -type d -ctime +"$RT" -exec echo "{}/$NAME" ';' | xargs btrfs subvolume del
btrfs subvolume delete "$d"
btrfs subvolume snapshot -r "$s" "$d"

32
migrate-rbd.sh Executable file
View File

@ -0,0 +1,32 @@
#!/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