Ass ability to move all datasets
This commit is contained in:
+10
-9
@@ -5,13 +5,13 @@ set -Eeuo pipefail
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: zfs-move-over-ssh.sh [options] SOURCE_ROOT REMOTE_HOST DESTINATION_ROOT
|
||||
Usage: zfs-move-over-ssh.sh [options] SOURCE_POOL REMOTE_HOST DESTINATION_ROOT
|
||||
|
||||
Create one snapshot for every filesystem under SOURCE_ROOT and send each one
|
||||
over SSH. Filesystems retain their relative paths below DESTINATION_ROOT.
|
||||
Create one snapshot for every filesystem in SOURCE_POOL and send each one over
|
||||
SSH. Filesystems retain their relative paths below DESTINATION_ROOT.
|
||||
|
||||
Arguments:
|
||||
SOURCE_ROOT Source ZFS filesystem, for example: tank/data
|
||||
SOURCE_POOL Source ZFS pool, for example: tank
|
||||
REMOTE_HOST SSH host, optionally user@host
|
||||
DESTINATION_ROOT Existing or new destination ZFS filesystem, for example: backup/data
|
||||
|
||||
@@ -77,14 +77,15 @@ done
|
||||
exit 2
|
||||
}
|
||||
|
||||
SOURCE_ROOT="$1"
|
||||
SOURCE_POOL="$1"
|
||||
REMOTE_HOST="$2"
|
||||
DESTINATION_ROOT="${3%/}"
|
||||
SNAPSHOT_NAME="move-$(date +%Y%m%d-%H%M%S)"
|
||||
|
||||
command -v zfs >/dev/null || die "zfs command was not found"
|
||||
command -v zpool >/dev/null || die "zpool command was not found"
|
||||
command -v ssh >/dev/null || die "ssh command was not found"
|
||||
zfs list -H -o name -t filesystem "$SOURCE_ROOT" >/dev/null || die "source filesystem does not exist: $SOURCE_ROOT"
|
||||
zpool list -H -o name "$SOURCE_POOL" >/dev/null || die "source pool does not exist: $SOURCE_POOL"
|
||||
|
||||
if ! $DRY_RUN; then
|
||||
ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" 'sudo -n zfs list -H -o name -t filesystem >/dev/null' \
|
||||
@@ -93,7 +94,7 @@ fi
|
||||
|
||||
map_destination() {
|
||||
local filesystem="$1"
|
||||
local relative_path="${filesystem#"$SOURCE_ROOT"}"
|
||||
local relative_path="${filesystem#"$SOURCE_POOL"}"
|
||||
printf '%s%s\n' "$DESTINATION_ROOT" "$relative_path"
|
||||
}
|
||||
|
||||
@@ -107,8 +108,8 @@ run() {
|
||||
fi
|
||||
}
|
||||
|
||||
mapfile -t FILESYSTEMS < <(zfs list -H -o name -t filesystem -r "$SOURCE_ROOT")
|
||||
((${#FILESYSTEMS[@]} > 0)) || die "no filesystems found below $SOURCE_ROOT"
|
||||
mapfile -t FILESYSTEMS < <(zfs list -H -o name -t filesystem -r "$SOURCE_POOL")
|
||||
((${#FILESYSTEMS[@]} > 0)) || die "no filesystems found in $SOURCE_POOL"
|
||||
|
||||
printf 'Migration snapshot: %s\n' "$SNAPSHOT_NAME"
|
||||
for filesystem in "${FILESYSTEMS[@]}"; do
|
||||
|
||||
Reference in New Issue
Block a user