Daily backup, automatically, of database

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
User avatar
Bernd
Posts: 27
Joined: Tuesday 04 February 2014 8:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: The Netherlands, De Wijk
Contact:

Daily backup, automatically, of database

Post by Bernd »

The RPi has the bad behavior to crash once in a while. All data between the period of the last manual backup and the moment of the crash is then lost. Is it possible to auto-email the database daily from out of Domoticz?
Raspberry Pi 4 2GB (RPi OS Light)
RFXCOM RFXtrx433E, firmware version = 1025
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Daily backup, automatically, of database

Post by waaren »

Bernd wrote: Saturday 17 August 2019 10:22 The RPi has the bad behavior to crash once in a while. All data between the period of the last manual backup and the moment of the crash is then lost. Is it possible to auto-email the database daily from out of Domoticz?
If your database size is not very big ( this works with my database of approximate 10 Mbyte ) you can use this in a cron job or in a bash script triggered by an domoticz event / script.

Code: Select all

domoDir=/home/pi/domoticz    # change to location of your domoticz.db
[email protected] # change to your Email address 
sudo echo "Backup attached" > message.txt
sudo cp $domoDir/domoticz.db $domoDir/backup.db
sudo mail -s "backup" $mailAddress -A $domoDir/backup.db < message.txt
sudo rm $domoDir/backup.db
sudo rm message.txt
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sion
Posts: 113
Joined: Friday 08 January 2016 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Daily backup, automatically, of database

Post by sion »

Hi guys.
I’m following the guide for backing up to nas in the wiki, and have what’s probably A stupid question.

On the part of the code for deleting old backups:

Code: Select all


# work out our cutoff date
MM=`date --date="$ndays days ago" +%b`
DD=`date --date="$ndays days ago" +%d`
TT=`date --date="$ndays days ago" +%s`
Do I just over write the MM DD and TT ?

So if I want to delete anything older than 15days, id do:

Code: Select all

# work out our cutoff date
00=`date --date="$ndays days ago" +%b`
15=`date --date="$ndays days ago" +%d`
00=`date --date="$ndays days ago" +%s`
Or for files over a month:

Code: Select all

# work out our cutoff date
01=`date --date="$ndays days ago" +%b`
00=`date --date="$ndays days ago" +%d`
00=`date --date="$ndays days ago" +%s`
Thanks.
Sion.
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.
User avatar
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Daily backup, automatically, of database

Post by waltervl »

You are referring to this wiki page I presume https://www.domoticz.com/wiki/Daily_bac ... ternal_hdd

In the extension for deleting old backups you only have to modify the ndays=19 line if you want to set something else. The rest will be done for you.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest