From db53bc324db4cd684932d9fad88f352d754e9bdf Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Sun, 20 Sep 2020 18:32:24 +0200 Subject: [PATCH 1/7] Update backup --- scripts/backup | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/backup b/scripts/backup index 65a1d11..d3a0ca9 100644 --- a/scripts/backup +++ b/scripts/backup @@ -69,6 +69,13 @@ ynh_print_info --message="Backing up the PostgreSQL database..." ynh_psql_dump_db --database="$db_name" > db.sql +================================================= +# BACKUP THE DATA DIRECTORY +#================================================= +ynh_print_info --message="Backing up data directory..." + +ynh_backup --src_path="/home/yunohost.app/${app}" --is_big + #================================================= # END OF SCRIPT #================================================= From a646f7648d55a53ff21129e654c78785cf99a8ed Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Sun, 20 Sep 2020 18:36:20 +0200 Subject: [PATCH 2/7] [fix] Restore data directory --- scripts/restore | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/restore b/scripts/restore index cf78b19..5661277 100644 --- a/scripts/restore +++ b/scripts/restore @@ -80,18 +80,16 @@ chown -R $app:$app $final_path #================================================= # SPECIFIC RESTORATION #================================================= -# CREATE THE DATA DIRECTORY +# RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Creating the data directory..." +ynh_script_progression --message="Restoring data directory..." --weight=2 -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" +datadir="/home/yunohost.app/$app/storage" -if [ ! -d "$datadir" ] -then - # Create app folders - mkdir -p "$datadir" -fi +# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. +ynh_restore_file --origin_path="$datadir" --not_mandatory + +mkdir -p "$datadir" # Give permission to the datadir chown -R "$app":"$app" "$datadir" From b8723b68c7d64e7872c9d7f0e5523805930cef5f Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Sun, 20 Sep 2020 18:37:33 +0200 Subject: [PATCH 3/7] [fix] Better path for datadir --- scripts/restore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/restore b/scripts/restore index 5661277..1b90ec6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -84,12 +84,12 @@ chown -R $app:$app $final_path #================================================= ynh_script_progression --message="Restoring data directory..." --weight=2 -datadir="/home/yunohost.app/$app/storage" +datadir="/home/yunohost.app/$app" # Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. ynh_restore_file --origin_path="$datadir" --not_mandatory -mkdir -p "$datadir" +mkdir -p "$datadir/storage" # Give permission to the datadir chown -R "$app":"$app" "$datadir" From 9d688fd9f1869a48258d0a2fedafa211fc459ca6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 27 Sep 2020 17:49:38 +0200 Subject: [PATCH 4/7] Typo --- scripts/backup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup b/scripts/backup index d3a0ca9..7417a0d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -69,7 +69,7 @@ ynh_print_info --message="Backing up the PostgreSQL database..." ynh_psql_dump_db --database="$db_name" > db.sql -================================================= +#================================================= # BACKUP THE DATA DIRECTORY #================================================= ynh_print_info --message="Backing up data directory..." From 01b375cb9e896ed8a40831501eb3a2ed2789d24b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 27 Sep 2020 19:00:21 +0200 Subject: [PATCH 5/7] Globally define datadir --- conf/message_remove | 4 ++-- conf/nginx.conf | 4 ++-- conf/production.yaml | 24 ++++++++++++------------ scripts/backup | 3 ++- scripts/install | 14 ++++++++------ scripts/remove | 2 ++ scripts/restore | 7 +++---- scripts/upgrade | 13 +++++++++---- 8 files changed, 40 insertions(+), 31 deletions(-) diff --git a/conf/message_remove b/conf/message_remove index d0cdb68..884314a 100644 --- a/conf/message_remove +++ b/conf/message_remove @@ -3,12 +3,12 @@ __APP__ was successfully removed :) __APP__ was successfully removed. The domain https://__DOMAIN____PATH_URL__ is free for other apps to be installed on it. But a futher action is required from your side to completely remove the __APP__ data folder. If you have backup and plan to restore this app in the future DON'T RUN THIS COMMAND. -And if you are going to migrate to othe server you will have to move /home/yunohost.app/__APP__ to your new server. +And if you are going to migrate to othe server you will have to move __DATADIR__ to your new server. You need to run this command to remove the data (warning all your videos will be removed) : -rm -R /home/yunohost.app/__APP__ -f +rm -R __DATADIR__ -f If you facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/peertube_ynh \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index 719ebe8..f0306bb 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -26,7 +26,7 @@ location ~ ^/static/(thumbnails|avatars)/ { # Cache 2 hours more_set_headers "Cache-Control : public, max-age=7200"; - root /home/yunohost.app/__NAME__/storage; + root __DATADIR__; rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break; try_files $uri /; @@ -97,7 +97,7 @@ location ~ ^/static/(webseed|redundancy|streaming-playlists)/ { access_log off; } - root /home/yunohost.app/__NAME__/storage; + root __DATADIR__; rewrite ^/static/webseed/(.*)$ /videos/$1 break; rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break; diff --git a/conf/production.yaml b/conf/production.yaml index 5dab156..6cccd20 100644 --- a/conf/production.yaml +++ b/conf/production.yaml @@ -70,18 +70,18 @@ email: # From the project root directory storage: - tmp: '/home/yunohost.app/__APP__/storage/tmp/' # Use to download data (imports etc), store uploaded files before processing... - avatars: '/home/yunohost.app/__APP__/storage/avatars/' - videos: '/home/yunohost.app/__APP__/storage/videos/' - streaming_playlists: '/home/yunohost.app/__APP__/storage/streaming-playlists/' - redundancy: '/home/yunohost.app/__APP__/storage/videos/' - logs: '/home/yunohost.app/__APP__/storage/logs/' - previews: '/home/yunohost.app/__APP__/storage/previews/' - thumbnails: '/home/yunohost.app/__APP__/storage/thumbnails/' - torrents: '/home/yunohost.app/__APP__/storage/torrents/' - captions: '/home/yunohost.app/__APP__/storage/captions/' - cache: '/home/yunohost.app/__APP__/storage/cache/' - plugins: '/home/yunohost.app/__APP__/storage/plugins/' + tmp: '__DATADIR__/tmp/' # Use to download data (imports etc), store uploaded files before processing... + avatars: '__DATADIR__/avatars/' + videos: '__DATADIR__/videos/' + streaming_playlists: '__DATADIR__/streaming-playlists/' + redundancy: '__DATADIR__/videos/' + logs: '__DATADIR__/logs/' + previews: '__DATADIR__/previews/' + thumbnails: '__DATADIR__/thumbnails/' + torrents: '__DATADIR__/torrents/' + captions: '__DATADIR__/captions/' + cache: '__DATADIR__/cache/' + plugins: '__DATADIR__/plugins/' log: level: 'info' # debug/info/warning/error diff --git a/scripts/backup b/scripts/backup index 7417a0d..7837123 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=psql_db) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -74,7 +75,7 @@ ynh_psql_dump_db --database="$db_name" > db.sql #================================================= ynh_print_info --message="Backing up data directory..." -ynh_backup --src_path="/home/yunohost.app/${app}" --is_big +ynh_backup --src_path="$datadir" --is_big #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index bf5ce33..c87fe37 100644 --- a/scripts/install +++ b/scripts/install @@ -32,6 +32,9 @@ is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME +# Define app's data directory +datadir="/home/yunohost.app/${app}/storage" + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -52,6 +55,7 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email ynh_app_setting_set --app=$app --key=admin_pass --value=$admin_pass ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=datadir --value=$datadir #================================================= # STANDARD MODIFICATIONS @@ -116,7 +120,7 @@ ynh_setup_source --dest_dir="$final_path" ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "datadir" #================================================= # CREATE DEDICATED USER @@ -133,9 +137,6 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= ynh_script_progression --message="Creating the data directory..." -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" - # Create app folders mkdir -p "$datadir" @@ -155,6 +156,7 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_email" --target_file="$config" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="$config" #Create the admin settings file local_config="$final_path/config/local-production.json" @@ -205,14 +207,14 @@ chown -R $app:$app $final_path ynh_script_progression --message="Configuring log rotation..." # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="/home/yunohost.app/${app}/storage/logs/peertube.log" +ynh_use_logrotate --logfile="$datadir/logs/peertube.log" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" +yunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index d680761..4d395e9 100644 --- a/scripts/remove +++ b/scripts/remove @@ -23,6 +23,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=psql_db) db_user=$app final_path=$(ynh_app_setting_get --app=$app --key=final_path) admin_email=$(ynh_app_setting_get --app=$app --key=admin_email) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -115,6 +116,7 @@ ynh_script_progression --message="Sending a readme for the admin..." ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/message_remove" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message_remove" ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message_remove" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="../conf/message_remove" ynh_send_readme_to_admin --app_message="../conf/message_remove" --recipients=$admin_email --type='remove' diff --git a/scripts/restore b/scripts/restore index 1b90ec6..11520e9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -34,6 +34,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=psql_db) db_user=$app db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -84,12 +85,10 @@ chown -R $app:$app $final_path #================================================= ynh_script_progression --message="Restoring data directory..." --weight=2 -datadir="/home/yunohost.app/$app" - # Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. ynh_restore_file --origin_path="$datadir" --not_mandatory -mkdir -p "$datadir/storage" +mkdir -p "$datadir" # Give permission to the datadir chown -R "$app":"$app" "$datadir" @@ -137,7 +136,7 @@ systemctl enable $app.service #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log" +yunohost service add $app --description "$app daemon for Peertube" --log "$datadir/logs/peertube.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 8e94a0d..063997c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,6 +24,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=psql_db) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK VERSION @@ -46,6 +47,12 @@ elif [ "$is_public" = "No" ]; then is_public=0 fi +if [ -z "$datadir" ]; +then + datadir="/home/yunohost.app/${app}/storage" + ynh_app_setting_set --app=$app --key=datadir --value=$datadir +fi + # Close a port if yunohost firewall list | grep -q "\- $port$" then @@ -129,7 +136,7 @@ fi ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "datadir" #================================================= # UPGRADE DEPENDENCIES @@ -171,9 +178,6 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Creating the data directory..." -# Define app's data directory -datadir="/home/yunohost.app/${app}/storage" - if [ ! -d "$datadir" ] then # Create app folders @@ -197,6 +201,7 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_email" --target_file="$config" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" +ynh_replace_string --match_string="__DATADIR__" --replace_string="$datadir" --target_file="$config" ynh_store_file_checksum --file="$config" local_config="$final_path/config/local-production.json" From 477704aab7e249c82e462b39bb9e020efde223d1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 27 Sep 2020 19:00:57 +0200 Subject: [PATCH 6/7] Typo --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 11520e9..b5a143d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -83,7 +83,7 @@ chown -R $app:$app $final_path #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring data directory..." --weight=2 +ynh_script_progression --message="Restoring data directory..." # Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. ynh_restore_file --origin_path="$datadir" --not_mandatory From 7e4b3c678cc1626ca3eca6b0971be70e74682147 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 8 Oct 2020 01:33:09 +0200 Subject: [PATCH 7/7] Implement backup_core_only --- scripts/upgrade | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 547fa0c..c16f112 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -73,8 +73,16 @@ ynh_secure_remove --file="/etc/apt/sources.list.d/yarn.list" #================================================= ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." +# Inform the backup/restore process that it should not save the data directory +# Use only for the previous backup script that doesn't set 'is_big' +ynh_app_setting_set --app=$app --key=backup_core_only --value=1 + # Backup the current version of the app ynh_backup_before_upgrade + +# Remove the option backup_core_only after the backup. +ynh_app_setting_delete --app=$app --key=backup_core_only + ynh_clean_setup () { # restore it if the upgrade fails ynh_clean_check_starting