Change Database location Raspberry Pi

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
Preko
Posts: 1
Joined: Thursday 16 November 2017 19:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Change Database location Raspberry Pi

Post by Preko »

Hello everyone.

I have recently created a Domoticz webserver on a raspberry pi.

I want to change the database location to be not on the SDCard but on a USB KEY (which will be forced to have the same driver number upon rebbot).

1 - is there a way to modify the path ?
2 - is it "acceptable" to do this ?

Thank you all ;)

NB : I have not found a topic / answer related to this question ...
Orionos
Posts: 6
Joined: Friday 15 December 2017 20:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Change Database location Raspberry Pi

Post by Orionos »

I'm surprised nobody answered this. Apparently this community isn't as active as we'd hope. Given the still quite complex nature of Domoticz, I would have expected a lot more whiz-kids. Anyway...

You can easily alter the startup line for domoticz to point to a different file.

In the case of systemd, you'll find a line in the domoticz.service file similar to this:

Code: Select all

ExecStart=/home/domoticz/domoticz/domoticz -www 8080 -sslwww 443 -dbase /home/domoticz/domoticz/domoticz.db
As you can see, the location of your database is just a little startup-option away. Given that it's part of the program, I imagine it's perfectly acceptable.

Important: Make certain the user that runs domoticz has read-write permission on the directory that holds the file. Otherwise, domoticz will boot, but you'll have lots of SQL errors.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Change Database location Raspberry Pi

Post by EddyG »

I am suprised why 'nobody' uses the 'default' linux methode of calling: ./domoticz --help or /home/pi/domoticz/domoticz --help
You see all the parameters you could use on domoticz.
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Change Database location Raspberry Pi

Post by ben53252642 »

Or you could just use a symbolic link (I use many for making certain files operate from tmpfs reducing writes to the SD card).

Example:

Code: Select all

mkdir -p /tmp/domoticz
ln -sf /tmp/domoticz/domoticz.db-shm /root/domoticz/domoticz.db-shm
ln -sf /tmp/domoticz/domoticz.db-wal /root/domoticz/domoticz.db-wal
ln -sf /tmp/domoticz/ozwcp.poll.XXXXXX.xml /root/domoticz/ozwcp.poll.XXXXXX.xml
ln -sf /tmp/domoticz/ozwcp.scenes.XXXXXX /root/domoticz/ozwcp.scenes.XXXXXX
ln -sf /tmp/domoticz/ozwcp.stat.XXXXXX /root/domoticz/ozwcp.stat.XXXXXX
ln -sf /tmp/domoticz/ozwcp.topo.XXXXXX /root/domoticz/ozwcp.topo.XXXXXX
ln -sf /tmp/domoticz/domocookie.txt /root/domoticz/domocookie.txt
ln -sf /tmp/domoticz/domoticz_beta.tgz /root/domoticz/domoticz_beta.tgz
mkdir -p /tmp/domoticz/Config
ln -sf /tmp/domoticz/Config/OZW_Log.txt /root/domoticz/Config/OZW_Log.txt
service domoticz start
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Change Database location Raspberry Pi

Post by EddyG »

It's not a good idea to put the database on a tmpfs, because if you have a power failure or reboot you lose the database.
Why not use the startup parameter to relocate the database, that's what the parameter is intended for.
albercola
Posts: 10
Joined: Monday 19 February 2018 18:15
Target OS: Windows
Domoticz version:
Contact:

Re: Change Database location Raspberry Pi

Post by albercola »

Hi,

Orionos gave the best solution for my problem. Unfortunately i cannot locate the domoticz.service file.

EddyG gave another good suggestion but i am not able to solve my problem in that way.

Can you please help me?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Change Database location Raspberry Pi

Post by waaren »

albercola wrote: Sunday 29 April 2018 22:21 Hi,

Orionos gave the best solution for my problem. Unfortunately i cannot locate the domoticz.service file.

EddyG gave another good suggestion but i am not able to solve my problem in that way.

Can you please help me?
@albercola,
I use Berryboot . Now I only boot from the sd card and all other IO is done from/to USB or SCSI attached storage. I use my Synology NAS for it with the the additional benefit of being able to have hourly snapshots of my domoticz production system. It saved my data already on a couple of occasions.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest