Skip to content

Commit 234d56f

Browse files
authored
Merge pull request #235 from github/git-hook-fixes
Git hooks backup fixes
2 parents e54abf8 + 4221efa commit 234d56f

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

bin/ghe-backup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
175175

176176
echo "Backing up custom Git hooks ..."
177177
ghe-backup-git-hooks-cluster ||
178-
failures="$failures alambic_assets"
178+
failures="$failures git-hooks"
179179
else
180180
echo "Backing up asset attachments ..."
181181
ghe-backup-userdata alambic_assets ||

share/github-backup-utils/ghe-backup-git-hooks-cluster

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ set -e
99
# Bring in the backup configuration
1010
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config
1111

12-
# Split host:port into parts
13-
port=$(ssh_port_part "$GHE_HOSTNAME")
14-
host=$(ssh_host_part "$GHE_HOSTNAME")
15-
16-
# Add user / -l option
17-
user="${host%@*}"
18-
[ "$user" = "$host" ] && user="admin"
19-
20-
backup_dir="$GHE_SNAPSHOT_DIR/git-hooks"
21-
22-
# Location of last good backup for rsync --link-dest
23-
backup_current="$GHE_DATA_DIR/current/git-hooks"
24-
2512
# Verify rsync is available.
2613
if ! rsync --version 1>/dev/null 2>&1; then
2714
echo "Error: rsync not found." 1>&2
2815
exit 1
2916
fi
3017

18+
bm_start "$(basename $0)"
19+
20+
backup_dir="$GHE_SNAPSHOT_DIR/git-hooks"
21+
# Location of last good backup for rsync --link-dest
22+
backup_current="$GHE_DATA_DIR/current/git-hooks"
23+
3124
# Perform a host-check and establish GHE_REMOTE_XXX variables.
3225
ghe_remote_version_required "$host"
3326

34-
# Generate SSH config for forwarding
27+
# Split host:port into parts
28+
port=$(ssh_port_part "$GHE_HOSTNAME")
29+
host=$(ssh_host_part "$GHE_HOSTNAME")
3530

31+
# Add user / -l option
32+
user="${host%@*}"
33+
[ "$user" = "$host" ] && user="admin"
34+
35+
# Generate SSH config for forwarding
3636
config=""
3737

3838
# git server hostnames
@@ -102,6 +102,16 @@ rsync_git_hooks_data () {
102102
}
103103

104104
hostname=$(echo $hostnames | awk '{ print $1; }')
105-
ghe-ssh -F $config_file "$hostname:122" -- "sudo -u git [ -d '$GHE_REMOTE_DATA_USER_DIR/git-hooks' ]" || exit 0
106-
rsync_git_hooks_data $hostname:122 environments/tarballs
107-
rsync_git_hooks_data $hostname:122 repos
105+
if ghe-ssh -F $config_file "$hostname:122" -- "sudo -u git [ -d '$GHE_REMOTE_DATA_USER_DIR/git-hooks/environments/tarballs' ]"; then
106+
rsync_git_hooks_data $hostname:122 environments/tarballs
107+
else
108+
ghe_verbose "git-hooks environment tarballs not found. Skipping ..."
109+
fi
110+
111+
if ghe-ssh -F $config_file "$hostname:122" -- "sudo -u git [ -d '$GHE_REMOTE_DATA_USER_DIR/git-hooks/repos' ]"; then
112+
rsync_git_hooks_data $hostname:122 repos
113+
else
114+
ghe_verbose "git-hooks repositories not found. Skipping ..."
115+
fi
116+
117+
bm_end "$(basename $0)"

0 commit comments

Comments
 (0)