Page 3 of 5

Re: Different Backups from Crontab to network

Posted: Tuesday 17 November 2015 22:14
by jvdz
Shouldn't that be:

Code: Select all

sudo sh domoticz_backup.sh
Jos

Re: Different Backups from Crontab to network

Posted: Wednesday 18 November 2015 20:59
by nigels0
or...

sudo ./domoticz_backup.sh

Re: Different Backups from Crontab to network

Posted: Wednesday 18 November 2015 21:21
by Derik
is this standing in the upper leftcorner: #!/bin/bash
Is the document pi and not root?
Is the document 0777 ?

Re: Different Backups from Crontab to network

Posted: Monday 25 January 2016 22:01
by assenzuid
I have running a daily backup script, but I'm looking/ searching for how to implement a notification trigger after a successfully backup went complete by email.

Someone some ideas or already implemented?

Thanks.

Re: Different Backups from Crontab to network

Posted: Sunday 20 March 2016 16:58
by woody4165
Very useful! Thanks.
I got it work.
What I would like to do is to remove previous backed files, let's say removing files older that a week before.
I haven't found a way to do it on ftp (my Nas).
I tried mdelete and other command found on internet, but none worked.
Any suggestion on this?


What would be nice is also to execute it via a switch.
Is there a way to execute a shell script from a lua script?

Thanks

Re: Different Backups from Crontab to network

Posted: Sunday 20 March 2016 22:50
by sebitop
Hi guys

I think I missed something... maybe someone can help me :

if I do a Save Database via domoticz just clicking the button I have a domoticz.db file created localy on my computer, this file is 2 MB

if I use the script (without zipping it as I have space on my server) I have a domoticz_[date].db but this file is 91kb

if i try to restore the database using one of these files generated the log says : Seems this is not our database, or it is corrupted!

So I think i missed something could someone help me ??

thank you for your help !!

cheers

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 7:52
by Derik
@ Sebitop..
What is the problem to make a backup from the whole domoticz map... you got all your settings saved
And when you have a very small file there is something wrong.

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 8:13
by woody4165
@sebitop
I have just tried to restore the backup that was done automatically this night from the script
My domoticz.db is around 630Kb and trying to do it also from the domoticz web the dimension is the same.
But I suggest to backup, like it's done in the script, also the whole domoticz folder tree since if you have modified any files in that structure will not be saved in the domoticz.db backup. I know that it takes something around 20MB, but it's worthing.

What I'm trying to find is a way to delete previous backup saved on my ftp server (Nas), but I haven't found a way yet.

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 10:01
by woody4165
I just solved my own request.

To remove older backup files using the script already published, I added those lines.

In the PARAMETERS section just add:

Code: Select all

    
REMOVETIMESTAMP=`/bin/date --date='2 day ago' +%Y%m%d`
REMOVEFILE="domoticz_$REMOVETIMESTAMP"
choosing how many days back you want the backup files to be deleted.

At the end of the script add:

Code: Select all

    
    ## Now remove old backup
    for i in `curl -s -l ftp://"$USERNAME":"$PASSWORD"@$SERVER/$DESTDIR/ | grep $REMOVEFILE` ;
    do
       curl ftp://${SERVER}/${DESTDIR}/${i} -u "${USERNAME}:${PASSWORD}" -O --quote "DELE ${DESTDIR}${i}"
    done
 
And that's all!

I'm not a "coder", but this is what I found going around and around.
Hope can help someone, like helped myself...

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 10:16
by sebitop
Hi Woody

I understand what you mean but it dosen't solve my problem

I don't understand why localy my .db is 2mb when using the script the .db is 91kb and impossible to restore ...

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 10:20
by woody4165
Hi Sebitop

how big is the file if you call it directly from the browser like http://domoticz_ip:domoticz_port/backupdatabase.php

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 10:32
by sebitop
2 MB this is the point !

if I directly ave the db from the browser, the file is 2 MB and I can restore it.

if I simply use : /usr/bin/curl http://192.168.0.30:8080/backupdatabase.php > /tmp/test.db

test.db is 91kb .... and impossible to restore it

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 10:45
by woody4165
this happens in the script as well if you launch the curl command from terminal?

what I would try is to write in another folder and another filename...

That's weird...

Re: Different Backups from Crontab to network

Posted: Monday 21 March 2016 10:47
by sebitop
this is exactly what i type in a terminal : /usr/bin/curl http://192.168.0.30:8080/backupdatabase.php > /tmp/test.db

