Scripts to do backups of nextcloud data, database and nextcloud files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nextcloud-backups/backup_inc.sh

39 lines
1.2 KiB

#!/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-datainc_"`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
ssh $REMOTE_SERVER "mkdir -p $REMOTE_PATH"
echo "\n[NEW BACKUP TASK] Backup cloud new/modified files of last day (incremental)\n" >> $LOG_FILE
# rsync of new files last day into nextcloud every day (incremental)
rsync -AaxzvPh --delete $ORIGIN_DATA_PATH --link-dest "../$LATEST_LINK" --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 incremental backup completed!\n" >> $LOG_FILE
echo "########################################################" >> $LOG_FILE