Last active
February 6, 2022 03:41
-
-
Save dmp1ce/5f51f798eee3806654f171e2b0272590 to your computer and use it in GitHub Desktop.
Move all ZFS child datasets to a new parent dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Move all ZFS child datasets to a new parent dataset | |
# See post about problematic Docker datasets: | |
# https://daveparrish.net/posts/2020-11-10-Managing-ZFS-Snapshots-ignore-Docker-snapshots.html | |
if [ ! $# -eq 2 ]; then | |
echo "Please supply a source and destination ZFS dataset as the first and second parameter" | |
echo "Example: ./move_zfs_child_datasets.bash zpool/ROOT/default zpool/docker" | |
exit; | |
fi | |
currentDatasetPath=$1 | |
newDatasetPath=$2 | |
currentDatasets=$(zfs list -H -t filesystem -d 1 -o name "$currentDatasetPath" | tail +2) | |
for dataset in $currentDatasets ; do | |
newDataset="$newDatasetPath/${dataset##*/}" | |
echo "Move $dataset to $newDataset" | |
sudo zfs rename "$dataset" "$newDataset" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment