Last active
May 6, 2016 13:56
-
-
Save gustavomdsantos/eb53e946e9e5dcd6dabe34486fddee20 to your computer and use it in GitHub Desktop.
Script que ajuda a restaurar backups no GitLab, resolvendo problemas de permissões de arquivos no GitLab, entre outros (comandos obtidos da saída do comando ´sudo gitlab-rake gitlab:check SANITIZE=true` e http://doc.gitlab.com/ce/raketasks/backup_restore.html#omnibus-installations)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
APP_NAME="Restore GitLab Backup Files by gustavosotnas" | |
# Author: Gustavo Moraes <[email protected]> | |
# | |
# Solution based in GitLab's official tutorial to restore backups: | |
# http://doc.gitlab.com/ce/raketasks/backup_restore.html#omnibus-installations | |
# (This script applies to GitLab installations from official .deb package!) | |
# | |
# To backup a GitLab repository server, simply run this command: | |
# sudo gitlab-rake gitlab:backup:create | |
# And copy the .tar file from /var/opt/gitlab/backups/ to the folder you want. | |
# | |
# This file is subject to the terms and conditions of the GNU General Public | |
# License. See http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
# for more details. | |
function restoreGitLabBackup() { | |
# Activate Debug from here (to user see what commands are being executed) | |
set -x | |
# Reconfigure to avoid problems during restore backup | |
sudo gitlab-ctl reconfigure | |
# To ensure that GitLab is running before restore backup | |
sudo gitlab-ctl start | |
# Copy backup file to default GitLab's backups folder | |
sudo cp "$1" /var/opt/gitlab/backups/ | |
# Giving reading permission to the file in backups folder | |
sudo chmod +r /var/opt/gitlab/backups/"$1" | |
# Stop the processes that are connected to the GitLab database | |
sudo gitlab-ctl stop unicorn | |
sudo gitlab-ctl stop sidekiq | |
# Verify | |
sudo gitlab-ctl status | |
# Restart all GitLab processes after restoring backup | |
sudo gitlab-ctl start | |
# Fix permissions (`sudo gitlab-rake gitlab:check SANITIZE=true` suggestion) | |
sudo chmod -R ug+rwX,o-rwx /var/opt/gitlab/git-data/repositories | |
sudo chmod -R ug-s /var/opt/gitlab/git-data/repositories | |
sudo find /var/opt/gitlab/git-data/repositories -type d -print0 | sudo xargs -0 chmod g+s | |
sudo chown -R git /var/opt/gitlab/gitlab-rails/uploads | |
sudo find /var/opt/gitlab/gitlab-rails/uploads -type f -exec chmod 0644 {} \; | |
sudo find /var/opt/gitlab/gitlab-rails/uploads -type d -not -path /var/opt/gitlab/gitlab-rails/uploads -exec chmod 0700 {} \; | |
# Check GitLab | |
sudo gitlab-rake gitlab:check SANITIZE=true | |
# Disable Debug | |
set +x | |
} | |
function displayErrorAndUsage() { | |
echo "$APP_NAME" | |
echo -e "\nInvalid parameter. You should pass the desired GitLab backup file location to work, like this: \n | |
$0 1462459594_gitlab_backup.tar \n\nFor example." | fmt | |
} | |
### MAIN ### | |
case $1 in | |
*_gitlab_backup.tar) restoreGitLabBackup $1;; | |
*) displayErrorAndUsage;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment