scripts/download-with-sftp.sh

29 lines
864 B
Bash
Raw Normal View History

2023-06-11 18:15:30 +02:00
#!/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
2023-06-11 18:48:16 +02:00
REPO_ROOT=/srv/data/backup/borg/snowboard
SCRIPTS_DIR=/usr/local/cron/scripts
cd $REPO_ROOT
2023-06-11 18:15:30 +02:00
mkdir -p old
mv data* old
backupdir="data-$(date -I)"
mkdir -p $backupdir
cd $backupdir
2023-06-11 18:48:16 +02:00
sftp fileserver@cscherr.de < $SCRIPTS_DIR/sftp-commands.txt
2023-06-11 18:15:30 +02:00
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
2023-10-31 19:52:30 +01:00
cd $REPO_ROOT
chown fileserver:fileserver $backupdir
2023-06-11 18:15:30 +02:00
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")