Skip to content

Instantly share code, notes, and snippets.

@duruyao
Last active May 17, 2024 02:35
Show Gist options
  • Save duruyao/eae992866229c6c394ad1d328776818b to your computer and use it in GitHub Desktop.
Save duruyao/eae992866229c6c394ad1d328776818b to your computer and use it in GitHub Desktop.
Automatically restore for Omnibus Gitlab installations from backups periodically.
#!/usr/bin/env bash
## date: 2024-02-29
## author: duruyao@vimicro.com
## desc: restore for 'omnibus' gitlab installations from backups
set -euo pipefail
current_date() {
date +"%Y-%m-%d"
}
current_time() {
date +"%Y-%m-%d %T"
}
gitlab_backups_dir="/opt/gitlab-data/gitlab-backups"
gitlab_restore_log_path="${gitlab_backups_dir}/restore.log"
gitlab_backups_data_dir="${gitlab_backups_dir}/data"
gitlab_backups_conf_dir="${gitlab_backups_dir}/conf"
{
printf "\n\n============================== %s ==============================\n\n\n" "$(current_date)"
printf "[INFO] restore gitlab from %s starting from [%s]\n" "${gitlab_backups_dir}" "$(current_time)"
sudo rsync -arv "${gitlab_backups_conf_dir}"/* /etc/gitlab/
sudo find /etc/gitlab -type f -execdir sed -i 's/10\.0\.13\.134/10.0.13.120/g' {} +
sudo gitlab-ctl reconfigure
sudo gitlab-ctl status
sudo chown git:git -R "${gitlab_backups_data_dir}"
sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl status
sudo gitlab-backup restore BACKUP=dump force=yes
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true
printf "[INFO] restore gitlab from %s end at [%s]\n" "${gitlab_backups_dir}" "$(current_time)"
} &>>"${gitlab_restore_log_path}"
#!/usr/bin/env bash
## date: 2021-11-11
## author: duruyao@vimicro.com
## desc: automatically restore for omnibus gitlab installations from backups at 14:00
set -euo pipefail
script_path="/home/duruyao/bin/gitlab-tools/restore-gitlab.sh"
auto_tasks=("0 14 * * * root ${script_path} CRON=1")
for task in "${auto_tasks[@]}"; do
if ! grep -Fxq "${task}" /etc/crontab; then
sudo echo "${task}" >>/etc/crontab
fi
done
sudo service cron restart
@duruyao
Copy link
Author

duruyao commented Nov 11, 2021

Priority reference Back up and restore GitLab.

Scripts for backup GitLab is in https://gist.github.com/duruyao/auto-backup-gitlab.sh.

Change some values of variables before you using my scripts, such as gitlab_backups_dir, gitlab_backups_data_dir, gitlab_backups_conf_dir and more.

$ chmod +x restore-gitlab.sh auto-restore-gitlab.sh
$ sudo bash auto-restore-gitlab.sh

All logs are stored in ${gitlab_restore_log_path}.

$ tail -f /opt/gitlab-data/gitlab-backups/restore.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment