Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/fzfs @ 424:a200c18603c9
Further work on "fzfs copy-tree"
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 20 Sep 2023 09:31:26 +0200 |
| parents | 1d6ee78f06ef |
| children | 2cd4777821fc |
comparison
equal
deleted
inserted
replaced
| 423:1d6ee78f06ef | 424:a200c18603c9 |
|---|---|
| 256 #: | 256 #: |
| 257 command_copy_tree() { | 257 command_copy_tree() { |
| 258 local _ds_source _ds_target | 258 local _ds_source _ds_target |
| 259 local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_dry_run | 259 local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_dry_run |
| 260 | 260 |
| 261 local _ds_source_base _ds_source_snapshot | 261 local _ds_source_base _ds_source_snapshot _snapshot_suffix |
| 262 local _ds_tree _ds _ds_relname | |
| 263 | |
| 264 _opt_mountpoint="" | |
| 265 _opt_mount_noauto="" | |
| 266 _opt_nomount="" | |
| 267 _opt_dry_run="" | |
| 262 | 268 |
| 263 while getopts "AM:nu" _opt ; do | 269 while getopts "AM:nu" _opt ; do |
| 264 case ${_opt} in | 270 case ${_opt} in |
| 265 A) | 271 A) |
| 266 _opt_mount_noauto="-o canmount=noauto" | 272 _opt_mount_noauto="-o canmount=noauto" |
| 286 _ds_target="${2-}" | 292 _ds_target="${2-}" |
| 287 | 293 |
| 288 [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; } | 294 [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; } |
| 289 [ -z "${_ds_target}" ] && { echo "ERROR: no target name given" 1>&2; return 2; } | 295 [ -z "${_ds_target}" ] && { echo "ERROR: no target name given" 1>&2; return 2; } |
| 290 | 296 |
| 297 if ! zfs get -H name "${_ds_source}" >/dev/null 2>&1; then | |
| 298 echo "ERROR: source dataset does not exist: ${_ds_source}" 1>&2; | |
| 299 return 1; | |
| 300 fi | |
| 301 | |
| 291 _ds_source_base="${_ds_source%@*}" | 302 _ds_source_base="${_ds_source%@*}" |
| 292 _ds_source_snapshot="${_ds_source##*@}" | 303 _ds_source_snapshot="${_ds_source##*@}" |
| 304 _snapshot_suffix="@${_ds_source_snapshot}" | |
| 293 | 305 |
| 294 if [ "${_ds_source_snapshot}" = "${_ds_source_base}" ]; then | 306 if [ "${_ds_source_snapshot}" = "${_ds_source_base}" ]; then |
| 295 # No snapshot given | 307 # No snapshot given |
| 308 [ "${_ds_source_base}" = "${_ds_source}" ] || { echo "ERROR:" 1>&2; return 1; } | |
| 296 _ds_source_snapshot="" | 309 _ds_source_snapshot="" |
| 310 _snapshot_suffix="" | |
| 297 fi | 311 fi |
| 312 | |
| 313 echo $_ds_source_base | |
| 314 echo $_ds_source_snapshot $_snapshot_suffix | |
| 315 | |
| 316 _ds_tree="" | |
| 317 | |
| 318 while IFS=$'\n' read -r _ds; do | |
| 319 if [ -z "${_ds_tree}" ]; then | |
| 320 _ds_tree="${_ds}" | |
| 321 else | |
| 322 _ds_tree="${_ds_tree}"$'\n'"${_ds}" | |
| 323 fi | |
| 324 echo "X: $_ds" | |
| 325 done <<EOF20ee7ea0781414fab8c305d3875d15e | |
| 326 $(zfs list -H -r -t filesystem -o name -s name "${_ds_source_base}") | |
| 327 EOF20ee7ea0781414fab8c305d3875d15e | |
| 328 # Check the existence of all intermediate datasets and their shapshots | |
| 329 IFS=$'\n' | |
| 330 for _ds in ${_ds_tree}; do | |
| 331 if ! zfs get -H name "${_ds}${_snapshot_suffix}" >/dev/null 2>&1; then | |
| 332 echo "ERROR: child dataset does not exist: ${_ds}${_snapshot_suffix}" 1>&2 | |
| 333 return 1 | |
| 334 fi | |
| 335 done | |
| 336 for _ds in ${_ds_tree}; do | |
| 337 # Determine the relative name of the dataset | |
| 338 _ds_relname="${_ds#${_ds_source_base}}" | |
| 339 echo "REL: $_ds --- $_ds_relname" | |
| 340 | |
| 341 if [ -z "${_ds_relname}" ]; then | |
| 342 # | |
| 343 # Source root to target root | |
| 344 # | |
| 345 if [ -z "${_opt_mountpoint}" ]; then | |
| 346 else | |
| 347 fi | |
| 348 else | |
| 349 if [ -z "${_opt_mountpoint}" ]; then | |
| 350 else | |
| 351 fi | |
| 352 fi | |
| 353 done | |
| 298 } | 354 } |
| 299 | 355 |
| 300 | 356 |
| 301 #: | 357 #: |
| 302 #: Implement the "create-tree" command | 358 #: Implement the "create-tree" command |
