backupdatabase.php results in Unauthorized

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

Moderator: leecollings

Post Reply
clardima
Posts: 2
Joined: Tuesday 15 June 2021 9:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

backupdatabase.php results in Unauthorized

Post by clardima »

Hi everybody,

For months I was using /usr/bin/curl -s http://localhost:8080/backupdatabase.php to get the domoticz database to load it into a small datawarehouse.
But since a few weeks, the php script is returning 401 Unauthorized.

In Domoticz, I have set my subnet (192.168.178.*) as lokal network to avoid logging in.
But the script also fails from my raspberry itself.

Is the script still supported? Or should I set something else?

Thanks!
Maarten
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: backupdatabase.php results in Unauthorized

Post by waltervl »

On what version of Domoticz are you?
You should also add 127.0.0.* to the access list in Setup - Settings to be sure when accessing from localhost.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
clardima
Posts: 2
Joined: Tuesday 15 June 2021 9:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: backupdatabase.php results in Unauthorized

Post by clardima »

Hi,

I am using 2021.1 as version.
Already tried to add 127.0.0.1 but that did not work.

Local command: /usr/bin/curl -s http://localhost:8080/backupdatabase.php > domoticz.backup
results in a domoticz.backup file containing

Code: Select all

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: backupdatabase.php results in Unauthorized

Post by erem »

which user runs domoticz?

which user rus the curl command?

does

Code: Select all

sudo /usr/bin/curl -s http://localhost:8080/backupdatabase.php > domoticz.backup
work?
Regards,

Rob
User avatar
TomTom
Posts: 4
Joined: Sunday 26 September 2021 22:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: backupdatabase.php results in Unauthorized

Post by TomTom »

Hi, have the same issue with a returning http 401.

running with sudo does not solve the issue for me.
erem wrote: Monday 28 June 2021 11:52 ...
does

Code: Select all

sudo /usr/bin/curl -s http://localhost:8080/backupdatabase.php > domoticz.backup
work?
Trying to run it via localhost entry and with the local ip address in curl parameters, with the pi and sudo user, as well as domoticz user and password in curl parameters - for all combinations always receiving a http 401.

Any ideas how to solve this?

Thanks and regards, Tom
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: backupdatabase.php results in Unauthorized

Post by EddyG »

Install sqlite3 and do

Code: Select all

/usr/bin/sqlite3 $SOURCEPATH$SOURCEFILE ".backup $MOUNTPOINT/$BACKUPFILE"
Of course set the appropriate variables before the command. I backup directly to my NAS every 5 minutes
It is much more efficient and runs faster (approx. 30 Mb in less then 1.5 seconds).
Last edited by EddyG on Friday 08 October 2021 12:04, edited 1 time in total.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: backupdatabase.php results in Unauthorized

Post by waltervl »

erem wrote: Monday 28 June 2021 11:52 which user runs domoticz?

which user rus the curl command?

does

Code: Select all

sudo /usr/bin/curl -s http://localhost:8080/backupdatabase.php > domoticz.backup
work?
For me this command works perfectly.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: backupdatabase.php results in Unauthorized

Post by EddyG »

I see in the source that you have to be an admin user in Domoticz for this to work. Could that be the problem?
Try using it without the '> domoticz.db' If you skip that part the database backup.db will created in /tmp/backup.db in Linux and userdatafolder/backup.db in Windows
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: backupdatabase.php results in Unauthorized

Post by sincze »

Mmm interesting.

Code: Select all

sudo /usr/bin/curl -v -s http://domo_ip:domo_port/backupdatabase.php > file2.db
Domoticz Version: 2023.1 it does give me the DB as a backup
Domoticz Version: 2024.4 gives me 0 bytes

Response Code is

Code: Select all

HTTP/1.1 200 OK
So that does not seem to be unauthorized.

Code: Select all

[31/Mar/2024:11:12:43.561 +0200] "GET /backupdatabase.php HTTP/1.1" 200 0 - "curl/7.74.0"
Via the Domoticz Web Interface -> Settings > Backup and Restore -> Backup I also receive 0 bytes in the download.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: backupdatabase.php results in Unauthorized

Post by waltervl »

2024.4 gives me normal size backup when doing it through menu Settings > Backup and Restore -> Backup.
So it seems something is wrong in your setup.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: backupdatabase.php results in Unauthorized

Post by sincze »

waltervl wrote: Sunday 31 March 2024 12:26 2024.4 gives me normal size backup when doing it through menu Settings > Backup and Restore -> Backup.
So it seems something is wrong in your setup.
Hehe probably. But with debug logging on and no errors... hard to find out.

What does the PHP command do?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: backupdatabase.php results in Unauthorized

Post by waltervl »

It is some kind of symbolic link into the Domoticz executable that makes a backup.....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: backupdatabase.php results in Unauthorized

Post by Kedi »

Indeed it has nothing to do with php
In this script I use an alternative methode: https://www.domoticz.com/forum/viewtopi ... te#p306625
If you install sqlite3 then this command is much faster and can run outside of Domoticz when ever you want.

Code: Select all

sqlite3 $SOURCEPATH$SOURCEFILE ".backup $MOUNTPOINT/$BACKUPFILE"
The sqlite3 .backup command is made for that.
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: backupdatabase.php results in Unauthorized

Post by sincze »

Kedi wrote: Monday 01 April 2024 13:45 Indeed it has nothing to do with php
In this script I use an alternative methode: https://www.domoticz.com/forum/viewtopi ... te#p306625
If you install sqlite3 then this command is much faster and can run outside of Domoticz when ever you want.

Code: Select all

sqlite3 $SOURCEPATH$SOURCEFILE ".backup $MOUNTPOINT/$BACKUPFILE"
The sqlite3 .backup command is made for that.
Mm interesting indeed. tried it with running Domoticz but received:

Code: Select all

sudo sqlite3 /home/pi/domoticz/domoticz.db ".backup /mnt/home/backup/domoticzdb/domoticzups_20240402204245_167_.db"

Code: Select all

Error: database is locked
And that makes me wonder is this also the rootcause of my initial error I am experiencing.
Let me check on the DEMO machine.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest