#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # ADD SWAP IF NEEDED #================================================= total_ram=$(ynh_get_ram --total) swap_needed=0 # https://docs.gitlab.com/ce/install/requirements.html#memory # Need at least 2Go of swap if [ $total_ram -lt 4096 ]; then swap_needed=2048 fi if [ $swap_needed -gt 0 ]; then ynh_script_progression --message="Adding $swap_needed Mo to swap..." if ! ynh_add_swap --size=$swap_needed; then ynh_print_warn --message="Please add $swap_needed Mo to swap to make GitLab work properly" fi fi #================================================= # RESTORE CONF FILES #================================================= ynh_script_progression --message="Restoring configuration files of GitLab..." --weight=1 config_path=/etc/$app chmod 755 $install_dir ynh_restore_file --origin_path="$config_path/gitlab-secrets.json" ynh_restore_file --origin_path="$config_path/gitlab.rb" ynh_restore_file --origin_path="$config_path/gitlab-persistent.rb" #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Reinstalling GitLab..." --weight=50 source $YNH_APP_BASEDIR/scripts/upgrade.d/upgrade.last.sh ynh_add_config --template="$YNH_APP_BASEDIR/conf/$architecture.src.default" --destination="$YNH_APP_BASEDIR/conf/$architecture.src" tempdir="$(mktemp -d)" ynh_setup_source --dest_dir=$tempdir --source_id=$architecture if ! ynh_exec_warn_less dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env package_check_action # defined in upgrade.d/upgrade.last.sh ynh_exec_warn_less dpkg --configure gitlab-ce fi #================================================= # SPECIFIC RESTORATION #================================================= # RESTORE GITLAB DATABASE #================================================= ynh_script_progression --message="Restoring GitLab..." --weight=35 ynh_restore_file --origin_path="/var/opt/$app/backups/last_gitlab_backup.tar" last_backup="last" gitlab-ctl stop puma gitlab-ctl stop sidekiq # Use gitlab-rake to backup # Doc: https://docs.gitlab.com/ce/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations ynh_exec_warn_less gitlab-backup restore force=yes BACKUP=$last_backup # https://docs.gitlab.com/ce/raketasks/backup_restore.html#container-registry-push-failures-after-restoring-from-a-backup if ynh_user_exists --username="registry" && [ -d "/var/opt/gitlab/gitlab-rails/shared/registry/docker" ]; then chown -R registry:registry /var/opt/gitlab/gitlab-rails/shared/registry/docker fi #================================================= # GENERIC FINALIZATION #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add "gitlab-runsvdir" --log "/var/log/$app/gitlab-rails/application.log" "/var/log/$app/gitlab-rails/api_json.log" "/var/log/$app/gitlab-rails/production.log" "/var/log/$app/gitlab-rails/production_json.log" "/var/log/$app/gitlab-rails/sidekiq.log" "/var/log/$app/puma/puma_stderr.log" "/var/log/$app/puma/current" "/var/log/$app/alertmanager/current" "/var/log/$app/gitaly/current" "/var/log/$app/gitlab-monitor/current" "/var/log/$app/gitlab-shell/gitlab-shell.log" "/var/log/$app/gitlab-workhorse/current" "/var/log/$app/logrotate/current" "/var/log/$app/nginx/current" "/var/log/$app/nginx/access.log" "/var/log/$app/nginx/error.log" "/var/log/$app/nginx/gitlab_access.log" "/var/log/$app/nginx/gitlab_error.log" "/var/log/$app/node-exporter/current" "/var/log/$app/postgres-exporter/current" "/var/log/$app/postgresql/current" "/var/log/$app/prometheus/current" "/var/log/$app/redis/current" "/var/log/$app/redis-exporter/current" #================================================= # WAITING GITLAB #================================================= ynh_script_progression --message="Waiting for GitLab..." --weight=14 ynh_systemd_action --action=restart --service_name="gitlab-runsvdir" --log_path="/var/log/$app/puma/current" --line_match="Listening on http://127.0.0.1:$port_puma" --timeout=300 #================================================= # CHECK THE RESTORED DATA #================================================= gitlab-rake gitlab:check SANITIZE=true # Allow ssh for git usermod -a -G "ssh.app" "git" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --action=reload --service_name=nginx #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Restoration completed for GitLab" --last