mirror of
https://github.com/YunoHost-Apps/gitlab_ynh.git
synced 2024-09-03 18:36:35 +02:00
update backup and restore scripts
This commit is contained in:
parent
f8010caeb4
commit
a4c169584a
2 changed files with 83 additions and 60 deletions
|
@ -1,33 +1,49 @@
|
||||||
#!/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 ./_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)
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
# mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
true
|
||||||
### MySQL end ###
|
}
|
||||||
|
# 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 THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Use gitlab-rake to backup
|
||||||
|
gitlab-rake gitlab:backup:create
|
||||||
|
|
||||||
|
ynh_backup "$config_path/gitlab-secrets.json" "gitlab-secrets.json"
|
||||||
|
ynh_backup "$config_path/gitlab.rb" "gitlab.rb"
|
|
@ -1,52 +1,59 @@
|
||||||
#!/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
|
||||||
|
#=================================================
|
||||||
# Exit on command errors and treat unset variables as an error
|
# IMPORT GENERIC HELPERS
|
||||||
set -eu
|
#=================================================
|
||||||
|
|
||||||
# See comments in install script
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
|
|
||||||
# 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 () {
|
||||||
|
### Remove this function if there's nothing to clean before calling the remove script.
|
||||||
|
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)
|
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
# STANDARD RESTORATION STEPS
|
||||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Restore sources & data
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
src_path="/var/www/${app}"
|
|
||||||
sudo cp -a ./sources "$src_path"
|
|
||||||
|
|
||||||
# Restore permissions to app files
|
#=================================================
|
||||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
# RESTORE THE APP MAIN DIR
|
||||||
sudo chown -R root: "$src_path"
|
#=================================================
|
||||||
|
|
||||||
### MySQL (remove if not used) ###
|
gitlab-ctl stop unicorn
|
||||||
# If a MySQL database is used:
|
gitlab-ctl stop sidekiq
|
||||||
# # 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
|
fullfile=$(ls /var/opt/gitlab/backups/*_gitlab* --file -c1 | head -1)
|
||||||
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
basename="/var/opt/gitlab/backups/"
|
||||||
|
last_backup="${filename%_gitlab_backup.tar}"
|
||||||
|
|
||||||
### PHP (remove if not used) ###
|
# Use gitlab-rake to backup
|
||||||
# If a dedicated php-fpm process is used:
|
gitlab-rake gitlab:backup:restore force=yes BACKUP=$last_backup
|
||||||
# # 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
|
ynh_backup "$config_path/gitlab-secrets.json" "gitlab-secrets.json"
|
||||||
sudo service nginx reload
|
ynh_backup "$config_path/gitlab.rb" "gitlab.rb"
|
||||||
|
|
||||||
|
gitlab-ctl restart
|
||||||
|
gitlab-rake gitlab:check SANITIZE=true
|
||||||
|
|
Loading…
Reference in a new issue