From bae5b36e7b648baf3e9453c06b02699d803af3e4 Mon Sep 17 00:00:00 2001 From: ljf Date: Sun, 28 Mar 2021 16:16:01 +0200 Subject: [PATCH] [fix] Some bugs found on Aleks review --- check_process | 2 +- conf/backup-with-borg | 30 +++++++++++++----------------- manifest.json | 2 +- scripts/install | 4 ++-- scripts/remove | 1 + scripts/upgrade | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/check_process b/check_process index 363a988..c712791 100644 --- a/check_process +++ b/check_process @@ -1,6 +1,6 @@ ;; Test complet ; Manifest - server="ssh://sam@domain.tld:22/~/backup" + repository="ssh://sam@domain.tld:22/~/backup" passphrase="APassphrase" conf=1 data=1 diff --git a/conf/backup-with-borg b/conf/backup-with-borg index 38f1f00..e202f3a 100644 --- a/conf/backup-with-borg +++ b/conf/backup-with-borg @@ -3,20 +3,16 @@ # We don't stop the script on errors cause we want to backup all data we could backuped #set -eu -app=$1 +borg_id=$1 errors="" current_date=$(date +"%y%m%d_%H%M") -log_file="/var/log/$app/$current_date.log" -err_file="/var/log/$app/$current_date.err" -mkdir -p "/var/log/$app" - -# Adapt this script to different API 2.x vs 3.x -if yunohost -v | grep "version: 2." > /dev/null; then - ignore_apps="--ignore-apps" - ignore_system="--ignore-system" -else - ignore_apps="" - ignore_system="" +log_file="/var/log/${borg_id}/${current_date}.log" +err_file="/var/log/${borg_id}/${current_date}.err" +mkdir -p "/var/log/${borg_id}" +if [[ -z "$borg_id" ]] +then + echo "This script expects a borg app id as first argument" >&2 + exit 1 fi filter_hooks() { @@ -28,10 +24,10 @@ fail_if_partially_failed() { } # Backup system part conf -conf=$(yunohost app setting $app conf) +conf=$(yunohost app setting ${borg_id} conf) if [ $conf -eq 1 ] then - if ! yunohost backup create $ignore_apps -n auto_conf --method $app_app --system $(filter_hooks conf) 2> $err_file > $log_file ; then + if ! yunohost backup create -n auto_conf --method ${borg_id}_app --system $(filter_hooks conf) 2> $err_file > $log_file ; then errors="$errors\nconf: Error" fi fi @@ -40,13 +36,13 @@ fi data=$(yunohost app setting $app data) if [ $data -eq 1 ] then - if ! yunohost backup create $ignore_apps -n auto_data --method $app_app --system $(filter_hooks data) 2> $err_file > $log_file ; then + if ! yunohost backup create -n auto_data --method ${borg_id}_app --system $(filter_hooks data) 2> $err_file > $log_file ; then errors="$errors\ndata: Error" fi fi # Backup all apps independently -apps=$(yunohost app setting $app apps) +apps=$(yunohost app setting ${borg_id} apps) for application in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do backup_app=false if [[ "$apps" = "all" ]]; then @@ -60,7 +56,7 @@ for application in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do done fi if [ "$backup_app" == "true" ];then - if ! yunohost backup create $ignore_system -n auto_$application --method $app_app --apps $app 2> $err_file > $log_file ; then + if ! yunohost backup create -n auto_$application --method ${borg_id}_app --apps $application 2> $err_file > $log_file ; then errors="$errors\$application: Error" fi fi diff --git a/manifest.json b/manifest.json index 10f8b83..1f075b3 100644 --- a/manifest.json +++ b/manifest.json @@ -29,7 +29,7 @@ "fr": "Dans quel repo borg souhaitez-vous sauvegarder vos fichiers ?" }, "help":{ - "en": "You can specify a local by giving direct path or a remote repo in this format: ssh://USER@DOMAIN.TLD:PORT/~/backup . For remote user, it is not meant to be an existing user on the guest server. Instead, it will be created *on the host server* during the installation of the Borg Server App." + "en": "Specify a remote repository using this format: ssh://USER@DOMAIN.TLD:PORT/~/backup . "USER" is *not* meant to be an existing user on the guest server. Instead, it will be created *on the host server* during the installation of the Borg Server App. It's also possible to use a local repository using a syntax such as /mount/my_external_harddrive/backups" }, "example": "ssh://john@serverb.tld:22/~/backup" }, diff --git a/scripts/install b/scripts/install index 85610c6..1ef275f 100755 --- a/scripts/install +++ b/scripts/install @@ -77,7 +77,7 @@ if [ ! -z "$server" ]; then # Display key #================================================= - echo "You should now install the \"Borg Server\" app on $server and fill questions like this: + echo "You should now install the \"Borg Server\" app on $server and with the following credentials: User: ${ssh_user} Public key: $(cat ${private_key}.pub)" @@ -86,7 +86,7 @@ if [ ! -z "$server" ]; then #================================================= ynh_print_OFF - message="You should now install the \"Borg Server\" app on $server and fill questions like this: + message="You should now install the \"Borg Server\" app on $server and with the following credentials: User: ${ssh_user} Public key: $(cat ${private_key}.pub) diff --git a/scripts/remove b/scripts/remove index 27cea14..e3da1d5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -43,6 +43,7 @@ ynh_secure_remove "/etc/systemd/system/$app.timer" ynh_secure_remove "/usr/local/bin/backup-with-$app" ynh_secure_remove "/etc/yunohost/hooks.d/backup_method/05-${app}_app" +# Remove borg if we are removing the last borg app on the system if [ "$(yunohost app list | grep "id: borg" | wc -l)" == "1" ] ; then ynh_secure_remove "/opt/borg-env" ynh_secure_remove "/usr/local/bin/borg" diff --git a/scripts/upgrade b/scripts/upgrade index 01a026c..9ebde06 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -67,7 +67,7 @@ if grep "borg.timer" /etc/yunohost/services.yml > /dev/null ; then fi # Replace backports with pip -rm -f /etc/apt/sources.list.d/$app-stretch-backports.list +[ ! -e " /etc/apt/sources.list.d/$app-stretch-backports.list" ] || rm -f /etc/apt/sources.list.d/$app-stretch-backports.list # Reinstall borg if stretch -> buster migration if is_buster; then