nextcloud-backups/backup_total.sh

38 lines
1.1 KiB
Bash

#!/bin/bash
PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
#Use backup_inc.sh <logfile> <origin_data_path> <remote_server> <remote_path>
LOG_FILE=$1
BACKUP_DIR="nextcloud-datatotal_"`date +\%Y\%m\%d`"/"
EXCLUDE_FILE="file-list.txt"
ORIGIN_DATA_PATH=$2
REMOTE_SERVER=$3
REMOTE_PATH=$4
LATEST_LINK="latest"
CURRENT_DATE=`date +\%y\%m\%d\%H\%M.\%S`
touch $EXCLUDE_FILE
cat > $EXCLUDE_FILE <<EOF
files_trashbin
nextcloud.log
updater.log
EOF
echo "\n[NEW BACKUP TASK] Backup cloud all files (total)\n" >> $LOG_FILE
# rsync of new files last day into nextcloud every day (incremental)
rsync -AaxzvPh $ORIGIN_DATA_PATH --exclude-from=$EXCLUDE_FILE "$REMOTE_SERVER:$REMOTE_PATH$BACKUP_DIR" >> $LOG_FILE
# set current date to sync remote folder
ssh $REMOTE_SERVER "touch -t $CURRENT_DATE $REMOTE_PATH$BACKUP_DIR 2>&1" >> $LOG_FILE
# replace latest
ssh $REMOTE_SERVER "rm -rf $REMOTE_PATH$LATEST_LINK && ln -s $REMOTE_PATH$BACKUP_DIR $REMOTE_PATH$LATEST_LINK 2>&1" >> $LOG_FILE
rm $EXCLUDE_FILE
echo "\n[DONE BACKUPS] handycat total backup completed!\n" >> $LOG_FILE
echo "########################################################" >> $LOG_FILE