mirror of
https://github.com/YunoHost-Apps/gitlab_ynh.git
synced 2024-09-03 18:36:35 +02:00
Merge pull request #3 from bourreP/backup-restore
Backup and Restore scripts
This commit is contained in:
commit
10e3225031
5 changed files with 158 additions and 66 deletions
|
@ -2,7 +2,7 @@
|
||||||
"name": "Gitlab",
|
"name": "Gitlab",
|
||||||
"id": "gitlab",
|
"id": "gitlab",
|
||||||
"packaging_format": 1,
|
"packaging_format": 1,
|
||||||
"version": "1.5.3~ynh1",
|
"version": "1.6.0~ynh1",
|
||||||
"description": {
|
"description": {
|
||||||
"en": "Gitlab for Yunohost.",
|
"en": "Gitlab for Yunohost.",
|
||||||
"fr": "Gitlab pour YunoHost."
|
"fr": "Gitlab pour YunoHost."
|
||||||
|
@ -59,9 +59,16 @@
|
||||||
"fr": "Est-ce une application publique ?"
|
"fr": "Est-ce une application publique ?"
|
||||||
},
|
},
|
||||||
"default": true
|
"default": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "only_use_ldap",
|
||||||
|
"type": "boolean",
|
||||||
|
"ask": {
|
||||||
|
"en": "Use only Yunohost account to sign in?",
|
||||||
|
"fr": "Utiliser seulement les comptes Yunohost pour se connecter ?"
|
||||||
|
},
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,57 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
# See comments in install script
|
# IMPORT GENERIC HELPERS
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
#=================================================
|
||||||
|
|
||||||
# Source YunoHost helpers
|
# Source YunoHost helpers
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Backup sources & data
|
# Load common variables and helpers
|
||||||
# Note: the last argument is where to save this path, see the restore script.
|
source ../settings/scripts/_common.sh
|
||||||
ynh_backup "/var/www/${app}" "sources"
|
|
||||||
|
|
||||||
### MySQL (remove if not used) ###
|
#=================================================
|
||||||
# If a MySQL database is used:
|
# MANAGE SCRIPT FAILURE
|
||||||
# # Dump the database
|
#=================================================
|
||||||
# dbname=$app
|
|
||||||
# dbuser=$app
|
ynh_clean_setup () {
|
||||||
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
# mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
rm /var/opt/gitlab/backups/*_gitlab_backup.tar
|
||||||
### MySQL end ###
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Copy NGINX configuration
|
# Copy NGINX configuration
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
|
||||||
|
|
||||||
### PHP (remove if not used) ###
|
#=================================================
|
||||||
# If a dedicated php-fpm process is used:
|
# STANDARD BACKUP STEPS
|
||||||
# # Copy PHP-FPM pool configuration
|
#=================================================
|
||||||
# ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
### PHP end ###
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP GITLAB DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Use gitlab-rake to backup
|
||||||
|
gitlab-rake gitlab:backup:create
|
||||||
|
|
||||||
|
ynh_backup "/var/opt/$app/backups/"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP CONF FILES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "$config_path/gitlab-secrets.json"
|
||||||
|
ynh_backup "$config_path/gitlab.rb"
|
||||||
|
|
|
@ -22,6 +22,7 @@ source ./_common.sh
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path_url=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
only_use_ldap=$YNH_APP_ARG_IS_PUBLIC
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -49,6 +50,7 @@ ynh_user_exists "$admin" \
|
||||||
ynh_app_setting_set $app admin $admin
|
ynh_app_setting_set $app admin $admin
|
||||||
ynh_app_setting_set $app path_url $path_url
|
ynh_app_setting_set $app path_url $path_url
|
||||||
ynh_app_setting_set $app is_public $is_public
|
ynh_app_setting_set $app is_public $is_public
|
||||||
|
ynh_app_setting_set $app only_use_ldap $only_use_ldap
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
|
@ -94,7 +96,7 @@ setup_source $architecture
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
#=================================================
|
#=================================================
|
||||||
# GETTING ADMIN INFO AND ADD AS A GITLAB USER
|
# GETTING ADMIN INFO AND ADD AS A GITLAB USER AND CONFIGURE SIGN IN SYSTEM
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
mailadmin=$(ynh_user_get_info $admin mail)
|
mailadmin=$(ynh_user_get_info $admin mail)
|
||||||
|
@ -104,7 +106,8 @@ echo "newuser = User.new({ \"email\"=>'$mailadmin', \"username\"=>'$admin', \"na
|
||||||
newuser.admin = true
|
newuser.admin = true
|
||||||
newuser.confirmed_at = Time.now
|
newuser.confirmed_at = Time.now
|
||||||
newuser.confirmation_token = nil
|
newuser.confirmation_token = nil
|
||||||
newuser.save" | sudo gitlab-rails console
|
newuser.save
|
||||||
|
ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $only_use_ldap, signup_enabled: $only_use_ldap)" | sudo gitlab-rails console
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTART TO TAKE INTO ACCOUNT CHANGES
|
# RESTART TO TAKE INTO ACCOUNT CHANGES
|
||||||
|
|
130
scripts/restore
130
scripts/restore
|
@ -1,52 +1,110 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Note: each files and directories you've saved using the ynh_backup helper
|
#=================================================
|
||||||
# will be located in the current directory, regarding the last argument.
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
if [ ! -e _common.sh ]; then
|
||||||
set -eu
|
# Get the _common.sh file if it's not in the current directory
|
||||||
|
cp ../settings/scripts/_common.sh ./_common.sh
|
||||||
# See comments in install script
|
mkdir ./upgrade.d
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
mkdir ../conf
|
||||||
|
cp ../settings/scripts/upgrade.d/upgrade.sh ./upgrade.d/upgrade.sh
|
||||||
|
cp ../settings/conf/*.default ../conf/
|
||||||
|
chmod a+rx _common.sh upgrade.d/upgrade.sh
|
||||||
|
fi
|
||||||
|
|
||||||
# Source YunoHost helpers
|
# Source YunoHost helpers
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Retrieve old app settings
|
# Load common variables and helpers
|
||||||
|
source _common.sh
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_clean_setup () {
|
||||||
|
|
||||||
|
rm /var/opt/gitlab/backups/*_gitlab_backup.tar
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Copy NGINX configuration
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
path_url=$(ynh_app_setting_get "$app" path_url)
|
path_url=$(ynh_app_setting_get "$app" path_url)
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
#=================================================
|
||||||
|
|
||||||
# Restore sources & data
|
ynh_webpath_available $domain $path_url \
|
||||||
src_path="/var/www/${app}"
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
sudo cp -a ./sources "$src_path"
|
test ! -d $final_path \
|
||||||
|
|| ynh_die "There is already a directory: $final_path "
|
||||||
|
|
||||||
# Restore permissions to app files
|
#=================================================
|
||||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
# STANDARD RESTORATION STEPS
|
||||||
sudo chown -R root: "$src_path"
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
### MySQL (remove if not used) ###
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
# If a MySQL database is used:
|
|
||||||
# # Create and restore the database
|
|
||||||
# dbname=$app
|
|
||||||
# dbuser=$app
|
|
||||||
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
# ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
||||||
# ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
|
||||||
### MySQL end ###
|
|
||||||
|
|
||||||
# Restore NGINX configuration
|
#=================================================
|
||||||
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
# REINSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
### PHP (remove if not used) ###
|
ynh_install_app_dependencies openssh-server
|
||||||
# If a dedicated php-fpm process is used:
|
|
||||||
# # Copy PHP-FPM pool configuration and reload the service
|
|
||||||
# sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf"
|
|
||||||
# sudo service php5-fpm reload
|
|
||||||
### PHP end ###
|
|
||||||
|
|
||||||
# Restart webserver
|
#=================================================
|
||||||
sudo service nginx reload
|
# RESTORE CONF FILES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "$config_path/gitlab-secrets.json"
|
||||||
|
ynh_restore_file "$config_path/gitlab.rb"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
setup_source $architecture
|
||||||
|
|
||||||
|
ynh_restore_file "/var/opt/$app/backups/"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC RESTORATION
|
||||||
|
#=================================================
|
||||||
|
# RESTORE GITLAB DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
fullfile=$(ls /var/opt/gitlab/backups/*_gitlab* --file -c1 | head -1)
|
||||||
|
basename="/var/opt/gitlab/backups/"
|
||||||
|
filename=$(basename -- "$fullfile")
|
||||||
|
last_backup="${filename%_gitlab_backup.tar}"
|
||||||
|
|
||||||
|
gitlab-ctl stop unicorn
|
||||||
|
gitlab-ctl stop sidekiq
|
||||||
|
|
||||||
|
# Use gitlab-rake to backup
|
||||||
|
gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
|
||||||
|
|
||||||
|
gitlab-ctl restart
|
||||||
|
gitlab-rake gitlab:check SANITIZE=true
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload nginx
|
|
@ -1,5 +1,5 @@
|
||||||
gitlab_version="11.5.3"
|
gitlab_version="11.6.0"
|
||||||
|
|
||||||
gitlab_x86_64_source_sha256="fdbea3e92eb1f613897659e99b20660d64524eaf5b1cd57a323cd6f61c573e7f"
|
gitlab_x86_64_source_sha256="040ac5917d71c45b3fbdeccbeaf2e7b3181fcce0ed9ca65ac68d3d15081b8b02"
|
||||||
|
|
||||||
gitlab_arm_source_sha256="81d37736442be80d687b52299604ef38bc4000b7545b241094b7f5a027c9fac4"
|
gitlab_arm_source_sha256="18d385af2a59fb37c6282298ccb7bbbf091d8ff39fbcde581226e35d5f3792dc"
|
||||||
|
|
Loading…
Reference in a new issue