2020-03-02 22:11:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-02-28 16:38:35 +01:00
|
|
|
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)
|
2020-11-08 17:42:25 +01:00
|
|
|
|
2021-02-28 16:38:35 +01:00
|
|
|
RESTIC_PASSWORD="$(yunohost app setting {{ app }} passphrase)"
|
2021-02-18 17:01:57 +01:00
|
|
|
RESTIC_REPOSITORY_BASE=sftp://$RESTIC_SERVER_USER@$RESTIC_SERVER:$RESTIC_SERVER_PORT/$RESTIC_PATH/
|
2020-11-08 17:42:25 +01:00
|
|
|
|
2021-02-28 16:38:35 +01:00
|
|
|
RESTIC_COMMAND=/usr/local/bin/{{ app }}
|
2020-03-02 22:11:41 +01:00
|
|
|
|
|
|
|
do_check() {
|
|
|
|
|
|
|
|
local name="$1"
|
|
|
|
local check_read_data="$2"
|
|
|
|
export RESTIC_PASSWORD
|
|
|
|
export RESTIC_REPOSITORY=${RESTIC_REPOSITORY_BASE}/$name
|
2021-02-28 16:38:35 +01:00
|
|
|
LOGFILE=/var/log/restic_check_{{ app }}.log
|
|
|
|
ERRFILE=/var/log/restic_check_{{ app }}.err
|
2020-03-02 22:11:41 +01:00
|
|
|
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
|
2020-03-03 19:24:13 +01:00
|
|
|
$RESTIC_COMMAND check --read-data > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
|
2020-03-02 22:11:41 +01:00
|
|
|
else
|
2020-03-03 19:24:13 +01:00
|
|
|
$RESTIC_COMMAND check > >(tee -a $LOGFILE) 2> >(tee -a $ERRFILE >&2)
|
2020-03-02 22:11:41 +01:00
|
|
|
fi
|
|
|
|
check_return_code="$?"
|
|
|
|
return "${check_return_code}"
|
|
|
|
}
|
|
|
|
|
|
|
|
name=$1
|
|
|
|
check_read_data=${2:-0}
|
|
|
|
|
|
|
|
do_check "${name}" "${check_read_data}"
|
|
|
|
|
|
|
|
exit 0
|