scripts/borg.sh
2022-08-24 16:40:31 +02:00

55 lines
1.9 KiB
Bash
Executable file

export BORG_REPO='/storage/backup'
export BORG_PASSPHRASE='discount-wham-untruth-apostle-mastiff-expand-foster-zealous-tricky'
export CLOUDDEST='backup_1:/backup'
export BORG_CACHE_DIR='/storage/backup/user/appdata/borg/cache/'
export BORG_BASE_DIR='/storage/backup/user/appdata/borg/'
echo "$(date "+%m-%d-%Y %T") : Borg backup has started" 2>&1 | tee -a $LOGFILE
SECONDS=0
borg create \
--verbose \
--info \
--list \
--stats \
--show-rc \
--compression lz4 \
--exclude-caches \
$BORG_REPO::"root-{now:%Y-%m-%d}" \
/home \
/etc \
/usr/src/linux \
backup_exit=$?
borg prune \
--list \
--prefix "$(hostname)-" \
--show-rc \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6 \
prune_exit=$?
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
if [ ${global_exit} -eq 0 ];
then
borgstart=$SECONDS
echo "$(date "+%m-%d-%Y %T") : Borg backup completed in $(($borgstart/ 3600))h:$(($borgstart% 3600/60))m:$(($borgstart% 60))s" | tee -a >> $LOGFILE 2>&1
#Reset timer
SECONDS=0
echo "$(date "+%m-%d-%Y %T") : Rclone Borg sync has started" >> $LOGFILE
rclone sync $BORG_REPO $CLOUDDEST -P --stats 1s -v 2>&1 | tee -a $LOGFILE
rclonestart=$SECONDS
echo "$(date "+%m-%d-%Y %T") : Rclone Borg sync completed in $(($rclonestart/ 3600))h:$(($rclonestart% 3600/60))m:$(($rclonestart% 60))s" 2>&1 | tee -a $LOGFILE
# All other errors
else
echo "$(date "+%m-%d-%Y %T") : Borg has errors code:" $global_exit 2>&1 | tee -a $LOGFILE
fi
exit ${global_exit}