hi folk !
I'm starting this discussion in order to have feedback from experimented people...
I would like to make weekly backup of the SD card of my raspberry (on which is running domoticz) and daily backup of the database of domoticz.
Nothing new on this, as a lot of tutorials are dealing with that, but I only found tutorials dealing with backup on a NAS server. In my case, as I don't have a NAS, I would like to do this backup on a 64 GB USB storage key attached to my raspberry.
Someone here in the group has been already developed this ? is a tutorial available to perform this operation ?
Many thanks !
Best regards.
backup on USB key
Moderators: leecollings, remb0
-
- Posts: 10
- Joined: Wednesday 14 December 2016 17:29
- Target OS: OS X
- Domoticz version:
- Contact:
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: backup on USB key
It is basically the same as backing up to a NAS, you just copy to another location.
If you only have on usb key connected following script should be fine, if not you need to alter the script to match your usb key.
If you do not have Monit installed just remove the lines that are related to that (lines 7, 8, 19 and 20)
I made a "Push on Button" with the script in the ON action so I don't have to run the script from command line.
You could put a timer on that , or instead of the button use a Cron task to do the backup weekly. I prefer to start the backup manually so that I can do it at a time that is convenient to me without shutting down (even very briefly) domoticz unexpectedly.
If you only have on usb key connected following script should be fine, if not you need to alter the script to match your usb key.
If you do not have Monit installed just remove the lines that are related to that (lines 7, 8, 19 and 20)
Code: Select all
#!/bin/bash
#script to backup entire domoticz folder
clear
sudo mount /dev/sda1 /media/usb
echo "Backing up Domoticz folder... please standby..."
##Remove following 2 lines if you don't use Monit
echo "First stopping Monit to avoid false alerts or reboots"
sudo /etc/init.d/monit stop
echo "Stopping the Domoticz service"
sudo service domoticz.sh stop
echo "domoticz service stopped- starting backup now"
sudo rsync -aAXv --fake-super --log-file=/home/pi/domoticz/scripts/domobackup.log /home/pi/domoticz /media/usb/home/pi/
echo "Restarting Domoticz... please standby..."
sudo service domoticz.sh restart
echo "domoticz service restarted"
sudo chmod +x /home/pi/domoticz/scripts/domobackup.log
sudo chmod 777 /home/pi/domoticz/scripts/domobackup.log
##Remove following 2 lines if you don't use Monit
echo "Starting monit again"
sudo /etc/init.d/monit start
You could put a timer on that , or instead of the button use a Cron task to do the backup weekly. I prefer to start the backup manually so that I can do it at a time that is convenient to me without shutting down (even very briefly) domoticz unexpectedly.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: backup on USB key
I never stop domoticz for making a backup 
I use this script on my nas to backup the complete domoticz folder with versioning:
LAST = timestamp of last execution stored in a txt file
LASTFILE = timestamp of newest file in SOURCE folder, also stored in a txt file.
A bit unnecessary in case of Domoticz, I just left it because this is the way I backup multiple things and I use that information in a web page where I can monitor all backup scripts I run.

I use this script on my nas to backup the complete domoticz folder with versioning:
Code: Select all
#!/bin/sh
NOW=$(date +"%Y-%m-%d")
TIME=$(date +"%s")
SOURCE="/volume1/@appstore/domoticz/"
LAST=`cat /volume1/web/secure/backups/domoticz.txt`
LASTFILE=`find /volume1/@appstore/domoticz -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f1 -d"."`
if [[ $LAST -ne $LASTFILE ]] || [[ $LAST -lt $MAXTIME ]];then
DESTINATION="/volume1/homes/guy/backup/domoticz"
LOGFILE=/volume1/web/secure/backups/logs/domoticz.$NOW.txt
echo ------------------------------------ START domoticz -- $(date +"%Y-%m-%d %H:%M:%S") UTC+2 | tee -a $LOGFILE
rsync -aP --exclude-from '/volume1/homes/guy/backup/excludedfiles.txt' --stats --delete-after --ignore-errors --links --link-dest="$DESTINATION/__prev/" "$SOURCE" "$DESTINATION/$NOW" | tee -a $LOGFILE
rm -f "$DESTINATION/__prev"
ln -s "$NOW" "$DESTINATION/__prev"
echo ------------------------------------ END domoticz -- $(date +"%Y-%m-%d %H:%M:%S") UTC+2 | tee -a $LOGFILE
echo $LASTFILE > /volume1/web/secure/backups/domoticz.txt
echo $TIME > /volume1/web/secure/backups/domoticz.time.txt
unset LAST
unset LASTFILE
fi
LASTFILE = timestamp of newest file in SOURCE folder, also stored in a txt file.
A bit unnecessary in case of Domoticz, I just left it because this is the way I backup multiple things and I use that information in a web page where I can monitor all backup scripts I run.
-
- Posts: 3
- Joined: Monday 26 December 2016 16:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.3530
- Location: Krimpen NL
- Contact:
Re: backup on USB key
Hello Elmortero I am new here,
I was searching for this!! Elmortero Can you tell me how i make the script running? Can i start it with Blocky to?
What do you mean with: I made a "Push on Button" with the script in the ON action?
My raspberry frequently jams. Therefor I have an old backup of the entire SD card and a backup of resent domoticz.db. Domoticz.db do I copy using ubuntu on the SD card.
Using Scripts I have no experience.
thanks gerritjan.
I was searching for this!! Elmortero Can you tell me how i make the script running? Can i start it with Blocky to?
What do you mean with: I made a "Push on Button" with the script in the ON action?
My raspberry frequently jams. Therefor I have an old backup of the entire SD card and a backup of resent domoticz.db. Domoticz.db do I copy using ubuntu on the SD card.
Using Scripts I have no experience.
thanks gerritjan.
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: backup on USB key
First you need to have a Dummy device active in Setup -> Hardware. Create a "device" of the type "Dummy (Does nothing, use for virtual switches only)", I called mine V-Switch
Then, in the Switches screen you can manually create a switch, as hardware you choose the dummy device you made, give a name and for Switch Type you select Push On Button.
Then add the path to the backup script in the On Action.
That's it
Then, in the Switches screen you can manually create a switch, as hardware you choose the dummy device you made, give a name and for Switch Type you select Push On Button.
Then add the path to the backup script in the On Action.
That's it
-
- Posts: 3
- Joined: Monday 26 December 2016 16:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.3530
- Location: Krimpen NL
- Contact:
Re: backup on USB key
The usb backup worked perfectly with a single adjustment so far. The special thing is that I did not use the backup this last year for recover. That may be because I also changed the password of the raspberrypi!
Who is online
Users browsing this forum: Google [Bot] and 1 guest