Page 1 of 1

backupdatabase.php results in Unauthorized

Posted: Tuesday 15 June 2021 9:07
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

Re: backupdatabase.php results in Unauthorized

Posted: Tuesday 15 June 2021 14:49
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.

Re: backupdatabase.php results in Unauthorized

Posted: Monday 28 June 2021 11:09
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>

Re: backupdatabase.php results in Unauthorized

Posted: Monday 28 June 2021 11:52
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?

Re: backupdatabase.php results in Unauthorized

Posted: Wednesday 06 October 2021 9:58
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

Re: backupdatabase.php results in Unauthorized

Posted: Thursday 07 October 2021 7:35
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).

Re: backupdatabase.php results in Unauthorized

Posted: Friday 08 October 2021 10:49
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.

Re: backupdatabase.php results in Unauthorized

Posted: Friday 08 October 2021 18:55
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

Re: backupdatabase.php results in Unauthorized

Posted: Sunday 31 March 2024 11:04
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.

Re: backupdatabase.php results in Unauthorized

Posted: Sunday 31 March 2024 12:26
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.

Re: backupdatabase.php results in Unauthorized

Posted: Sunday 31 March 2024 12:45
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?

Re: backupdatabase.php results in Unauthorized

Posted: Sunday 31 March 2024 14:15
by waltervl
It is some kind of symbolic link into the Domoticz executable that makes a backup.....

Re: backupdatabase.php results in Unauthorized

Posted: Monday 01 April 2024 13:45
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.

Re: backupdatabase.php results in Unauthorized

Posted: Tuesday 02 April 2024 20:46
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.