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 "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
|
2019-03-16 13:17:15 +01:00
|
|
|
|
|
|
|
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
|
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
|
2019-03-17 21:03:20 +01:00
|
|
|
if ! dpkg -i $tempdir/$gitlab_filename ; then # This command will fail in lxc env
|
2019-03-17 20:15:14 +01:00
|
|
|
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
|
2019-03-17 20:14:06 +01:00
|
|
|
fi
|
2019-03-16 02:38:12 +01:00
|
|
|
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
|
2019-03-17 20:15:14 +01:00
|
|
|
ynh_exec_warn_less gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
|
|
|
|
|
|
|
|
gitlab_ctl_action --action=restart --timeout=3600
|
2018-12-24 16:25:49 +01:00
|
|
|
|
|
|
|
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"
|