comparison sbin/fzfs @ 429:bbdb1ab0ea00

Implement "-k" option for "fzfs copy-tree" to keep received snapshots
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 22 Sep 2023 09:22:25 +0200
parents 824e88618376
children 9c3b1966ba91
comparison
equal deleted inserted replaced
428:824e88618376 429:bbdb1ab0ea00
254 #: 254 #:
255 #: Implementation of "copy-tree" 255 #: Implementation of "copy-tree"
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_keep _opt_dry_run
260 260
261 local _ds_source_base _ds_source_snapshot _snapshot_suffix 261 local _ds_source_base _ds_source_snapshot _snapshot_suffix
262 local _ds_tree _ds _ds_relname _ds_canmount 262 local _ds_tree _ds _ds_relname _ds_canmount
263 local _arg_canmount _arg_mp1 _arg_mp2 263 local _arg_canmount _arg_mp1 _arg_mp2
264 264
265 _opt_mountpoint="" 265 _opt_mountpoint=""
266 _opt_mount_noauto="" 266 _opt_mount_noauto=""
267 _opt_nomount="" 267 _opt_nomount=""
268 _opt_keep=""
268 _opt_dry_run="" 269 _opt_dry_run=""
269 270
270 while getopts "AM:nu" _opt ; do 271 while getopts "AM:knu" _opt ; do
271 case ${_opt} in 272 case ${_opt} in
272 A) 273 A)
273 _opt_mount_noauto="-o canmount=noauto" 274 _opt_mount_noauto="-o canmount=noauto"
274 ;; 275 ;;
275 M) 276 M)
276 _opt_mountpoint="${OPTARG}" 277 _opt_mountpoint="${OPTARG}"
278 ;;
279 k)
280 _opt_keep="yes"
277 ;; 281 ;;
278 n) 282 n)
279 _opt_dry_run="-n" 283 _opt_dry_run="-n"
280 ;; 284 ;;
281 u) 285 u)
373 # for the loop 377 # for the loop
374 IFS=$'\n' 378 IFS=$'\n'
375 done 379 done
376 # Reset to default 380 # Reset to default
377 IFS=$' \t\n' 381 IFS=$' \t\n'
378 # Remove received snapshots 382 # Remove received snapshots by default
379 if [ -n "${_ds_source_snapshot}" ]; then 383 if [ -n "${_ds_source_snapshot}" ]; then
380 if [ -z "${_opt_dry_run}" ]; then 384 if [ -z "${_opt_keep}" ]; then
381 zfs destroy -rv "${_ds_target}${_snapshot_suffix}" 385 if [ -z "${_opt_dry_run}" ]; then
382 else 386 zfs destroy -rv "${_ds_target}${_snapshot_suffix}"
383 echo "Would execute: zfs destroy -rv '${_ds_target}${_snapshot_suffix}'" 387 else
388 echo "Would execute: zfs destroy -rv '${_ds_target}${_snapshot_suffix}'"
389 fi
384 fi 390 fi
385 fi 391 fi
386 } 392 }
387 393
388 394