feat: add rscp function for rsyncing files to NAS datasets
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
function rscp
|
||||
if test (count $argv) -lt 2
|
||||
echo "Usage: rscp SOURCE DESTINATION"
|
||||
return 1
|
||||
end
|
||||
|
||||
if not command -q rsync
|
||||
echo "rscp: 'rsync' is not installed. Install it via your package manager."
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l src $argv[1]
|
||||
set -l dst $argv[2]
|
||||
|
||||
# Mount <-> NAS dataset mapping (keep both lists in the same order)
|
||||
set -l mounts /home/honney/mount/Media /home/honney/mount/Data /home/honney/mount/Ripping /home/honney/mount/Apps
|
||||
set -l remotes NAS:/mnt/tank/Media NAS:/mnt/tank/Data NAS:/mnt/tank/Ripping NAS:/mnt/tank/Apps
|
||||
|
||||
set -l src_remote 0
|
||||
set -l dst_remote 0
|
||||
|
||||
for i in (seq (count $mounts))
|
||||
if string match -q -- $mounts[$i] $src; or string match -q -- "$mounts[$i]/*" $src
|
||||
set src (string replace -f -- $mounts[$i] $remotes[$i] -- $src)
|
||||
set src_remote 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
for i in (seq (count $mounts))
|
||||
if string match -q -- $mounts[$i] $dst; or string match -q -- "$mounts[$i]/*" $dst
|
||||
set dst (string replace -f -- $mounts[$i] $remotes[$i] -- $dst)
|
||||
set dst_remote 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if test $src_remote -eq 0 -a $dst_remote -eq 0
|
||||
echo "cp -av -- $src $dst"
|
||||
command cp -av -- $src $dst
|
||||
return $status
|
||||
end
|
||||
|
||||
# --no-perms: required - TrueNAS ZFS datasets use SMB ACLs and reject unix perms preservation
|
||||
set -l opts -avh --no-perms --info=progress2 --partial
|
||||
if test $dst_remote -eq 1
|
||||
set -a opts --rsync-path="sudo -n rsync" --chown=1000:0
|
||||
end
|
||||
if test $src_remote -eq 1
|
||||
set -a opts --rsync-path="sudo -n rsync"
|
||||
end
|
||||
|
||||
echo rsync $opts -- $src $dst
|
||||
command rsync $opts -- $src $dst
|
||||
end
|
||||
Reference in New Issue
Block a user