diff --git a/README.md b/README.md index 2e7d16a..ed98652 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ A [Restic](https://restic.net/) package for YunoHost (heavily inspired by [the B Restic is a backup tool that can make local and remote backups. This package uses restic to make backups to a sftp server. +The package does not handle local backups yet but you can work around that by using the local sftp server as target server (see my comment [here](https://forum.yunohost.org/t/sauvegarde-yunohost-avec-restic/10275/33)). ## Usage diff --git a/conf/backup_method.j2 b/conf/backup_method.j2 index 9445f7f..ace6747 100644 --- a/conf/backup_method.j2 +++ b/conf/backup_method.j2 @@ -5,17 +5,17 @@ set -e ### # Fetch information from YNH settings ### -RESTIC_SERVER=$(yunohost app setting restic server) -RESTIC_SERVER_PORT=$(yunohost app setting restic port) -RESTIC_SERVER_USER=$(yunohost app setting restic ssh_user) -RESTIC_PATH=$(yunohost app setting restic backup_path) +RESTIC_SERVER=$(yunohost app setting {{ app }} server) +RESTIC_SERVER_PORT=$(yunohost app setting {{ app }} port) +RESTIC_SERVER_USER=$(yunohost app setting {{ app }} ssh_user) +RESTIC_PATH=$(yunohost app setting {{ app }} backup_path) -RESTIC_PASSWORD="$(yunohost app setting restic passphrase)" +RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)" RESTIC_REPOSITORY_BASE=sftp://$RESTIC_SERVER_USER@$RESTIC_SERVER:$RESTIC_SERVER_PORT/$RESTIC_PATH/ -RESTIC_COMMAND=/usr/local/bin/restic -LOGFILE=/var/log/restic_backup.log -ERRFILE=/var/log/restic_backup.err +RESTIC_COMMAND=/usr/local/bin/{{ app }} +LOGFILE=/var/log/restic_backup_{{ app }}.log +ERRFILE=/var/log/restic_backup_{{ app }}.err do_need_mount() { work_dir="$1" diff --git a/conf/check-restic.j2 b/conf/check-restic.j2 index a9d404f..2113bc8 100644 --- a/conf/check-restic.j2 +++ b/conf/check-restic.j2 @@ -20,13 +20,13 @@ CHECK_READ_DATA=${1:-0} # Check system part conf conf=$(yunohost app setting {{ app }} conf) if [ $conf -eq 1 ];then - {{final_path}}/check_method auto_conf ${CHECK_READ_DATA} + {{final_path}}/check_method_{{ app }} auto_conf ${CHECK_READ_DATA} fi # Check system data data=$(yunohost app setting {{ app }} data) if [ $data -eq 1 ];then - {{final_path}}/check_method auto_data ${CHECK_READ_DATA} + {{final_path}}/check_method_{{ app }} auto_data ${CHECK_READ_DATA} fi # Check all apps independently @@ -40,7 +40,7 @@ for app in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do fi done if [ "$check_app" == "true" ];then - {{final_path}}/check_method auto_${app} ${CHECK_READ_DATA} + {{final_path}}/check_method_{{ app }} auto_${app} ${CHECK_READ_DATA} fi done rm "$LOCK_FILE" diff --git a/conf/check_method.j2 b/conf/check_method.j2 index ef8058c..5fa488b 100644 --- a/conf/check_method.j2 +++ b/conf/check_method.j2 @@ -2,15 +2,15 @@ set -e -RESTIC_SERVER=$(yunohost app setting restic server) -RESTIC_SERVER_PORT=$(yunohost app setting restic port) -RESTIC_SERVER_USER=$(yunohost app setting restic ssh_user) -RESTIC_PATH=$(yunohost app setting restic backup_path) +RESTIC_SERVER=$(yunohost app setting {{ app }} server) +RESTIC_SERVER_PORT=$(yunohost app setting {{ app }} port) +RESTIC_SERVER_USER=$(yunohost app setting {{ app }} ssh_user) +RESTIC_PATH=$(yunohost app setting {{ app }} backup_path) -RESTIC_PASSWORD="$(yunohost app setting restic passphrase)" +RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)" RESTIC_REPOSITORY_BASE=sftp://$RESTIC_SERVER_USER@$RESTIC_SERVER:$RESTIC_SERVER_PORT/$RESTIC_PATH/ -RESTIC_COMMAND=/usr/local/bin/restic +RESTIC_COMMAND=/usr/local/bin/{{ app }} do_check() { @@ -18,8 +18,8 @@ do_check() { local check_read_data="$2" export RESTIC_PASSWORD export RESTIC_REPOSITORY=${RESTIC_REPOSITORY_BASE}/$name - LOGFILE=/var/log/restic_check.log - ERRFILE=/var/log/restic_check.err + LOGFILE=/var/log/restic_check_{{ app }}.log + ERRFILE=/var/log/restic_check_{{ app }}.err current_date=$(date +"%d_%m_%y_%H:%M") echo -e "\n==============\n${current_date}\n==============\n" | tee -a ${LOGFILE} | tee -a ${ERRFILE} if [ "$check_read_data" -eq "1" ];then diff --git a/conf/systemd.service b/conf/systemd.service index 1647e27..33fc4ce 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -5,7 +5,7 @@ After=network.target [Service] Type=oneshot ExecStart=/usr/local/bin/backup-with-__APP__ -ExecStartPost=/opt/yunohost/__APP__/restic_log +ExecStartPost=/opt/yunohost/__APP__/restic_log___APP__ User=root Group=root diff --git a/manifest.json b/manifest.json index ff244bd..6b96513 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Backup your server with restic.", "fr": "Sauvegardez votre serveur avec restic." }, - "version": "0.12.0~ynh1", + "version": "0.12.0~ynh2", "url": "https://restic.net/", "license": "BSD-2-Clause", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 181f71b..6484835 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -32,8 +32,8 @@ install_restic () { sum=$(sha256sum /tmp/restic.bz2 | awk '{print $1}') if [ "$sum" == "$expected_sum" ];then pkill restic || true - bunzip2 /tmp/restic.bz2 -f -c > /usr/local/bin/restic - chmod +x /usr/local/bin/restic + bunzip2 /tmp/restic.bz2 -f -c > /usr/local/bin/${app} + chmod +x /usr/local/bin/${app} else ynh_die --message="\nDownloaded file does not match expected sha256 sum, aborting" fi diff --git a/scripts/install b/scripts/install index 6a11b7e..610dfcb 100755 --- a/scripts/install +++ b/scripts/install @@ -48,14 +48,14 @@ mkdir -p /usr/share/yunohost/backup_method #================================================= ynh_script_progression --message="Setting up backup methods" ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app" -ynh_configure check_method "${final_path}/check_method" +ynh_configure check_method "${final_path}/check_method_${app}" #================================================= # SETUP LOG SCRIPT #================================================= ynh_script_progression --message="Setting up log script" -ynh_configure restic_log "${final_path}/restic_log" -chmod u+x "${final_path}/restic_log" +ynh_configure restic_log "${final_path}/restic_log_${app}" +chmod u+x "${final_path}/restic_log_${app}" #================================================= # CONFIGURE CRON @@ -65,7 +65,7 @@ ynh_configure backup-with-restic "/usr/local/bin/backup-with-${app}" ynh_configure check-restic "${final_path}/check-${app}" chmod u+x "/usr/local/bin/backup-with-${app}" chmod u+x "${final_path}/check-${app}" -chmod u+x "${final_path}/check_method" +chmod u+x "${final_path}/check_method_${app}" ynh_add_systemd_config --service=${app} --template=systemd.service ynh_add_systemd_config --service=${app}_check --template=systemd_check.service ynh_add_systemd_config --service=${app}_check_read_data --template=systemd_check_read_data.service @@ -92,8 +92,9 @@ test -f $private_key || ssh-keygen -q -t ed25519 -N "" -f $private_key #================================================= # GENERATE SSH CONFIG #================================================= -ynh_script_progression --message="Generating ssh config for ${server}" -grep -q "${server}" /root/.ssh/config 2>/dev/null || cat << EOCONF >> ~/.ssh/config +ynh_script_progression --message="Generating ssh config for ${app} server ${server}" +grep -q "${app}" /root/.ssh/config 2>/dev/null || cat << EOCONF >> ~/.ssh/config +# begin $app ssh config Host ${server} Hostname ${server} Port ${port} @@ -101,6 +102,7 @@ Host ${server} IdentityFile ${private_key} StrictHostKeyChecking no UserKnownHostsFile /dev/null +# end $app ssh config EOCONF #================================================= @@ -119,7 +121,7 @@ ynh_print_OFF message="You should now allow the following public key for user ${ssh_user} on server ${server}: $(cat ${private_key}.pub) -Do so by running this command on ${server} with user ${ssh_user}: +Do so by running those commands on ${server} with user ${ssh_user}: mkdir ~/.ssh 2>/dev/null touch ~/.ssh/authorized_keys @@ -130,7 +132,7 @@ EOPKEY $(if [ "$backup_path" != "./" ];then echo "Also make sure ${backup_path} exists and is writable by ${ssh_user}";fi) -If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/restic_ynh" +If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/restic_ynh" ynh_send_readme_to_admin "$message" "root" ynh_print_ON diff --git a/scripts/remove b/scripts/remove index 00eede2..0400d37 100755 --- a/scripts/remove +++ b/scripts/remove @@ -36,7 +36,7 @@ ynh_secure_remove "/etc/systemd/system/${app}_check.timer" ynh_secure_remove "/etc/systemd/system/${app}_check_read_data.timer" ynh_secure_remove "/usr/local/bin/backup-with-${app}" ynh_secure_remove "/etc/yunohost/hooks.d/backup_method/05-${app}_app" -ynh_secure_remove "${final_path}/check_method" +ynh_secure_remove "${final_path}/check_method_${app}" ynh_secure_remove "${final_path}/check-${app}" ynh_secure_remove "${final_path}" @@ -44,4 +44,4 @@ ynh_secure_remove "${final_path}" # REMOVE SSH CONFIG #================================================= ynh_script_progression --message="Removing ssh config" --last -sed -e "/Host ${server}/,+6d" /root/.ssh/config -i || true +sed -e "/begin ${app}/,/end ${app}/{/.*/d}" /root/.ssh/config -i || true diff --git a/scripts/upgrade b/scripts/upgrade index a3093e6..c164fca 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -48,7 +48,7 @@ ynh_clean_setup () { ynh_abort_if_errors -if grep "restic.timer" /etc/yunohost/services.yml > /dev/null ; then +if grep "${app}.timer" /etc/yunohost/services.yml > /dev/null ; then yunohost service remove $app.timer systemctl --quiet enable $app.timer systemctl start $app.timer @@ -72,14 +72,14 @@ mkdir -p /usr/share/yunohost/backup_method #================================================= ynh_script_progression --message="Setting up backup methods" ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app" -ynh_configure check_method "${final_path}/check_method" +ynh_configure check_method "${final_path}/check_method_${app}" #================================================= # SETUP LOG SCRIPT #================================================= ynh_script_progression --message="Setting up log script" -ynh_configure restic_log "${final_path}/restic_log" -chmod u+x "${final_path}/restic_log" +ynh_configure restic_log "${final_path}/restic_log_${app}" +chmod u+x "${final_path}/restic_log_${app}" #================================================= # CONFIGURE CRON @@ -89,7 +89,7 @@ ynh_configure backup-with-restic "/usr/local/bin/backup-with-${app}" ynh_configure check-restic "${final_path}/check-${app}" chmod u+x "/usr/local/bin/backup-with-${app}" chmod u+x "${final_path}/check-${app}" -chmod u+x "${final_path}/check_method" +chmod u+x "${final_path}/check_method_${app}" ynh_add_systemd_config --service=${app} --template=systemd.service ynh_add_systemd_config --service=${app}_check --template=systemd_check.service ynh_add_systemd_config --service=${app}_check_read_data --template=systemd_check_read_data.service @@ -107,3 +107,29 @@ systemctl start ${app}_check.timer systemctl start ${app}_check_read_data.timer ynh_script_progression --message="End of upgrade process" --last + +#================================================= +# UPGRADE SSH CONFIG +#================================================= + +# old versions did not have delimiters in /root/.ssh/config +# making removal in multi-instance cases break the remaining +# instances. +# So we need to add the delimiters if they are missing +grep -q "begin ${app}" /root/.ssh/config +missing_delimiters="$?" +if [ "$missing_delimiters" -eq 1 ];then + # did not find delimiters so removing old configuration + sed -e "/Host ${server}/,+6d" /root/.ssh/config -i || true + cat << EOCONF >> ~/.ssh/config + # begin $app ssh config + Host ${server} + Hostname ${server} + Port ${port} + User ${ssh_user} + IdentityFile ${private_key} + StrictHostKeyChecking no + UserKnownHostsFile /dev/null + # end $app ssh config +EOCONF +fi