Skip to content

Instantly share code, notes, and snippets.

@timmahoney
Last active October 17, 2017 18:45
Show Gist options
  • Save timmahoney/8c0e2ff1f415d8d4afe0 to your computer and use it in GitHub Desktop.
Save timmahoney/8c0e2ff1f415d8d4afe0 to your computer and use it in GitHub Desktop.
Parallel RSync
#!/bin/bash
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
exit 1
fi
# SETUP OPTIONS
export SRCDIR="$1"
export DESTDIR="$2"
export THREADS="4"
# RSYNC DIRECTORY STRUCTURE
rsync -zr -f"+ */" -f"- *" $SRCDIR/ $DESTDIR/
# FOLLOWING MAYBE FASTER BUT NOT AS FLEXIBLE
# cd $SRCDIR; find . -type d -print0 | cpio -0pdm $DESTDIR/
# FIND ALL FILES AND PASS THEM TO MULTIPLE RSYNC PROCESSES
cd $SRCDIR && find $SRCDIR ! -type d -printf "%f\n" | xargs -P$THREADS -I {} rsync -avz {} $DESTDIR/{}
# IF YOU WANT TO LIMIT THE IO PRIORITY, 
# PREPEND THE FOLLOWING TO THE rsync & cd/find COMMANDS ABOVE:
#   ionice -c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment