From d1bb42cad72d699e02e99831a5f9a04e0a04294a Mon Sep 17 00:00:00 2001 From: kay0u Date: Sun, 18 Aug 2019 16:07:18 +0200 Subject: [PATCH] Backup strategy --- config_panel.json | 101 ++++++++++++++++++++++++++++++++++++++++++++-- scripts/backup | 46 ++++++++++++++++++++- scripts/config | 66 ++++++++++++++++++++++++++++++ scripts/install | 29 +++++++++++++ scripts/upgrade | 50 +++++++++++++++++++++++ 5 files changed, 288 insertions(+), 4 deletions(-) diff --git a/config_panel.json b/config_panel.json index 4b7ccf8..d2d2442 100644 --- a/config_panel.json +++ b/config_panel.json @@ -11,7 +11,10 @@ "id": "is_public", "options": [ { - "name": "Is it a public app ?", + "name": "Public app", + "ask": { + "en": "Is it a public app ?" + }, "id": "is_public", "type": "bool", "default": true @@ -23,7 +26,10 @@ "id": "overwrite_files", "options": [ { - "name": "Overwrite the nginx config file ?", + "name": "Overwrite the nginx config file", + "ask": { + "en": "Overwrite the nginx config file ?" + }, "help": "If the file is overwritten, a backup will be created.", "id": "overwrite_nginx", "type": "bool", @@ -36,13 +42,102 @@ "id": "users", "options": [ { - "name": "Authorized external user creation ?", + "name": "Authorized external user creation", + "ask": { + "en": "Authorized external user creation ?" + }, "help": "Allow user to be created without yunohost account.", "id": "use_web_account", "type": "bool", "default": true } ] + }, + { + "name": "Backup strategy", + "id": "backup_strategy", + "options": [ + { + "name": "Backup db", + "ask": { + "en": "Should gitlab backup the database ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_db", + "type": "bool", + "default": true + }, + { + "name": "Backup uploads", + "ask": { + "en": "Should gitlab backup attachments ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_uploads", + "type": "bool", + "default": true + }, + { + "name": "Backup repositories", + "ask": { + "en": "Should gitlab backup git repositories data ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_repositories", + "type": "bool", + "default": true + }, + { + "name": "Backup builds", + "ask": { + "en": "Should gitlab backup CI job output logs ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_builds", + "type": "bool", + "default": true + }, + { + "name": "Backup artifacts", + "ask": { + "en": "Should gitlab backup CI job artifacts ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_artifacts", + "type": "bool", + "default": true + }, + { + "name": "Backup lfs", + "ask": { + "en": "Should gitlab backup LFS objects ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_lfs", + "type": "bool", + "default": true + }, + { + "name": "Backup registry", + "ask": { + "en": "Should gitlab backup container registry images ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_registry", + "type": "bool", + "default": true + }, + { + "name": "Backup pages", + "ask": { + "en": "Should gitlab backup pages content ?" + }, + "help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup", + "id": "backup_pages", + "type": "bool", + "default": true + } + ] } ] } diff --git a/scripts/backup b/scripts/backup index e25ab0b..66ae3fd 100644 --- a/scripts/backup +++ b/scripts/backup @@ -32,6 +32,15 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) config_path=$(ynh_app_setting_get --app=$app --key=config_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +backup_db=$(ynh_app_setting_get --app="$app" --key=backup_db) +backup_uploads=$(ynh_app_setting_get --app="$app" --key=backup_uploads) +backup_repositories=$(ynh_app_setting_get --app="$app" --key=backup_repositories) +backup_builds=$(ynh_app_setting_get --app="$app" --key=backup_builds) +backup_artifacts=$(ynh_app_setting_get --app="$app" --key=backup_artifacts) +backup_lfs=$(ynh_app_setting_get --app="$app" --key=backup_lfs) +backup_registry=$(ynh_app_setting_get --app="$app" --key=backup_registry) +backup_pages=$(ynh_app_setting_get --app="$app" --key=backup_pages) + #================================================= # STANDARD BACKUP STEPS #================================================= @@ -46,10 +55,45 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Backuping of Gitlab..." --weight=9 +to_skip="" + +if [ $backup_db -eq 1 ]; then + to_skip="db,"$to_skip +fi + +if [ $backup_uploads -eq 1 ]; then + to_skip="uploads,"$to_skip +fi + +if [ $backup_repositories -eq 1 ]; then + to_skip="repositories,"$to_skip +fi + +if [ $backup_builds -eq 1 ]; then + to_skip="builds,"$to_skip +fi + +if [ $backup_artifacts -eq 1 ]; then + to_skip="artifacts,"$to_skip +fi + +if [ $backup_lfs -eq 1 ]; then + to_skip="lfs,"$to_skip +fi + +if [ $backup_registry -eq 1 ]; then + to_skip="registry,"$to_skip +fi + +if [ $backup_pages -eq 1 ]; then + to_skip="pages,"$to_skip +fi + # Use gitlab-rake to backup # For the complete doc: https://docs.gitlab.com/ce/raketasks/backup_restore.html # For the filename: https://docs.gitlab.com/ce/raketasks/backup_restore.html#backup-filename -gitlab-rake gitlab:backup:create BACKUP=last +# For the backup strategy: https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup +gitlab-rake gitlab:backup:create BACKUP=last SKIP=$to_skip ynh_backup --src_path="/var/opt/$app/backups/last_gitlab_backup.tar" diff --git a/scripts/config b/scripts/config index f66658d..800d7d8 100644 --- a/scripts/config +++ b/scripts/config @@ -40,6 +40,39 @@ old_use_web_account="$(ynh_app_setting_get --app=$app --key=use_web_account)" old_use_web_account=$(bool_to_true_false $old_use_web_account) use_web_account="${YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT:-$old_use_web_account}" +# backup_strategy +old_backup_db="$(ynh_app_setting_get --app=$app --key=backup_db)" +old_backup_db=$(bool_to_true_false $old_backup_db) +backup_db="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_DB:-$old_backup_db}" + +old_backup_uploads="$(ynh_app_setting_get --app=$app --key=backup_uploads)" +old_backup_uploads=$(bool_to_true_false $old_backup_uploads) +backup_uploads="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_UPLOADS:-$old_backup_uploads}" + +old_backup_repositories="$(ynh_app_setting_get --app=$app --key=backup_repositories)" +old_backup_repositories=$(bool_to_true_false $old_backup_repositories) +backup_repositories="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REPOSITORIES:-$old_backup_repositories}" + +old_backup_builds="$(ynh_app_setting_get --app=$app --key=backup_builds)" +old_backup_builds=$(bool_to_true_false $old_backup_builds) +backup_builds="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_BUILDS:-$old_backup_builds}" + +old_backup_artifacts="$(ynh_app_setting_get --app=$app --key=backup_artifacts)" +old_backup_artifacts=$(bool_to_true_false $old_backup_artifacts) +backup_artifacts="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_ARTIFACTS:-$old_backup_artifacts}" + +old_backup_lfs="$(ynh_app_setting_get --app=$app --key=backup_lfs)" +old_backup_lfs=$(bool_to_true_false $old_backup_lfs) +backup_lfs="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_LFS:-$old_backup_lfs}" + +old_backup_registry="$(ynh_app_setting_get --app=$app --key=backup_registry)" +old_backup_registry=$(bool_to_true_false $old_backup_registry) +backup_registry="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REGISTRY:-$old_backup_registry}" + +old_backup_pages="$(ynh_app_setting_get --app=$app --key=backup_pages)" +old_backup_pages=$(bool_to_true_false $old_backup_pages) +backup_pages="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_PAGES:-$old_backup_pages}" + #================================================= # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND #================================================= @@ -53,6 +86,22 @@ show_config() { echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx" echo "YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT=$use_web_account" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_DB=$backup_db" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_UPLOADS=$backup_uploads" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REPOSITORIES=$backup_repositories" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_BUILDS=$backup_builds" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_ARTIFACTS=$backup_artifacts" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_LFS=$backup_lfs" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REGISTRY=$backup_registry" + + echo "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_PAGES=$backup_pages" } #================================================= @@ -78,6 +127,23 @@ apply_config() { # Set overwrite_nginx ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx" + + # Set backup_db + ynh_app_setting_set --app=$app --key=backup_db --value="$(bool_to_01 $backup_db)" + # Set backup_uploads + ynh_app_setting_set --app=$app --key=backup_uploads --value="$(bool_to_01 $backup_uploads)" + # Set backup_repositories + ynh_app_setting_set --app=$app --key=backup_repositories --value="$(bool_to_01 $backup_repositories)" + # Set backup_builds + ynh_app_setting_set --app=$app --key=backup_builds --value="$(bool_to_01 $backup_builds)" + # Set backup_artifacts + ynh_app_setting_set --app=$app --key=backup_artifacts --value="$(bool_to_01 $backup_artifacts)" + # Set backup_lfs + ynh_app_setting_set --app=$app --key=backup_lfs --value="$(bool_to_01 $backup_lfs)" + # Set backup_registry + ynh_app_setting_set --app=$app --key=backup_registry --value="$(bool_to_01 $backup_registry)" + # Set backup_pages + ynh_app_setting_set --app=$app --key=backup_pages --value="$(bool_to_01 $backup_pages)" } #================================================= diff --git a/scripts/install b/scripts/install index 99402e0..4c9aa9e 100644 --- a/scripts/install +++ b/scripts/install @@ -216,6 +216,35 @@ newuser.confirmation_token = nil newuser.save ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console + +#================================================= +# DEFINE THE BACKUP STRATEGY: https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup +#================================================= + +backup_db=1 +ynh_app_setting_set --app=$app --key=backup_db --value=$backup_db + +backup_uploads=1 +ynh_app_setting_set --app=$app --key=backup_uploads --value=$backup_uploads + +backup_repositories=1 +ynh_app_setting_set --app=$app --key=backup_repositories --value=$backup_repositories + +backup_builds=1 +ynh_app_setting_set --app=$app --key=backup_builds --value=$backup_builds + +backup_artifacts=1 +ynh_app_setting_set --app=$app --key=backup_artifacts --value=$backup_artifacts + +backup_lfs=1 +ynh_app_setting_set --app=$app --key=backup_lfs --value=$backup_lfs + +backup_registry=1 +ynh_app_setting_set --app=$app --key=backup_registry --value=$backup_registry + +backup_pages=1 +ynh_app_setting_set --app=$app --key=backup_pages --value=$backup_pages + #================================================= # RECONFIGURE TO TAKE INTO ACCOUNT CHANGES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6b0baed..26decfa 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -33,6 +33,15 @@ unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size) overwrite_nginx=$(ynh_app_setting_get --app="$app" --key=overwrite_nginx) +backup_db=$(ynh_app_setting_get --app="$app" --key=backup_db) +backup_uploads=$(ynh_app_setting_get --app="$app" --key=backup_uploads) +backup_repositories=$(ynh_app_setting_get --app="$app" --key=backup_repositories) +backup_builds=$(ynh_app_setting_get --app="$app" --key=backup_builds) +backup_artifacts=$(ynh_app_setting_get --app="$app" --key=backup_artifacts) +backup_lfs=$(ynh_app_setting_get --app="$app" --key=backup_lfs) +backup_registry=$(ynh_app_setting_get --app="$app" --key=backup_registry) +backup_pages=$(ynh_app_setting_get --app="$app" --key=backup_pages) + #================================================= # CHECK VERSION #================================================= @@ -146,6 +155,47 @@ if [ -e "/etc/apt/sources.list.d/gitlab-ce.list" ]; then ynh_secure_remove --file="/etc/apt/sources.list.d/gitlab-ce.list" fi +# Define the backup strategy: https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup +if [ -z "$backup_db" ]; then + backup_db=1 + ynh_app_setting_set --app=$app --key=backup_db --value=$backup_db +fi + +if [ -z "$backup_uploads" ]; then + backup_uploads=1 + ynh_app_setting_set --app=$app --key=backup_uploads --value=$backup_uploads +fi + +if [ -z "$backup_repositories" ]; then + backup_repositories=1 + ynh_app_setting_set --app=$app --key=backup_repositories --value=$backup_repositories +fi + +if [ -z "$backup_builds" ]; then + backup_builds=1 + ynh_app_setting_set --app=$app --key=backup_builds --value=$backup_builds +fi + +if [ -z "$backup_artifacts" ]; then + backup_artifacts=1 + ynh_app_setting_set --app=$app --key=backup_artifacts --value=$backup_artifacts +fi + +if [ -z "$backup_lfs" ]; then + backup_lfs=1 + ynh_app_setting_set --app=$app --key=backup_lfs --value=$backup_lfs +fi + +if [ -z "$backup_registry" ]; then + backup_registry=1 + ynh_app_setting_set --app=$app --key=backup_registry --value=$backup_registry +fi + +if [ -z "$backup_pages" ]; then + backup_pages=1 + ynh_app_setting_set --app=$app --key=backup_pages --value=$backup_pages +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #=================================================