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

134 lines
4.3 KiB
Text
Raw Normal View History

2017-06-10 10:10:31 +02:00
#!/bin/bash
2018-12-24 16:25:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-06-10 10:10:31 +02:00
2019-03-16 02:38:12 +01:00
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
2019-01-22 16:05:08 +01:00
source /usr/share/yunohost/helpers
2019-02-09 22:18:57 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2019-03-16 02:38:12 +01:00
ynh_clean_setup () {
ynh_secure_remove "$tempdir" 2>&1
2019-02-09 22:18:57 +01:00
}
2019-01-22 16:05:08 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2018-12-24 16:25:49 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Loading settings..."
app=$YNH_APP_INSTANCE_NAME
2018-12-24 16:25:49 +01:00
2019-03-16 02:38:12 +01:00
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)
2018-12-24 19:10:30 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Validating restoration parameters..."
2018-12-24 19:10:30 +01:00
2019-03-16 02:38:12 +01:00
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 "
2018-12-24 16:25:49 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
2018-12-24 19:10:30 +01:00
#=================================================
2018-12-25 20:55:11 +01:00
# REINSTALL DEPENDENCIES
2018-12-24 19:10:30 +01:00
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Reinstalling dependencies..."
2018-12-24 19:10:30 +01:00
2019-03-16 02:38:12 +01:00
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
2018-12-25 19:22:24 +01:00
2018-12-25 20:55:11 +01:00
#=================================================
# RESTORE CONF FILES
#=================================================
2019-01-26 14:30:58 +01:00
ynh_print_info "Restoring configuration files of Gitlab..."
2018-12-25 20:08:49 +01:00
ynh_restore_file "$config_path/gitlab-secrets.json"
ynh_restore_file "$config_path/gitlab.rb"
2018-12-25 20:55:11 +01:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Reinstalling gitlab..."
update_src_version() {
source ../settings/scripts/upgrade.d/upgrade.last.sh
mkdir -p ../conf/
2019-03-16 12:28:47 +01:00
cp ../settings/conf/$architecture.src.default ../conf/$architecture.src
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src"
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
2019-03-16 02:38:12 +01:00
}
update_src_version
2018-12-25 20:55:11 +01:00
2019-03-16 02:38:12 +01:00
tempdir="$(mktemp -d)"
2018-12-24 19:55:59 +01:00
2019-03-16 02:38:12 +01:00
ynh_setup_source $tempdir $architecture
if IS_PACKAGE_CHECK; then
dpkg -i $tempdir/$gitlab_filename || true # This command will fail in lxc env
sed -i 's/command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"/command \"cat \/etc\/sysctl.conf\"/g' $final_path/embedded/cookbooks/package/resources/sysctl.rb
dpkg --configure gitlab-ce
else
dpkg -i $tempdir/$gitlab_filename
fi
2018-12-24 19:10:30 +01:00
2018-12-24 19:31:51 +01:00
#=================================================
2018-12-24 19:55:59 +01:00
# SPECIFIC RESTORATION
#=================================================
2018-12-25 20:55:11 +01:00
# RESTORE GITLAB DATABASE
2018-12-24 19:31:51 +01:00
#=================================================
2019-01-26 14:30:58 +01:00
ynh_print_info "Restoring Gitlab..."
2019-03-16 02:38:12 +01:00
ynh_restore_file "/var/opt/$app/backups/last_gitlab_backup.tar"
last_backup="last"
2018-12-24 16:25:49 +01:00
2018-12-25 20:55:11 +01:00
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
2018-12-24 16:25:49 +01:00
# Use gitlab-rake to backup
gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true
2018-12-25 20:55:11 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
2019-03-16 02:38:12 +01:00
ynh_print_info "Reloading nginx web server..."
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# END OF SCRIPT
#=================================================
2018-12-25 20:55:11 +01:00
2019-03-16 02:38:12 +01:00
ynh_print_info "Restoration completed for $app"