#!/bin/bash
DIR=$(realpath $(dirname $0))
source $DIR/inc.sh

if [ -z "$2" ]; then
    echo "Usage $0 <restore_path> <destination_path> [timeago]"
    echo "restore_path      :   path to restore without leading slash"
    echo "destination_path  :   path to download the file(s), duplicity will not override existing files"
    echo "timeago           :   optionnal : the age of the version we want to restore, for instance 6D for 6 days ago"
    exit 1
fi

if [ ! -z "$3" ]; then
    delay="-t $3"
fi

export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"

/usr/bin/duplicity --file-to-restore $delay "$1" ftp://$user@$host/$remotedir/ "$2"

unset PASSPHRASE
unset FTP_PASSWORD