Ass ability to move all datasets

This commit is contained in:
2026-09-01 23:59:40 +03:00
parent 2ce4afdfdd
commit b98d7877fc
2 changed files with 20 additions and 18 deletions
+10 -9
View File
@@ -1,7 +1,8 @@
# ZFS Move Over SSH # ZFS Move Over SSH
`zfs-move-over-ssh.sh` snapshots every ZFS filesystem at and beneath a source `zfs-move-over-ssh.sh` snapshots every ZFS filesystem in a source pool, then
dataset, then sends each snapshot to a remote ZFS server over SSH. sends each snapshot to a remote ZFS server over SSH. A vdev is the underlying
storage device; ZFS filesystems belong to a pool, so pass the pool name.
For a source tree such as: For a source tree such as:
@@ -36,13 +37,13 @@ incremental sends or resume tokens.
## Usage ## Usage
```bash ```bash
bash zfs-move-over-ssh.sh [options] SOURCE_ROOT REMOTE_HOST DESTINATION_ROOT bash zfs-move-over-ssh.sh [options] SOURCE_POOL REMOTE_HOST DESTINATION_ROOT
``` ```
Example: Example:
```bash ```bash
bash zfs-move-over-ssh.sh tank/data root@new-server backup/data bash zfs-move-over-ssh.sh tank root@new-server backup/tank
``` ```
Use a non-standard SSH key or port when needed: Use a non-standard SSH key or port when needed:
@@ -51,7 +52,7 @@ Use a non-standard SSH key or port when needed:
bash zfs-move-over-ssh.sh \ bash zfs-move-over-ssh.sh \
--identity-file ~/.ssh/zfs-migration \ --identity-file ~/.ssh/zfs-migration \
--ssh-port 2222 \ --ssh-port 2222 \
tank/data admin@new-server backup/data tank admin@new-server backup/tank
``` ```
Options: Options:
@@ -69,7 +70,7 @@ Options:
1. Confirm the source datasets: 1. Confirm the source datasets:
```bash ```bash
zfs list -r tank/data zfs list -r tank
``` ```
2. Confirm remote privileged ZFS access: 2. Confirm remote privileged ZFS access:
@@ -81,19 +82,19 @@ Options:
3. Preview the operation. Review every destination name in the output: 3. Preview the operation. Review every destination name in the output:
```bash ```bash
bash zfs-move-over-ssh.sh --dry-run tank/data admin@new-server backup/data bash zfs-move-over-ssh.sh --dry-run tank admin@new-server backup/tank
``` ```
4. Run the migration: 4. Run the migration:
```bash ```bash
bash zfs-move-over-ssh.sh tank/data admin@new-server backup/data bash zfs-move-over-ssh.sh tank admin@new-server backup/tank
``` ```
5. Verify the received datasets and data before retiring the source: 5. Verify the received datasets and data before retiring the source:
```bash ```bash
ssh admin@new-server 'sudo zfs list -r backup/data' ssh admin@new-server 'sudo zfs list -r backup/tank'
``` ```
## Safety and Recovery ## Safety and Recovery
+10 -9
View File
@@ -5,13 +5,13 @@ set -Eeuo pipefail
usage() { usage() {
cat <<'EOF' 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 Create one snapshot for every filesystem in SOURCE_POOL and send each one over
over SSH. Filesystems retain their relative paths below DESTINATION_ROOT. SSH. Filesystems retain their relative paths below DESTINATION_ROOT.
Arguments: 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 REMOTE_HOST SSH host, optionally user@host
DESTINATION_ROOT Existing or new destination ZFS filesystem, for example: backup/data DESTINATION_ROOT Existing or new destination ZFS filesystem, for example: backup/data
@@ -77,14 +77,15 @@ done
exit 2 exit 2
} }
SOURCE_ROOT="$1" SOURCE_POOL="$1"
REMOTE_HOST="$2" REMOTE_HOST="$2"
DESTINATION_ROOT="${3%/}" DESTINATION_ROOT="${3%/}"
SNAPSHOT_NAME="move-$(date +%Y%m%d-%H%M%S)" SNAPSHOT_NAME="move-$(date +%Y%m%d-%H%M%S)"
command -v zfs >/dev/null || die "zfs command was not found" 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" 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 if ! $DRY_RUN; then
ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" 'sudo -n zfs list -H -o name -t filesystem >/dev/null' \ ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" 'sudo -n zfs list -H -o name -t filesystem >/dev/null' \
@@ -93,7 +94,7 @@ fi
map_destination() { map_destination() {
local filesystem="$1" local filesystem="$1"
local relative_path="${filesystem#"$SOURCE_ROOT"}" local relative_path="${filesystem#"$SOURCE_POOL"}"
printf '%s%s\n' "$DESTINATION_ROOT" "$relative_path" printf '%s%s\n' "$DESTINATION_ROOT" "$relative_path"
} }
@@ -107,8 +108,8 @@ run() {
fi fi
} }
mapfile -t FILESYSTEMS < <(zfs list -H -o name -t filesystem -r "$SOURCE_ROOT") mapfile -t FILESYSTEMS < <(zfs list -H -o name -t filesystem -r "$SOURCE_POOL")
((${#FILESYSTEMS[@]} > 0)) || die "no filesystems found below $SOURCE_ROOT" ((${#FILESYSTEMS[@]} > 0)) || die "no filesystems found in $SOURCE_POOL"
printf 'Migration snapshot: %s\n' "$SNAPSHOT_NAME" printf 'Migration snapshot: %s\n' "$SNAPSHOT_NAME"
for filesystem in "${FILESYSTEMS[@]}"; do for filesystem in "${FILESYSTEMS[@]}"; do