2015-12-08 09:08:22 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# this script should run as the 'git' user, not root, because 'root' should not
|
|
|
|
# own intermediate directories created by rsync.
|
2015-09-25 12:31:54 -04:00
|
|
|
#
|
|
|
|
# Example invocation:
|
|
|
|
# find /var/opt/gitlab/git-data/repositories -maxdepth 2 | \
|
2015-12-08 09:08:22 -05:00
|
|
|
# parallel-rsync-repos transfer-success.log /var/opt/gitlab/git-data/repositories /mnt/gitlab/repositories
|
2015-10-05 12:02:12 -04:00
|
|
|
#
|
|
|
|
# You can also rsync to a remote destination.
|
|
|
|
#
|
2015-12-08 09:08:22 -05:00
|
|
|
# parallel-rsync-repos transfer-success.log /var/opt/gitlab/git-data/repositories user@host:/mnt/gitlab/repositories
|
2015-10-05 12:02:12 -04:00
|
|
|
#
|
|
|
|
# If you need to pass extra options to rsync, set the RSYNC variable
|
|
|
|
#
|
2015-12-08 09:08:22 -05:00
|
|
|
# env RSYNC='rsync --rsh="foo bar"' parallel-rsync-repos transfer-success.log /src dest
|
2015-10-05 12:02:12 -04:00
|
|
|
#
|
2015-09-25 12:31:54 -04:00
|
|
|
|
2015-12-08 09:08:22 -05:00
|
|
|
LOGFILE=$1
|
|
|
|
SRC=$2
|
|
|
|
DEST=$3
|
2015-09-25 12:31:54 -04:00
|
|
|
|
2015-12-08 09:08:22 -05:00
|
|
|
if [ -z "$LOGFILE" ] || [ -z "$SRC" ] || [ -z "$DEST" ] ; then
|
|
|
|
echo "Usage: $0 LOGFILE SRC DEST"
|
|
|
|
exit 1
|
2015-09-25 12:31:54 -04:00
|
|
|
fi
|
|
|
|
|
2015-12-08 09:08:22 -05:00
|
|
|
if [ -z "$JOBS" ] ; then
|
|
|
|
JOBS=10
|
2015-09-25 12:31:54 -04:00
|
|
|
fi
|
|
|
|
|
2015-10-05 12:02:12 -04:00
|
|
|
if [ -z "$RSYNC" ] ; then
|
|
|
|
RSYNC=rsync
|
|
|
|
fi
|
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
if ! cd $SRC ; then
|
2015-09-25 12:31:54 -04:00
|
|
|
echo "cd $SRC failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-12-08 09:08:22 -05:00
|
|
|
rsyncjob() {
|
2021-11-09 10:12:42 -05:00
|
|
|
relative_dir="./${1#$SRC}"
|
2015-12-08 09:08:22 -05:00
|
|
|
|
|
|
|
if ! $RSYNC --delete --relative -a "$relative_dir" "$DEST" ; then
|
|
|
|
echo "rsync $1 failed"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
echo "$1" >> $LOGFILE
|
2015-12-08 09:08:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export LOGFILE SRC DEST RSYNC
|
|
|
|
export -f rsyncjob
|
|
|
|
|
|
|
|
parallel -j$JOBS --progress rsyncjob
|