add dir2subvol function to convert directory to subvolume

fix - bug in copy function where collected arguments were erased.
master
David Kebler 2024-10-17 11:24:08 -07:00
parent d5c89e284e
commit 263ba5296d
2 changed files with 45 additions and 14 deletions

View File

@ -250,7 +250,31 @@ alias btsub="sudo $BTRFS_BIN subvolume"
dir2subvol () {
# Directory to convert into BTRFS subvolume
dirPath="$1"
getfacl -R "$dirPath" > /tmp/_perms
# Rename original dierctory
sudo mv "${dirPath}" "${dirPath}_original"
# Create btrfs subvolume
sudo $BTRFS_BIN subvolume create "${dirPath}"
# Copy as "reflink" for speed and save space
sudo cp --archive --one-file-system --reflink=always \
"${dirPath}_original/." "${dirPath}"
# Remove old directory
sudo rm -rf --one-file-system "${dirPath}_original"
setfacl --restore=/tmp/_perms
rm -f /tmp/_perms
}

View File

@ -21,7 +21,7 @@ copy () {
cat <<EOF
usage:
rsync <script options> source destination <rsync options> --- <ssh options>
rsync <script options> source destination <rsync options> -- <ssh options>
Available Script Options
-r, run the command by this script uses --dry-run. When ready pass this flag.
@ -34,7 +34,7 @@ Available Script Options
-m, copy as "mirror" uses options. -a --numeric-ids --delete --force
-M, copy as "mirror" above -m plus '--delete-excluded' added. A perfect mirror
-f, rsync --exclude-from <path>, can have multiple
-F, copy a filesystem, uses -M mirror plus -xHAXS, and uses sudo (i.e. -s script option)
-F, copy a filesystem, uses -M and -m mirror plus -xHAXS, and uses sudo (i.e. -s script option)
-n, no confirm, will always confirm command unless this is set
-q, quiet, suppress progress
-v, verbose, same as -v for rsync option, unset if -q is set
@ -43,6 +43,9 @@ Available Script Options
-C, show excludes for clean transfer
-h, this help text
ssh arguments may be added at the end after --. any option with multiple arguments
must be enclosed in literal double quotes, (.e.g) -o \"ProxyCommand nohup ssh firewall nc -w1 %h %p\"
source or destination may include a <host>: prefix but not both
use 'fcopy <src> <dest>' for fast copy uses -r -q -m -n -a
@ -85,9 +88,10 @@ EOF
;;
F)
args+=("-xHAXS")
args+=("--exclude-from=$COPY_MODULE_PATH/cache-trash-log.exc")
Mirror=true
mirror=true
usesudo=sudo
args+=("--exclude-from=$COPY_MODULE_PATH/cache-trash-log.exc")
;;
p)
args+=("--mkpath")
@ -128,12 +132,12 @@ EOF
shift $((OPTIND - 1))
[ $# -lt 2 ] && echo both a source and destination need to be passed && return 2
[ $# -lt 2 ] && ( echo Error: both a source and destination need to be passed; help; ) && return 1
# source parse
SRC=$1; shift
if [[ $SRC =~ ":" ]]; then
echo source is remote
# echo source is remote
SHOST=${SHOST:-$(sed 's/\(.*\):.*/\1/' <<< "$SRC")}
SPATH=$(sed 's/.*:\(.*\)/\1/' <<< "$SRC")
else
@ -172,24 +176,27 @@ EOF
[[ ! $SHOST ]] && SPATH=$(realpath $SPATH)
[[ ! $DHOST ]] && DPATH=$(realpath $DPATH)
debug $( ( IFS=$','; echo all arguments: "$*" ) )
# BASH_DEBUG="stdout"
debug $( ( IFS=$','; echo all remaining arguments: "$*" ) )
for ((d=1; d<$#+1; ++d)); do
# echo in loop $d, ${!d}
echo in loop $d, ${!d}
[[ ${!d} == "--" ]] && sargs=true && break
done
if [[ $sargs ]]; then # if there are extra ssh arguments
sshargs=("${@:$d+1:$#}")
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
args=("${@:1:$d-1}")
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
else
args=("${@:1}")
[[ $DHOST || $SHOST ]] && args+=( "$(remove_end_spaces "-e '$(ssh -l "${sshargs[*]}")'")")
fi
[[ $DHOST || $SHOST ]] && args+=( "$(remove_end_spaces "-e '$(ssh -l "${sshargs[*]}")'")")
# remove --
# args=+("${@:1:$d-1}")
# debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
# else
# echo again: ${args[*]}
# args=("${@:1}")
# assemble options
# assemble arguments from options
[[ ! $exec ]] && args+=(--dry-run -v)
[[ ! $quiet ]] && args+=(--info=progress2 $verbose)
[[ $mirror ]] && args+=(-a --numeric-ids --delete --force)