when i go into the tmp folder, the file is 91kb instead of 2 MB

Re: Different Backups from Crontab to network

Posted: Tuesday 30 August 2016 10:16
by vikasjee
While taking a backup on windows 10 i am getting a backupdatabase.php instead of the .db file. Is anybody else getting same error? Can somebody help?

Re: Different Backups from Crontab to network

Posted: Tuesday 30 August 2016 11:26
by Egregius
That's probably because your Windows machine doesn't has PHP installed.

Re: Different Backups from Crontab to network

Posted: Sunday 22 January 2017 18:00
by svanzon
I have the same problem as sebitop.

When I goto http://192.168.1.100:8090/backupdatabase.php (that are my Domoticz settings) I can safe a file of 450KB but when i use the automated script I get an empty DB file.

Any tips, used the script for the DB only and also tried the Synology one (get the DB and folders but DB is empty).

Re: Different Backups from Crontab to network

Posted: Tuesday 07 March 2017 21:47
by K3rryBlue
I backup 9 different folder and with the standard script it became a lot of seperate files dumped to my NAS.
So I decided to use the $timestamp to create a folder, to drop the 9 archives, by using the command:

Code: Select all

curl -u "$USERNAME:$PASSWORD" --ftp-create-dirs "ftp://$SERVER/$DESTDIRNAS/$TIMESTAMP/"

#Modified the drop location for the archives:
curl -s --disable-epsv -v -T"/tmp/kwhmeter.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS/$TIMESTAMP/"
The daily backup is stored in seperate folders.

Re: Different Backups from Crontab to network

Posted: Monday 19 June 2017 22:58
by sschouten
Hello,

iám using this script to backup to my nas,
but i still get the bellow error. what sis going wrong ?

Code: Select all

#!/bin/bash
# LOCAL/FTP/SCP/MAIL PARAMETERS
SERVER="10.0.0.207" # IP of Synology NAS, used for ftp
USERNAME="domoticz-bk" # FTP username of Network disk used for ftp
PASSWORD="***********" # FTP password of Network disk used for ftp
DESTDIR="/opt/backup" # used for temorarily storage
DESTDIRNAS="/backups_lokaal/Domoticz-hoofddorp/" # Path to your Synology NAS backup folder
DOMO_IP="10.0.0.95" # Domoticz IP 
DOMO_PORT="8080" # Domoticz port 
### END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
BACKUPFILE="domoticz_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
BACKUPFILEGZ="$BACKUPFILE".gz
### Create backup and ZIP it
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /tmp/$BACKUPFILE
gzip -9 /tmp/$BACKUPFILE
tar -zcvf /tmp/domoticz_scripts_$TIMESTAMP.tar.gz /home/pi/domoticz/scripts/
#tar -zcvf /tmp/telegram_scripts_$TIMESTAMP.tar.gz /home/pi/tg/scripts/
### Send to Network disk through FTP
curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEGZ" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS"
curl -s --disable-epsv -v -T"/tmp/domoticz_scripts_$TIMESTAMP.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS"
#curl -s --disable-epsv -v -T"/tmp/telegram_scripts_$TIMESTAMP.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS"
### Remove temp backup file
/bin/rm /tmp/$BACKUPFILEGZ
/bin/rm /tmp/domoticz_scripts_$TIMESTAMP.tar.gz
#/bin/rm /tmp/telegram_scripts_$TIMESTAMP.tar.gz
### Done!

Code: Select all

pi@Domoticz:~/domoticz/scripts $ sh domoticz_backup.sh
tar: Removing leading `/' from member names
tar: /home/pi/domoticz/scripts/\r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
'!b.gzCan't open '/tmp/domoticz_20170619222329
curl: try 'curl --help' or 'curl --manual' for more information
* Illegal characters found in URL
* Closing connection -1
/bin/rm: cannot remove ‘/tmp/domoticz_20170619222329\r.db.gz\r\r’: No such file or directory
/bin/rm: cannot remove ‘/tmp/domoticz_scripts_20170619222329\r.tar.gz\r’: No such file or directory

Re: Different Backups from Crontab to network

Posted: Monday 19 June 2017 23:05
by Derik
mm

I do have a other strange problem..:
https://www.domoticz.com/forum/viewtopi ... =4&t=18015

So if there is someone that understand my strange error..
Hope he can help me..

Thanks