#!/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 #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ynh_exec_warn_less ynh_secure_remove --file="$tempdir" ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) config_path=$(ynh_app_setting_get --app=$app --key=config_path) portPuma=$(ynh_app_setting_get --app="$app" --key=puma_port) architecture=$(ynh_app_setting_get --app="$app" --key=architecture) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=5 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies #================================================= # ADD SWAP IF NEEDED #================================================= total_memory=$(ynh_get_ram --total) total_swap=$(ynh_get_ram --total --only_swap) swap_needed=0 # https://docs.gitlab.com/ce/install/requirements.html#memory if [ $total_memory -lt 8192 ]; then # Need a minimum of 8Go of memory swap_needed=$((8192 - $total_memory)) fi # Need at least 2Go of swap if [ $(($total_swap + $swap_needed)) -lt 2048 ]; then swap_needed=$((2048 - $total_swap)) fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 ynh_add_swap --size=$swap_needed #================================================= # RESTORE CONF FILES #================================================= ynh_script_progression --message="Restoring configuration files of GitLab..." --weight=1 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 ../settings/scripts/upgrade.d/upgrade.last.sh mkdir -p ../conf/ cp ../settings/conf/$architecture.src.default ../conf/$architecture.src ynh_replace_string --match_string="__VERSION__" --replace_string="$gitlab_version" --target_file="../conf/$architecture.src" ynh_replace_string --match_string="__SOURCE_FILENAME__" --replace_string="$gitlab_filename" --target_file="../conf/$architecture.src" ynh_replace_string --match_string="__DEBIAN_VERSION__" --replace_string="$gitlab_debian_version" --target_file="../conf/$architecture.src" ynh_replace_string --match_string="__SHA256_SUM__" --replace_string="$gitlab_source_sha256" --target_file="../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:$portPuma" --timeout=300 #================================================= # CHECK THE RESTORED DATA #================================================= gitlab-rake gitlab:check SANITIZE=true #================================================= # 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