Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 4 additions & 46 deletions share/github-backup-utils/ghe-backup-repositories-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -84,68 +84,26 @@ echo "$config" > "$config_file"

opts="$GHE_EXTRA_SSH_OPTS -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no"

# Remote sync-in-progress file location. When this file exists, Git GC
# operations are disabled on the GitHub instance.
sync_in_progress_file="$GHE_REMOTE_DATA_USER_DIR/repositories/.sync_in_progress"

# Make sure root backup dir exists if this is the first run
mkdir -p "$backup_dir"

# Removes the remote sync-in-progress file on exit, re-enabling GC operations
# on the remote instance.
cleanup() {
# Enable remote GC operations
for hostname in $hostnames; do
ghe-ssh -F $config_file "$hostname:$port" -- "sudo rm -f '$sync_in_progress_file'"
ghe-gc-enable -F $config_file $hostname:$port
done
rm -f $config_file
}
trap 'cleanup' EXIT
trap 'exit $?' INT # ^C always terminate

wait_pids=""
# Disable remote GC operations
for hostname in $hostnames; do
# Touch the sync-in-progress file, disabling GC operations, and wait for all
# active GC processes to finish on the remote side.
echo "
set -e
sudo -u git touch '$sync_in_progress_file'

sanity=0
while [ \$sanity -lt $GHE_GIT_COOLDOWN_PERIOD ]; do
# note: the bracket synta[x] below is to prevent matches against the
# grep process itself.
if ps axo args | grep -E -e '^git( -.*)? nw-repac[k]( |$)' -e '^git( -.*)? g[c]( |$)' >/dev/null; then
sleep 1
sanity=\$(( sanity + 1 ))
else
exit 0
fi
done
exit 7
" | ssh -q $opts -p $port -F $config_file -l $user $hostname -- /bin/sh
wait_pids="$wait_pids $hostname:$!"
done

# strip leading space
wait_pids="$(echo -e "${wait_pids}" | sed -e 's/^[[:space:]]*//')"

# wait for jobs one by one, bail on the first one
for pid in $wait_pids; do
# pull out pid:hostname pairs into vars
wait_hostname="$(echo $pid | awk 'BEGIN {FS = ":" }; { print $1; }')"
wait_pid="$(echo $pid | awk 'BEGIN {FS = ":" }; { print $2; }')"
wait $wait_pid || {
res=$?
if [ $res = 7 ]; then
echo "Error: Git GC processes remain after $GHE_GIT_COOLDOWN_PERIOD seconds on host: $wait_hostname. Aborting..." 1>&2
fi
exit $res
}
unset wait_hostname wait_pid
ghe-gc-disable -F $config_file $hostname:$port
done

unset wait_pids

# If we have a previous increment, avoid transferring existing files via rsync's
# --link-dest support. This also decreases physical space usage considerably.
if [ -d "$backup_current" ]; then
Expand Down
34 changes: 4 additions & 30 deletions share/github-backup-utils/ghe-backup-repositories-rsync
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,20 @@ fi
# Perform a host-check and establish GHE_REMOTE_XXX variables.
ghe_remote_version_required "$host"

# Remote sync-in-progress file location. When this file exists, Git GC
# operations are disabled on the GitHub instance.
sync_in_progress_file="$GHE_REMOTE_DATA_USER_DIR/repositories/.sync_in_progress"

# Make sure root backup dir exists if this is the first run
mkdir -p "$backup_dir"

# Removes the remote sync-in-progress file on exit, re-enabling GC operations
# on the remote instance.
cleanup() {
ghe-ssh "$host" -- "sudo rm -f '$sync_in_progress_file'"
# Enable remote GC operations
ghe-gc-enable $host
}
trap 'cleanup' EXIT
trap 'exit $?' INT # ^C always terminate

# Touch the sync-in-progress file, disabling GC operations, and wait for all
# active GC processes to finish on the remote side.
echo "
set -e
sudo -u git touch '$sync_in_progress_file'

sanity=0
while [ \$sanity -lt $GHE_GIT_COOLDOWN_PERIOD ]; do
# note: the bracket synta[x] below is to prevent matches against the
# grep process itself.
if ps axo args | grep -E -e '^git( -.*)? nw-repac[k]( |$)' -e '^git( -.*)? g[c]( |$)' >/dev/null; then
sleep 1
sanity=\$(( sanity + 1 ))
else
exit 0
fi
done
exit 7
" | ghe-ssh "$host" -- /bin/sh || {
res=$?
if [ $res = 7 ]; then
echo "Error: Git GC processes remain after $GHE_GIT_COOLDOWN_PERIOD seconds. Aborting..." 1>&2
fi
exit $res
}
# Disable remote GC operations
ghe-gc-disable $host

# Transfer repository data from a GitHub instance to the current snapshot
# directory, using a previous snapshot to avoid transferring files that have
Expand Down