BigW Consortium Gitlab

parallel-rsync-repos 1.2 KB
Newer Older
1 2 3
#!/usr/bin/env bash
# this script should run as the 'git' user, not root, because 'root' should not
# own intermediate directories created by rsync.
4 5 6
#
# Example invocation:
# find /var/opt/gitlab/git-data/repositories -maxdepth 2 | \
7
#   parallel-rsync-repos transfer-success.log /var/opt/gitlab/git-data/repositories /mnt/gitlab/repositories
8 9 10
#
# You can also rsync to a remote destination.
#
11
# parallel-rsync-repos transfer-success.log /var/opt/gitlab/git-data/repositories user@host:/mnt/gitlab/repositories
12 13 14
#
# If you need to pass extra options to rsync, set the RSYNC variable
#
15
# env RSYNC='rsync --rsh="foo bar"' parallel-rsync-repos transfer-success.log /src dest
16
#
17

18 19 20
LOGFILE=$1
SRC=$2
DEST=$3
21

22 23 24
if [ -z "$LOGFILE" ] || [ -z "$SRC" ] || [ -z "$DEST" ] ; then
  echo "Usage: $0 LOGFILE SRC DEST"
  exit 1
25 26
fi

27 28
if [ -z "$JOBS" ] ; then
  JOBS=10
29 30
fi

31 32 33 34
if [ -z "$RSYNC" ] ; then
  RSYNC=rsync
fi

35 36 37 38 39
if ! cd $SRC ; then
  echo "cd $SRC failed"
  exit 1
fi

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
rsyncjob() {
  relative_dir="./${1#$SRC}"

  if ! $RSYNC --delete --relative -a "$relative_dir" "$DEST" ; then
    echo "rsync $1 failed"
    return 1
  fi

  echo "$1" >> $LOGFILE
}

export LOGFILE SRC DEST RSYNC
export -f rsyncjob

parallel -j$JOBS --progress rsyncjob