Skip to content

Instantly share code, notes, and snippets.

@dmp1ce
Last active February 6, 2022 03:41
Show Gist options
  • Save dmp1ce/5f51f798eee3806654f171e2b0272590 to your computer and use it in GitHub Desktop.
Save dmp1ce/5f51f798eee3806654f171e2b0272590 to your computer and use it in GitHub Desktop.
Move all ZFS child datasets to a new parent dataset
#!/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