It is necessary to make the following adjustments to Synology (Personal Cloud) before backing up any data. If not, the script will fail.
First of all, install the “sshpass” package onto the client machine (On Local or Laptop PC). It provides the password directly to the script without having to enter it manually (create a text file with password).
[root@localhost ~]# dnf install sshpass -y
Enable the Rsync service to render your DiskStation as a backup destination for another Synology server or Rsync-compatible service via the following services. Be sure to enable Rsync and the Rsync account.
(control Panel → File services → rsync-→ enable rsync service and enable rynsc)

NB:- If needed, we can change port 22 to different port for secure synchronization by assigning a different port value. (If the port is 31947,the following command is required for synchronization)
sshpass -f /root/file1 rsync -av -e ‘ssh -p 31947’ –update –timeout=60 /home/admin/Documents/ admin@192.168.1.105:/volume1/admin/Laptop/Documents/ 2> /dev/null # (ssh port 31947)
Further Edit rsync Account and enter admin username and password.

After that, access “Terminal & SNMP” option and enable the ssh service. If needed, you can change port 22 to a different value.
Further Control Panel – > Terminal & SNMP -→Enable ssh services

Run this script as a cron job to automatically backup the necessary files and folders, as shown below.
- Cron job
[root@localhost ~]# vi /etc/crontab
HELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
00 23 * * * root /root/mybackup.sh >> /var/log/backup.log
- Script
[root@localhost ~]# vi mybackup.sh
#!/bin/bash
#Backup Sources
ORIGIN_PATH1=/home/admin/Documents/
ORIGIN_PATH2=/home/admin/Downloads/
#Backup destination listed below
BACKUP_PATH1=/volume1/NetBackup/
BACKUP_PATH2=/volume1/NetBackup/
#File path for password file
PASS_PATH=/root/mypassword.txt
#This is used to detect the IP address automatically.
IP=`arp -an | grep 00:11:32:9d:a0:bc | awk ‘{print $2}’ | sed ‘s/[()]//g’`
#Backup to the right destination
sshpass -f $PASS_PATH rsync -av -e ‘ssh -p 22’ –update –timeout=150 $ORIGIN_PATH1 admin@$IP:$BACKUP_PATH1 2> /dev/null
sleep 15
sshpass -f $PASS_PATH rsync -av -e ‘ssh -p 22’ –update –timeout=60 $ORIGIN_PATH2 admin@$IP:$BACKUP_PATH2 2> /dev/null



