add dir2subvol function to convert directory to subvolume
fix - bug in copy function where collected arguments were erased.master
parent
d5c89e284e
commit
263ba5296d
|
@ -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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ copy () {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
rsync <script options> source destination <rsync options> --- <ssh options>
|
rsync <script options> source destination <rsync options> -- <ssh options>
|
||||||
|
|
||||||
Available Script Options
|
Available Script Options
|
||||||
-r, run the command by this script uses --dry-run. When ready pass this flag.
|
-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" uses options. -a --numeric-ids --delete --force
|
||||||
-M, copy as "mirror" above -m plus '--delete-excluded' added. A perfect mirror
|
-M, copy as "mirror" above -m plus '--delete-excluded' added. A perfect mirror
|
||||||
-f, rsync --exclude-from <path>, can have multiple
|
-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
|
-n, no confirm, will always confirm command unless this is set
|
||||||
-q, quiet, suppress progress
|
-q, quiet, suppress progress
|
||||||
-v, verbose, same as -v for rsync option, unset if -q is set
|
-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
|
-C, show excludes for clean transfer
|
||||||
-h, this help text
|
-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
|
source or destination may include a <host>: prefix but not both
|
||||||
|
|
||||||
use 'fcopy <src> <dest>' for fast copy uses -r -q -m -n -a
|
use 'fcopy <src> <dest>' for fast copy uses -r -q -m -n -a
|
||||||
|
@ -85,9 +88,10 @@ EOF
|
||||||
;;
|
;;
|
||||||
F)
|
F)
|
||||||
args+=("-xHAXS")
|
args+=("-xHAXS")
|
||||||
|
args+=("--exclude-from=$COPY_MODULE_PATH/cache-trash-log.exc")
|
||||||
|
Mirror=true
|
||||||
mirror=true
|
mirror=true
|
||||||
usesudo=sudo
|
usesudo=sudo
|
||||||
args+=("--exclude-from=$COPY_MODULE_PATH/cache-trash-log.exc")
|
|
||||||
;;
|
;;
|
||||||
p)
|
p)
|
||||||
args+=("--mkpath")
|
args+=("--mkpath")
|
||||||
|
@ -128,12 +132,12 @@ EOF
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
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
|
# source parse
|
||||||
SRC=$1; shift
|
SRC=$1; shift
|
||||||
if [[ $SRC =~ ":" ]]; then
|
if [[ $SRC =~ ":" ]]; then
|
||||||
echo source is remote
|
# echo source is remote
|
||||||
SHOST=${SHOST:-$(sed 's/\(.*\):.*/\1/' <<< "$SRC")}
|
SHOST=${SHOST:-$(sed 's/\(.*\):.*/\1/' <<< "$SRC")}
|
||||||
SPATH=$(sed 's/.*:\(.*\)/\1/' <<< "$SRC")
|
SPATH=$(sed 's/.*:\(.*\)/\1/' <<< "$SRC")
|
||||||
else
|
else
|
||||||
|
@ -172,24 +176,27 @@ EOF
|
||||||
[[ ! $SHOST ]] && SPATH=$(realpath $SPATH)
|
[[ ! $SHOST ]] && SPATH=$(realpath $SPATH)
|
||||||
[[ ! $DHOST ]] && DPATH=$(realpath $DPATH)
|
[[ ! $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
|
for ((d=1; d<$#+1; ++d)); do
|
||||||
# echo in loop $d, ${!d}
|
echo in loop $d, ${!d}
|
||||||
[[ ${!d} == "--" ]] && sargs=true && break
|
[[ ${!d} == "--" ]] && sargs=true && break
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $sargs ]]; then # if there are extra ssh arguments
|
if [[ $sargs ]]; then # if there are extra ssh arguments
|
||||||
sshargs=("${@:$d+1:$#}")
|
sshargs=("${@:$d+1:$#}")
|
||||||
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
|
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
|
||||||
args=("${@:1:$d-1}")
|
[[ $DHOST || $SHOST ]] && args+=( "$(remove_end_spaces "-e '$(ssh -l "${sshargs[*]}")'")")
|
||||||
debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
|
|
||||||
else
|
|
||||||
args=("${@:1}")
|
|
||||||
fi
|
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 arguments from options
|
||||||
# assemble options
|
|
||||||
[[ ! $exec ]] && args+=(--dry-run -v)
|
[[ ! $exec ]] && args+=(--dry-run -v)
|
||||||
[[ ! $quiet ]] && args+=(--info=progress2 $verbose)
|
[[ ! $quiet ]] && args+=(--info=progress2 $verbose)
|
||||||
[[ $mirror ]] && args+=(-a --numeric-ids --delete --force)
|
[[ $mirror ]] && args+=(-a --numeric-ids --delete --force)
|
||||||
|
|
Loading…
Reference in New Issue