Easy backup to remote share (e.g. NAS)

All kinds of 'OS' scripts
Post Reply
jerry
Posts: 2
Joined: Saturday 04 November 2017 13:19
Target OS: Raspberry Pi
Domoticz version:
Contact:

Easy backup to remote share (e.g. NAS)

Post by jerry » Saturday 04 November 2017 13: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):

Code: Select all

sudo mkdir /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:

Code: Select all

sudo vi /etc/fstab
add this line to the bottom (use your own pathnames and username/password):

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
mount the share:

Code: Select all

sudo mount /diskstation
check if you can access the share and create a subfolder (use the following command one by one and check output):

Code: Select all

mount /diskstation
ls -l /diskstation
touch /diskstation/testfile
ls -l /diskstation
rm /diskstation/testfile
mkdir /diskstation/backup
Step 4: I use a small script to backup the database and scripts. It is very easy to backup more files/folders:

Code: Select all

vi ~/backup_domoticz.sh
The script I use:

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
Step 5: Add the script to cron (note: the scripts does not require root in my config, but you may need to add sudo):

Code: Select all

crontab -e
and add the line:

Code: Select all

50 23 * * * ~/backup_domoticz.sh
And you're done. Hope you like it!

Smiggel
Posts: 28
Joined: Friday 23 March 2018 18:29
Target OS: -
Domoticz version:
Contact:

Re: Easy backup to remote share (e.g. NAS)

Post by Smiggel » Friday 13 April 2018 15:58

Thanks for the tutorial! It works excellent. :-)

jake
Posts: 491
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Easy backup to remote share (e.g. NAS)

Post by jake » Saturday 14 April 2018 12:59

Thanks for sharing the script and the how-to!
Do I need to make the script executable? If so, how?

DAVIZINHO
Posts: 205
Joined: Sunday 27 August 2017 18:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spain
Contact:

Re: Easy backup to remote share (e.g. NAS)

Post by DAVIZINHO » Saturday 19 May 2018 20:20

great job!
aditionally if you want to remove files older than X days you can use this:

Code: Select all

find /synobackups/* -mtime +30 -exec rm {} \;
when /synobackups/ is the folder thant i mount and 30 is the X days you want to delete

jeroennus
Posts: 2
Joined: Monday 28 May 2018 20:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Easy backup to remote share (e.g. NAS)

Post by jeroennus » Monday 28 May 2018 20:19

After almost losing all my script en config this week I tried a couple of backup solutions. Liked this one the most because I don't have to use FTP on my Qnap. Thanks for posting this!!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests