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_db.sh

26 lines
927 B

#!/bin/bash
PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
#Use backup_db.sh <logfile> <path_local_backups> <remote_server> <remote_path>
LOG_FILE=$1
BACKUP_FILE="nextcloud-sqlbkp-"`date +\%Y\%m\%d`".sql"
DB_HOST="localhost"
DB_USER="user"
DB_PASS="password"
DB_NAME="dbname"
PATH_LOCAL_BACKUPS=$2
REMOTE_SERVER=$3
REMOTE_PATH=$4
ssh $REMOTE_SERVER "mkdir -p $REMOTE_PATH"
echo "\n[NEW BACKUP TASK] Backup database nextcloud...\n" >> $LOG_FILE
# dump and backup db nextcloud handycat and rsync deleting origin
mysqldump --single-transaction --verbose -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME 2>> $LOG_FILE > $PATH_LOCAL_BACKUPS$BACKUP_FILE
rsync -AaxzPh --remove-source-files $PATH_LOCAL_BACKUPS$BACKUP_FILE "$REMOTE_SERVER:$REMOTE_PATH" >> $LOG_FILE
echo "\n[DONE BACKUPS] handycat db nextcloud backup completed!\n" >> $LOG_FILE
echo "########################################################" >> $LOG_FILE