#!/bin/bash

SRCNAME="appdata/xeoma"
DSTDIR="/mnt/user/Public/Restore"
LOGFILENAME="dup_restore.log"
LOGDIR="/mnt/user/logs/Duplicity/${LOGFILENAME}"
DOCKERDIR="/mnt/user/appdata/dup_backup"
CACHEDIR="${DOCKERDIR}/.cache:/home/duplicity/.cache/duplicity"
ARCHIVEDIR="${DOCKERDIR}/archive"
SRCDIR="/mnt/user/Google/gdrive/Backup/Ket/Duplicity"
KEYDIR="${DOCKERDIR}/.gnupg:/home/duplicity/.gnupg"
BOTODIR="${DOCKERDIR}/.boto:/home/duplicity/.boto:ro"
PASSPHRASE="fjK8UH3hVvNimTvkmMMt7DhesJ"

echo " " >> "${LOGDIR}"
echo "****************************************************" >> "${LOGDIR}"
echo "$(date "+%d/%m/%Y %T") Starting ${SRCNAME} Restore" >> "${LOGDIR}"
echo "****************************************************" >> "${LOGDIR}"
echo " "
  docker run --rm \
-v "${SRCDIR}/${SRCNAME}:/src:ro" \
-v "${DSTDIR}/${SRCNAME}:/dst" \
-v "${ARCHIVEDIR}:/archive" \
-v "${CACHEDIR}" \
-v "${KEYDIR}" \
-v "${BOTODIR}" \
-v "${LOGDIR}:/logs" \
-v "/etc/localtime:/etc/localtime:ro" \
-e "TZ=Europe/Paris" \
-e "PASSPHRASE=${PASSPHRASE}" \
wernight/duplicity duplicity restore \
--allow-source-mismatch \
--full-if-older-than=1M \
--log-file "/logs" \
--verbosity 4 \
--name="${SRCNAME}" \
--archive-dir="/archive" \
file://src /dst
echo "****************************************************" >> "${LOGDIR}"
echo "$(date "+%d/%m/%Y %T") End ${SRCNAME} Restore" >> "${LOGDIR}"
echo "****************************************************" >> "${LOGDIR}"
echo " " >> "${LOGDIR}"