Skip to content

Instantly share code, notes, and snippets.

@liejuntao001
Last active June 9, 2023 06:25
Show Gist options
  • Save liejuntao001/bf33ded58416498dd61a9eaaea6d0c27 to your computer and use it in GitHub Desktop.
Save liejuntao001/bf33ded58416498dd61a9eaaea6d0c27 to your computer and use it in GitHub Desktop.
my rsync cheetsheet
# simple copy
rsync -axHAWXS /data/a/ /data/b/
# simple copy showing progress in terminal
rsync -axHAWXS --numeric-ids --info=progress2 /data/a/ /data/b/
# show copy stats at the end
rsync -axHAWXS --stats /data/a/ /data/b/
# copy folder excluding the "lost+found" directory
rsync -axHAWXS --exclude 'lost+found' --numeric-ids --info=progress2 /mnt/a/ /data/a/
# sync folder to exact same
rsync -axHAWXS --numeric-ids --info=progress2 --delete-after /mnt/a/ /data/a/
# after sync, verify the 2 dirs have all the same
rsync --recursive --delete --links --verbose --dry-run /mnt/a/ /data/a/
# rsync with remote sudo permission
rsync ... --rsync-path="sudo rsync" ...
# retry rsync automatically
while [ 1 ]
do
rsync --rsync-path="sudo rsync" -axHAWXS --exclude 'lost+found' --delete-after --numeric-ids --info=progress2 remote:/data/a/ /data/a/
if [ "$?" = "0" ] ; then
echo "rsync completed normally"
break
else
echo "Rsync failure. Backing off and retrying..."
sleep 60
fi
done
# resume rsync
# I'm running rsync over network with a proxy, and the proxy limit a session to 10Gb so a file larger than 10Gb need resume rsync
while [ 1 ]
do
rsync --rsync-path="sudo rsync" -axHAXS --append-verify --numeric-ids --info=progress2 remote:/data/a/my_large_file /data/a/
if [ "$?" = "0" ] ; then
echo "rsync completed normally"
break
else
echo "Rsync failure. Backing off and retrying..."
sleep 60
fi
done
# rsync between remote hosts
# host1/data1 -> host2/data2
# for all the .xz files in data1
eval `ssh-agent`
ssh-add
ssh -A -R localhost:50000:host2:22 host1 'rsync -e "ssh -p 50000" -axHAWXS --include="*.xz" --exclude="*" --numeric-ids --info=progress2 /data1/ localhost:/data2/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment