Commit a3e3e5ad authored by Kirill Smelkov's avatar Kirill Smelkov

gitlab-backup/restore: Adjust hooks links to point to current gitlab-shell location

By design Gitlab currently symlinks *.git/hooks to hooks in gitlab-shell
working tree. As when restoring backup on different machine gitlab-shell
worktree can be located in another place, all hooks needs to be adjusted
upon restoration.

Btw, Gitlab itself does the same:

    https://gitlab.com/gitlab-org/gitlab-ce/blob/7383453b/lib/backup/repository.rb#L103
    https://gitlab.com/gitlab-org/gitlab-ce/commit/1d03fa2e

/cc @kazuhiko
parent c8ac2f3a
...@@ -20,6 +20,7 @@ die() { ...@@ -20,6 +20,7 @@ die() {
GITLAB_BACKUP_PATH= GITLAB_BACKUP_PATH=
GITLAB_REPOS_PATH= GITLAB_REPOS_PATH=
GITLAB_HOOKS_PATH=
# database name & PostgreSQL settings how to connect to server # database name & PostgreSQL settings how to connect to server
GITLAB_DATABASE= GITLAB_DATABASE=
...@@ -35,6 +36,7 @@ need_gitlab_config() { ...@@ -35,6 +36,7 @@ need_gitlab_config() {
{ {
read GITLAB_BACKUP_PATH read GITLAB_BACKUP_PATH
read GITLAB_REPOS_PATH read GITLAB_REPOS_PATH
read GITLAB_HOOKS_PATH
read GITLAB_DATABASE read GITLAB_DATABASE
read gitlab_db_adapter read gitlab_db_adapter
...@@ -50,7 +52,7 @@ need_gitlab_config() { ...@@ -50,7 +52,7 @@ need_gitlab_config() {
} < <(gitlab-rails r ' } < <(gitlab-rails r '
c = Gitlab.config c = Gitlab.config
s = c.gitlab_shell s = c.gitlab_shell
puts c.backup.path, s.repos_path puts c.backup.path, s.repos_path, s.hooks_path
c = Backup::Database.new.config c = Backup::Database.new.config
puts c["database"] puts c["database"]
...@@ -245,6 +247,11 @@ backup_restore() { ...@@ -245,6 +247,11 @@ backup_restore() {
# gitlab wants repositories to be drwxrws--- # gitlab wants repositories to be drwxrws---
chmod u=rwx,g=rwxs,o=--- "$reposX" chmod u=rwx,g=rwxs,o=--- "$reposX"
# adjust hooks links to point to current gitlab-shell location
find "$reposX" -type l -path "*.git/hooks" | \
while read H; do
ln -sf "$GITLAB_HOOKS_PATH" "$H"
done
# extraction complete - now proceed with actual backup restore # extraction complete - now proceed with actual backup restore
# (which is mv repositories dir + load db) # (which is mv repositories dir + load db)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment