Easy backup to remote share (e.g. NAS)
Posted: Saturday 04 November 2017 12:50
Hi all,
I have created a solution to backup files and folders to a remote CIFS file share (in my case Synology). It does not require FTP and is very easy to use. I could not find an easy manual to do this, so here you go. Basic Linux knowledge is required.
Step 1: create a file share on your target device (e.g. Synology, QNAP or Windows) and create a user with write permissions. There are plenty of manuals how to do this. My remote folder is called \\diskstation\User\domoticz
Step 2: create a folder on your Domoticz server to mount the share (I use /diskstation):
Step 3: mount the remote share on your domoticz server (I have a pi). The best way is to add this line to /etc/fstab (do this as root!) so it is reconnected after a reboot:
add this line to the bottom (use your own pathnames and username/password):
mount the share:
check if you can access the share and create a subfolder (use the following command one by one and check output):
Step 4: I use a small script to backup the database and scripts. It is very easy to backup more files/folders:
The script I use:
Step 5: Add the script to cron (note: the scripts does not require root in my config, but you may need to add sudo):
and add the line:
And you're done. Hope you like it!
I have created a solution to backup files and folders to a remote CIFS file share (in my case Synology). It does not require FTP and is very easy to use. I could not find an easy manual to do this, so here you go. Basic Linux knowledge is required.
Step 1: create a file share on your target device (e.g. Synology, QNAP or Windows) and create a user with write permissions. There are plenty of manuals how to do this. My remote folder is called \\diskstation\User\domoticz
Step 2: create a folder on your Domoticz server to mount the share (I use /diskstation):
Code: Select all
sudo mkdir /diskstation
Code: Select all
sudo vi /etc/fstab
Code: Select all
//192.168.1.100/User/domoticz /diskstation cifs _netdev,username=<yourusername>,password=<yourpassword>,dir_mode=0755,file_mode=0755,uid=1000,gid=1000 0 0
Code: Select all
sudo mount /diskstation
Code: Select all
mount /diskstation
ls -l /diskstation
touch /diskstation/testfile
ls -l /diskstation
rm /diskstation/testfile
mkdir /diskstation/backup
Code: Select all
vi ~/backup_domoticz.sh
Code: Select all
#!/bin/bash
DESTDIR="/diskstation/backup"
DOMO_IP="192.168.1.99" # Domoticz IP
DOMO_PORT="8080" # Domoticz port
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /$DESTDIR/domoticz_backup.db
cp -r /home/pi/domoticz/scripts/ $DESTDIR
Code: Select all
crontab -e
Code: Select all
50 23 * * * ~/backup_domoticz.sh