1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00
gitlab_ynh/scripts/restore
2019-03-17 20:15:14 +01:00

140 lines
4.5 KiB
Bash

#!/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_secure_remove "$tempdir" 2>&1
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
architecture=$(ynh_app_setting_get "$app" architecture)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_print_info "Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE CONF FILES
#=================================================
ynh_print_info "Restoring configuration files of Gitlab..."
ynh_restore_file "$config_path/gitlab-secrets.json"
ynh_restore_file "$config_path/gitlab.rb"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info "Reinstalling gitlab..."
update_src_version() {
source ../settings/scripts/upgrade.d/upgrade.last.sh
mkdir -p ../conf/
cp ../settings/conf/$architecture.src.default ../conf/$architecture.src
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src"
ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
if [ $architecture = "x86-64" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src"
elif [ $architecture = "arm" ]; then
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
fi
}
update_src_version
tempdir="$(mktemp -d)"
ynh_setup_source $tempdir $architecture
if IS_PACKAGE_CHECK; then
if [ ! dpkg -i $tempdir/$gitlab_filename ]; then # This command will fail in lxc env
ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb"
dpkg --configure gitlab-ce
fi
else
dpkg -i $tempdir/$gitlab_filename
fi
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE GITLAB DATABASE
#=================================================
ynh_print_info "Restoring Gitlab..."
ynh_restore_file "/var/opt/$app/backups/last_gitlab_backup.tar"
last_backup="last"
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# Use gitlab-rake to backup
ynh_exec_warn_less gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
gitlab_ctl_action --action=restart --timeout=3600
gitlab-rake gitlab:check SANITIZE=true
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Restoration completed for $app"