Rsync scripts to backup your Nextcloud data to another machine.
The repository also includes mail scripts that sends mails with error logs and weekly logfiles to a specified receiver.
These scripts are made in Shell for Linux.
Tested using Nextcloud versions 18-20 and Ubuntu.
- Install Nextcloud and configure it
- Download this script (
git clone https://github.com/Cactooz/NextcloudRsync
) - Configure all variables (in
rsync.sh
andsendmail.py
) - Configure automatic executions (using crontab or similar)
Scripts that backups you Nextcloud using Rsync over SSH.
Supports both user folders and other files and folders.
Users are added in the USERNAMES
array in rsync.sh
.
Special jobs are added in the SPECIALJOBS
array in rsync.sh
.
Before use make sure to configure the following variables in rsync.sh
.
More information can be found in the file itself.
LOGFILE
- The file name of the logfile used (Recomended to leave untouched)LOGPATH
- The file path to the logfile used (Recomended to leave untouched)SOURCEPATH
- Path where the backup data is locatedTARGETPATH
- Path where the backuped date should be sentTARGETIP
- IP to the server/computer that should recive the dataSSHPORT
- Port for SSH that Rsync should useUSERNAMES
- Array of users folder that should be backed up, specified with spaces in-betweenDAYS
- After how many days the logs should be removed
SPECIALJOBS
- Array of special files and folders
These scripts sends a mail with errorlogs and weeklylog files.
Currently supporting TLS email servers.
SSL is not tested.
To use mail scripts you need to configure the following variables in sendmail.py
.
More information can be found in the file itself.
fromaddress
- The adress the mail will be sent fromtoaddress
- The adress that will receive the emailusername
- Username of thefromadress
password
- Password for thefromadress
ip
- IP to the server for thefromadress
port
- Port to the server for thefromadress
Examples are pre-filled in the sendmail.py
file.
To disable error logs emails, remove this line
python3 ./sendmail.py "$LOGPATH" "$LOGFILE" "Rsync fail" 2>&1 | tee -a $LOGPATH/$LOGFILE
and the following if error checks in rsync-job.sh
(Click the link to get it highlighted)
To get weekly mails the weeklymails.sh
script needs to be executed once a week, preferably at Sundays or Mondays.
The script can be executed using cron jobs. The following into your crontab jobs file:
#Send a weekly mail about the weeks Rsync jobs (Sunday at 18:00)
0 18 * * 0 <USER> cd <DIRECTORY> && ./weeklymail.sh
Configure the variables before saving.
<USER>
- The Linux user that should execute the job<DIRECTORY>
- The directory that all the scripts are located inside
- Discord Webhook integration
- Large backup size difference check
- Send mail for SSL mail servers
- Config file
- Setup command for automatic setup