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

41 lines
1.3 KiB
Django/Jinja

#!/bin/bash
set -e
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 {{ app }} passphrase)"
RESTIC_REPOSITORY_BASE=sftp://$RESTIC_SERVER_USER@$RESTIC_SERVER:$RESTIC_SERVER_PORT/$RESTIC_PATH/
RESTIC_COMMAND={{ install_dir }}/{{ app }}
do_check() {
local name="$1"
local check_read_data="$2"
export RESTIC_PASSWORD
export RESTIC_REPOSITORY=${RESTIC_REPOSITORY_BASE}/$name
LOGFILE=/var/log/restic_check_{{ app }}.log
ERRFILE=/var/log/restic_check_{{ app }}.err
current_date=$(date --iso-8601=seconds)
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
$RESTIC_COMMAND check --read-data > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
else
$RESTIC_COMMAND check > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
fi
echo -e "END REPO CHECK: ${name}" | tee -a ${LOGFILE} | tee -a ${ERRFILE}
check_return_code="$?"
return "${check_return_code}"
}
name=$1
check_read_data=${2:-0}
do_check "${name}" "${check_read_data}"
exit 0