1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/restic_ynh.git synced 2024-09-03 20:16:22 +02:00

Merge branch 'testing'

This commit is contained in:
Lionel Coupouchetty-Ramouchetty 2020-11-18 19:04:52 +01:00
commit 3b056e3a1b
5 changed files with 88 additions and 3 deletions

15
conf/restic_log.j2 Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
set -u
invocation_id=$(systemctl show -p InvocationID --value {{ app }}.service)
hostname=$(hostname)
subject="YunoHost Restic backup log on ${hostname}"
backup_results=$(/bin/journalctl _SYSTEMD_INVOCATION_ID=${invocation_id} | grep -oP '(?<= )[a-zA-Z_-]+: \w+')
echo ${backup_results} | grep -iqE 'error|fail'
if [ "$?" -eq 0 ];then
subject="${subject} (FAIL)"
else
subject="${subject} (SUCCESS)"
fi
echo "${backup_results}" | mail -s "${subject}" root

View file

@ -5,7 +5,7 @@ After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup-with-__APP__
ExecStartPost=/bin/bash -c 'echo -e "Subject: YunoHost Restic backup log on $(hostname)\n$(/bin/journalctl _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value __APP__.service`)" | /usr/sbin/sendmail root'
ExecStartPost=/opt/yunohost/__APP__/restic_log
User=root
Group=root

View file

@ -6,7 +6,7 @@
"en": "Backup your server with restic.",
"fr": "Sauvegardez votre serveur avec restic."
},
"version": "0.10.0~ynh3",
"version": "0.10.0~ynh4",
"url": "https://restic.net/",
"license": "BSD-2-Clause",
"maintainer": {

View file

@ -50,6 +50,13 @@ 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"
#=================================================
# 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"
#=================================================
# CONFIGURE CRON
#=================================================

View file

@ -13,7 +13,21 @@ source /usr/share/yunohost/helpers
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
export app=$YNH_APP_INSTANCE_NAME
export final_path="/opt/yunohost/${app}"
export server=$(ynh_app_setting_get $app server)
export port=$(ynh_app_setting_get $app port)
export ssh_user=$(ynh_app_setting_get $app ssh_user)
export backup_path=$(ynh_app_setting_get $app backup_path)
export passphrase=$(ynh_app_setting_get $app passphrase)
export on_calendar=$(ynh_app_setting_get $app on_calendar)
export check_on_calendar=$(ynh_app_setting_get $app check_on_calendar)
export check_read_data_on_calendar=$(ynh_app_setting_get $app check_read_data_on_calendar)
export conf=$(ynh_app_setting_get $app conf)
export data=$(ynh_app_setting_get $app data)
export apps=$(ynh_app_setting_get $app apps)
export allow_extra_space_use=$(ynh_app_setting_get $app allow_extra_space_use)
#=================================================
# CHECK IF AN UPGRADE IS NEEDED
@ -43,4 +57,53 @@ fi
#=================================================
# INSTALL RESTIC
#=================================================
ynh_script_progression --message="Installing restic binary" --weight=7
install_restic
#=================================================
# ACTIVATE BACKUP METHODS
#=================================================
ynh_script_progression --message="Activating backup methods"
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
#=================================================
# SETUP THE 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"
#=================================================
# 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"
#=================================================
# CONFIGURE CRON
#=================================================
ynh_script_progression --message="Configuring cron" --weight=5
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"
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
ynh_configure systemd.timer "/etc/systemd/system/${app}.timer"
ynh_configure systemd_check.timer "/etc/systemd/system/${app}_check.timer"
ynh_configure systemd_check_read_data.timer "/etc/systemd/system/${app}_check_read_data.timer"
systemctl disable ${app}.service
systemctl disable ${app}_check.service
systemctl disable ${app}_check_read_data.service
systemctl enable ${app}.timer
systemctl enable ${app}_check.timer
systemctl enable ${app}_check_read_data.timer
systemctl start ${app}.timer
systemctl start ${app}_check.timer
systemctl start ${app}_check_read_data.timer
ynh_script_progression --message="End of upgrade process" --last