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:
commit
cc15abae1b
9 changed files with 89 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
vagrant up
|
vagrant up
|
||||||
vagrant ssh -c "/package_check/package_check.sh /restic_ynh"
|
vagrant ssh -c "lxd init --auto;/package_check/package_check.sh /restic_ynh"
|
||||||
vagrant halt
|
vagrant halt
|
||||||
|
|
|
@ -20,13 +20,15 @@ do_check() {
|
||||||
export RESTIC_REPOSITORY=${RESTIC_REPOSITORY_BASE}/$name
|
export RESTIC_REPOSITORY=${RESTIC_REPOSITORY_BASE}/$name
|
||||||
LOGFILE=/var/log/restic_check_{{ app }}.log
|
LOGFILE=/var/log/restic_check_{{ app }}.log
|
||||||
ERRFILE=/var/log/restic_check_{{ app }}.err
|
ERRFILE=/var/log/restic_check_{{ app }}.err
|
||||||
current_date=$(date +"%d_%m_%y_%H:%M")
|
current_date=$(date --iso-8601=seconds)
|
||||||
echo -e "\n==============\n${current_date}\n==============\n" | tee -a ${LOGFILE} | tee -a ${ERRFILE}
|
echo -e "\n$current_date" | tee -a ${LOGFILE} | tee -a ${ERRFILE}
|
||||||
|
echo -e "BEGIN REPO CHECK: ${name}" | tee -a ${LOGFILE} | tee -a ${ERRFILE}
|
||||||
if [ "$check_read_data" -eq "1" ];then
|
if [ "$check_read_data" -eq "1" ];then
|
||||||
$RESTIC_COMMAND check --read-data > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
|
$RESTIC_COMMAND check --read-data > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
|
||||||
else
|
else
|
||||||
$RESTIC_COMMAND check > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
|
$RESTIC_COMMAND check > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
|
||||||
fi
|
fi
|
||||||
|
echo -e "END REPO CHECK: ${name}" | tee -a ${LOGFILE} | tee -a ${ERRFILE}
|
||||||
check_return_code="$?"
|
check_return_code="$?"
|
||||||
return "${check_return_code}"
|
return "${check_return_code}"
|
||||||
}
|
}
|
||||||
|
|
65
conf/restic_check_log.j2
Normal file
65
conf/restic_check_log.j2
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -u
|
||||||
|
|
||||||
|
function parse_log {
|
||||||
|
# do not consider unset variables as an error
|
||||||
|
set +u
|
||||||
|
log="$@"
|
||||||
|
current_repo=''
|
||||||
|
repo_ok=0
|
||||||
|
check_log=''
|
||||||
|
echo -e "$log" | while read l;do
|
||||||
|
matched_repo=$(echo $l | grep -oP "(?<=BEGIN REPO CHECK: ).*")
|
||||||
|
if [ ! -z "$matched_repo" ];then
|
||||||
|
current_repo="$matched_repo"
|
||||||
|
fi
|
||||||
|
end_matched_repo=$(echo $l | grep -oP "(?<=END REPO CHECK: ).*")
|
||||||
|
if [ ! -z "$end_matched_repo" ];then
|
||||||
|
if [ "$repo_ok" -eq "1" ];then
|
||||||
|
echo -e "\n==> [OK] $current_repo"
|
||||||
|
else
|
||||||
|
echo -e "\n==> [ERROR] $current_repo"
|
||||||
|
echo -e "$current_log\n$l"
|
||||||
|
fi
|
||||||
|
current_repo=""
|
||||||
|
repo_ok=0
|
||||||
|
current_log=""
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo $l | grep -q "no errors were found"
|
||||||
|
if [ "$?" -eq 0 ];then
|
||||||
|
repo_ok=1
|
||||||
|
fi
|
||||||
|
if [ "$current_repo" != "" ];then
|
||||||
|
if [ -z "$current_log" ];then
|
||||||
|
current_log="${l}"
|
||||||
|
else
|
||||||
|
current_log="$current_log\n${l}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
set -u
|
||||||
|
}
|
||||||
|
|
||||||
|
COMPLETE_CHECK=${1:-0}
|
||||||
|
|
||||||
|
hostname=$(hostname)
|
||||||
|
if [ "$COMPLETE_CHECK" -eq "0" ];then
|
||||||
|
subject="YunoHost Restic check log on ${hostname}"
|
||||||
|
invocation_id=$(systemctl show -p InvocationID --value {{ app }}_check.service)
|
||||||
|
else
|
||||||
|
subject="YunoHost Restic complete check log on ${hostname}"
|
||||||
|
invocation_id=$(systemctl show -p InvocationID --value {{ app }}_check_read_data.service)
|
||||||
|
fi
|
||||||
|
check_log=$(sudo /bin/journalctl _SYSTEMD_INVOCATION_ID=${invocation_id})
|
||||||
|
parsed_log=$(parse_log "$check_log")
|
||||||
|
echo "$parsed_log" | grep -q '\[ERROR\]'
|
||||||
|
if [ "$?" -eq "0" ];then
|
||||||
|
subject="${subject} (FAILED)"
|
||||||
|
else
|
||||||
|
subject="${subject} (SUCCESS)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
parsed_log="$parsed_log\n\nTo get more detailed info check the log files /var/log/restic_check_{{ app }}.log and /var/log/restic_check_{{ app }}.err"
|
||||||
|
|
||||||
|
echo -e "${parsed_log}" | mail -s "${subject}" root
|
|
@ -5,7 +5,7 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=__FINALPATH__/check-__APP__
|
ExecStart=__FINALPATH__/check-__APP__
|
||||||
ExecStartPost=/bin/bash -c 'echo -e "Subject: YunoHost Restic check log on $(hostname)\n$(sudo /bin/journalctl _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value __APP___check.service`)" | /usr/sbin/sendmail root'
|
ExecStartPost=/opt/yunohost/__APP__/restic_check_log___APP__ 0
|
||||||
User=__APP__
|
User=__APP__
|
||||||
Group=__APP__
|
Group=__APP__
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=__FINALPATH__/check-__APP__ "1"
|
ExecStart=__FINALPATH__/check-__APP__ "1"
|
||||||
ExecStartPost=/bin/bash -c 'echo -e "Subject: YunoHost Restic complete check log on $(hostname)\n$(/bin/journalctl _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value __APP___check_read_data.service`)" | /usr/sbin/sendmail root'
|
ExecStartPost=/opt/yunohost/__APP__/restic_check_log___APP__ 1
|
||||||
User=__APP__
|
User=__APP__
|
||||||
Group=__APP__
|
Group=__APP__
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"en": "Backup your server with restic.",
|
"en": "Backup your server with restic.",
|
||||||
"fr": "Sauvegardez votre serveur avec restic."
|
"fr": "Sauvegardez votre serveur avec restic."
|
||||||
},
|
},
|
||||||
"version": "0.12.0~ynh6",
|
"version": "0.12.0~ynh7",
|
||||||
"url": "https://restic.net/",
|
"url": "https://restic.net/",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
|
|
@ -62,13 +62,18 @@ ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
ynh_configure check_method "${final_path}/check_method_${app}"
|
ynh_configure check_method "${final_path}/check_method_${app}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOG SCRIPT
|
# SETUP LOG SCRIPTS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Setting up log script"
|
ynh_script_progression --message="Setting up backup log script"
|
||||||
ynh_configure restic_log "${final_path}/restic_log_${app}"
|
ynh_configure restic_log "${final_path}/restic_log_${app}"
|
||||||
chmod +x "${final_path}/restic_log_${app}"
|
chmod +x "${final_path}/restic_log_${app}"
|
||||||
chown ${app}: "${final_path}/restic_log_${app}"
|
chown ${app}: "${final_path}/restic_log_${app}"
|
||||||
|
|
||||||
|
ynh_script_progression --message="Setting up check log script"
|
||||||
|
ynh_configure restic_check_log "${final_path}/restic_check_log_${app}"
|
||||||
|
chmod +x "${final_path}/restic_check_log_${app}"
|
||||||
|
chown ${app}: "${final_path}/restic_check_log_${app}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE CRON
|
# CONFIGURE CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -38,6 +38,8 @@ ynh_secure_remove "/usr/local/bin/backup-with-${app}"
|
||||||
ynh_secure_remove "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
ynh_secure_remove "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
ynh_secure_remove "${final_path}/check_method_${app}"
|
ynh_secure_remove "${final_path}/check_method_${app}"
|
||||||
ynh_secure_remove "${final_path}/check-${app}"
|
ynh_secure_remove "${final_path}/check-${app}"
|
||||||
|
ynh_secure_remove "${final_path}/restic_log_${app}"
|
||||||
|
ynh_secure_remove "${final_path}/restic_check_log_${app}"
|
||||||
ynh_secure_remove "${final_path}"
|
ynh_secure_remove "${final_path}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -111,13 +111,18 @@ ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
ynh_configure check_method "${final_path}/check_method_${app}"
|
ynh_configure check_method "${final_path}/check_method_${app}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOG SCRIPT
|
# SETUP LOG SCRIPTS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Setting up log script"
|
ynh_script_progression --message="Setting up backup log script"
|
||||||
ynh_configure restic_log "${final_path}/restic_log_${app}"
|
ynh_configure restic_log "${final_path}/restic_log_${app}"
|
||||||
chmod +x "${final_path}/restic_log_${app}"
|
chmod +x "${final_path}/restic_log_${app}"
|
||||||
chown ${app}: "${final_path}/restic_log_${app}"
|
chown ${app}: "${final_path}/restic_log_${app}"
|
||||||
|
|
||||||
|
ynh_script_progression --message="Setting up check log script"
|
||||||
|
ynh_configure restic_check_log "${final_path}/restic_check_log_${app}"
|
||||||
|
chmod +x "${final_path}/restic_check_log_${app}"
|
||||||
|
chown ${app}: "${final_path}/restic_check_log_${app}"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE CRON
|
# CONFIGURE CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue