diff --git a/bin/ghe-backup b/bin/ghe-backup index 11c4f3308..f67b4dc71 100755 --- a/bin/ghe-backup +++ b/bin/ghe-backup @@ -81,6 +81,25 @@ if [ "$(ls -il dest1/testfile | awk '{ print $1 }')" != "$(ls -il dest2/testfile fi rm -rf src dest1 dest2 +# if we should use gitbackups to backup repositories +should_use_gitbackups_for_repositories(){ + ghe-ssh "$GHE_HOSTNAME" ghe-config --true "app.github.gitbackups" +} + +# check that the appliance supports using gitbackups for repositories +can_use_gitbackups_for_repositories(){ + ghe-ssh "$GHE_HOSTNAME" test -e /data/github/current/bin/backup-repositories +} + +# Exit early if the appliance is missing script to backup repositories using gitbackups +if should_use_gitbackups_for_repositories; then + if ! can_use_gitbackups_for_repositories; then + echo "Error: Configuration setting 'app.github.gitbackups' is enabled but this version of GHES cannot use gitbackups to back up repositories via 'ghe-backup'." + echo "Disable configuration setting 'app.github.gitbackups' and re-run 'ghe-backup' to use rsync." + exit 1 + fi +fi + # To prevent multiple backup runs happening at the same time, we create a # in-progress file with the timestamp and pid of the backup process, # giving us a form of locking. @@ -197,8 +216,13 @@ ghe-backup-audit-log || failures="$failures audit-log" echo "Backing up hookshot logs ..." ghe-backup-es-hookshot || failures="$failures hookshot" -echo "Backing up Git repositories ..." -ghe-backup-repositories || failures="$failures repositories" +if should_use_gitbackups_for_repositories && can_use_gitbackups_for_repositories; then + echo "Backing up Git repositories using gitbackups ..." + ghe-backup-repositories-gitbackups || failures="$failures repositories" +else + echo "Backing up Git repositories using rsync ..." + ghe-backup-repositories-rsync || failures="$failures repositories" +fi echo "Backing up GitHub Pages ..." ghe-backup-pages || failures="$failures pages" diff --git a/share/github-backup-utils/ghe-backup-repositories-gitbackups b/share/github-backup-utils/ghe-backup-repositories-gitbackups new file mode 100755 index 000000000..35c9c6472 --- /dev/null +++ b/share/github-backup-utils/ghe-backup-repositories-gitbackups @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +#/ Usage: ghe-backup-repositories-gitbackups +#/ Take an online, incremental snapshot of all Git repository data using gitbackups. +#/ +#/ Note: This command typically isn't called directly. It's invoked by +#/ ghe-backup. +set -e + +# Bring in the backup configuration +# shellcheck source=share/github-backup-utils/ghe-backup-config +. "$( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config" + +bm_start "$(basename $0)" + +echo "github-env ./bin/backup-repositories" | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash + +bm_end "$(basename $0)" diff --git a/share/github-backup-utils/ghe-backup-repositories b/share/github-backup-utils/ghe-backup-repositories-rsync similarity index 99% rename from share/github-backup-utils/ghe-backup-repositories rename to share/github-backup-utils/ghe-backup-repositories-rsync index 62feb8d22..e89484b01 100755 --- a/share/github-backup-utils/ghe-backup-repositories +++ b/share/github-backup-utils/ghe-backup-repositories-rsync @@ -1,6 +1,6 @@ #!/usr/bin/env bash -#/ Usage: ghe-backup-repositories -#/ Take an online, incremental snapshot of all Git repository data. +#/ Usage: ghe-backup-repositories-rsync +#/ Take an online, incremental snapshot of all Git repository data using rsync. #/ #/ Note: This command typically isn't called directly. It's invoked by #/ ghe-backup.