scripts/download-with-sftp.sh

26 lines
789 B
Bash
Executable File

#!/bin/bash
export BORG_PASSPHRASE="$(cat /root/secret/borg-snowboard.key)"
if [[ -z "${BORG_PASSPHRASE}" ]]; then
echo 'BORG_PASSPHRASE is not set, cannot continue'
exit
fi
cd /srv/data/backup/borg/snowboard
mkdir -p old
mv data* old
backupdir="data-$(date -I)"
mkdir -p $backupdir
cd $backupdir
sftp fileserver@cscherr.de < /usr/local/cron/sftp-commands.txt
status_download=$?
echo "finished downloading from snowboard. Status: $status_download"
borg check -v data/backup/borg/snowboard
status_check=$?
echo "finished checking the downloaded repo. Status: $status_check"
if [ "$status_check" -eq "0" ]; then
cd /srv/data/backup/borg/snowboard
rm -r old
else
echo "the new repo was not checked successfully, keeping old repo."
fi
echo $(date +"%Y-%m-%dT%H:%M:%S%z")