Different Backups from Crontab to network

All kinds of 'OS' scripts

Moderator: leecollings

leonardo
Posts: 14
Joined: Sunday 21 July 2013 22:04
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Italy
Contact:

Re: Different Backups from Crontab to network

Post by leonardo »

Hello dudes, I'm sorry I passed a lot of time out of Forum, I'm busy with other thinks and I have really little time for Domoticz :(
Please if someone needs help with script, just drop me a private message and I should get a notification email!
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by remb0 »

[solved] nice.
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Different Backups from Crontab to network

Post by Derik »

and counting:
ScreenShot108.jpg
ScreenShot108.jpg (89.67 KiB) Viewed 8069 times
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Different Backups from Crontab to network

Post by Derik »

Go one step further ..
I can also make a backup for the script folder with the same setting and crontab?
If I'm going to write more scripts is one of handy backup ok ..

Thank you ..

And ps I had often necessary the backups .. ;) ;)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
schmm
Posts: 8
Joined: Monday 29 September 2014 21:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Weert (Netherlands)
Contact:

Re: Different Backups from Crontab to network

Post by schmm »

You can add this to the script before Done to enable the backup of the scripts folder

Code: Select all

   ### Backup Script Folder
   tar -zcvf /tmp/domoticz_scripts_$TIMESTAMP.tar.gz /home/pi/domoticz/scripts/
   ### Send to Network disk through FTP
   curl -s --disable-epsv -v -T"/tmp/domoticz_scripts_$TIMESTAMP.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIR/"
   ### Remove temp backup file
   /bin/rm /tmp/domoticz_scripts_$TIMESTAMP.tar.gz
LJ80
Posts: 20
Joined: Wednesday 14 January 2015 21:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Different Backups from Crontab to network

Post by LJ80 »

I followed all steps from the wiki but wen I am at the step for testing I get this message back:

Code: Select all

'!b.gzCan't open '/tmp/domoticz_20150313172005
curl: try 'curl --help' or 'curl --manual' for more information
* Illegal characters found in URL
/bin/rm: cannot remove `/tmp/domoticz_20150313172005\r.db.gz\r\r': No such file or directory
What have I done wrong or what am i missing?
jjnj

Re: Different Backups from Crontab to network

Post by jjnj »

LJ80 wrote:Hi all,

I followed all steps from the wiki but wen I am at the step for testing I get this message back:

Code: Select all

'!b.gzCan't open '/tmp/domoticz_20150313172005
curl: try 'curl --help' or 'curl --manual' for more information
* Illegal characters found in URL
/bin/rm: cannot remove `/tmp/domoticz_20150313172005\r.db.gz\r\r': No such file or directory
What have I done wrong or what am i missing?
Found out the temp folder isn't correct. Make a folder on the pi where the script can backup to. I just made a folder in /home/pi/domoticz/scripts/backup
sschouten
Posts: 9
Joined: Thursday 23 April 2015 13:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Different Backups from Crontab to network

Post by sschouten »

i still get the same error i already make a new folder

'!b.gzCan't open '/tmp/domoticz_20150523214855
curl: try 'curl --help' or 'curl --manual' for more information
* Illegal characters found in URL
/bin/rm: cannot remove `/home/pi/domoticz/scripts/backupnas/domoticz_20150523214855\r.db\r': No such file or directory

the pi is creating the file but not upload it to the ftp server.

what i'm do i wrong.
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: Different Backups from Crontab to network

Post by sincze »

Why not use a simple rsync in crontab?

Code: Select all

crontab -e

Code: Select all

# Version 15-12-2014:

3 * * * * rsync -r -t --delete /home/pi/domoticz /mnt/syno/Domoticz
This is keeping my system going for over a year now.
You have to mount the external drive ofcourse. in my case mounted to /mnt/syno
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.
Skorpion
Posts: 27
Joined: Thursday 15 January 2015 9:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Different Backups from Crontab to network

Post by Skorpion »

Hi guys,

I am trying to establish a connection with my Synology via SFTP to upload my backups. Via Filezilla, I can get a working connection, but via the script, I got the following output when executing my script via CLI. I'm certain that the problem lies with the authentication of fingerprint/keys, but I don't know how to put this in my script.

Line in script:

Code: Select all

curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEGZ" -u"$USERNAME:$PASSWORD" "sftp://$SERVER/Domoticz/Backups/DB/"
CLI output:

Code: Select all

* About to connect() to 192.168.XX.XX port 22 (#0)
*   Trying 192.168.XX.XX...
* connected
* Connected to 192.168.XX.XX (192.168.XX.XX) port 22 (#0)
* SFTP 0x9a50a8 state change from SSH_STOP to SSH_INIT
* SFTP 0x9a50a8 state change from SSH_INIT to SSH_S_STARTUP
* SFTP 0x9a50a8 state change from SSH_S_STARTUP to SSH_HOSTKEY
* SSH MD5 fingerprint: MyFingerprint
* SSH host check: 2, key: <none>
* SFTP 0x9a50a8 state change from SSH_HOSTKEY to SSH_SESSION_FREE
* SFTP 0x9a50a8 state change from SSH_SESSION_FREE to SSH_STOP
* SSH DISCONNECT starts now
* SSH DISCONNECT is done
* Closing connection #0
* SSL peer certificate or SSH remote key was not OK
I hope that someone can help me out.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by ThinkPad »

Just posting my script here, maybe someone can use it. It creates a backup of the database, the www folder (i have custom frontpage.html for my tablet in it) and the scripts folder.
It is based on locations on my NAS, and the backups are also stored on this same NAS.

Code: Select all

#!/bin/bash
DOMO_IP="192.168.4.4"  # Domoticz IP 
DOMO_PORT="8084"        # Domoticz port 
### END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
BACKUPFILE="domoticzbackup_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
BACKUPFILEGZ="$BACKUPFILE".gz

#Create backup and make tar archives
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /volume1/dataschijf/Domoticz_backup/database/$BACKUPFILE
tar -zcvf /volume1/dataschijf/Domoticz_backup/scripts/domoticz_scripts_$TIMESTAMP.tar.gz /volume1/@appstore/domoticz/var/scripts/
tar -zcvf /volume1/dataschijf/Domoticz_backup/www/domoticz_wwwfolder_$TIMESTAMP.tar.gz /volume1/@appstore/domoticz/www/

#Delete backups older than 31 days
/usr/bin/find /volume1/dataschijf/Domoticz_backup/database/ -name '*.db' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/scripts/ -name '*.tar.gz' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/www/ -name '*.tar.gz' -mtime +31 -delete
The backup is just stored as a .db file, the two folders (www & script) are compressed in a .tar.gz file. I prefer .zip, but have not yet found out how to configure the 'tar' parameters.

I run it every evening at 23:55 by a cronjob:

Code: Select all

55      23      *       *       *       root    sh      /volume1/@appstore/domoticz/var/scripts/bash/domobackup.sh
Last edited by ThinkPad on Friday 24 July 2015 17:00, edited 1 time in total.
Reason: Forgot to add cronjob
I am not active on this forum anymore.
User avatar
kraades
Posts: 36
Joined: Wednesday 24 June 2015 9:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by kraades »

ThinkPad wrote:The backup is just stored as a .db file, the two folders (www & script) are compressed in a .tar.gz file. I prefer .zip, but have not yet found out how to configure the 'tar' parameters.
Maybe you can use gzip/gzunzip instead.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Different Backups from Crontab to network

Post by jannl »

Why do you want zip? A program like 7zip on Windows reads tar & zip/gzip etc.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by ThinkPad »

True, but .zip is native supported on all operating systems, including Android. On my PC i have 7-zip indeed.
It is not that important, but i would prefer zip over tar.gz.
I am not active on this forum anymore.
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by G3rard »

ThinkPad wrote:Just posting my script here, maybe someone can use it. It creates a backup of the database, the www folder (i have custom frontpage.html for my tablet in it) and the scripts folder.
It is based on locations on my NAS, and the backups are also stored on this same NAS.

Code: Select all

#!/bin/bash
DOMO_IP="192.168.4.4"  # Domoticz IP 
DOMO_PORT="8084"        # Domoticz port 
### END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
BACKUPFILE="domoticzbackup_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
BACKUPFILEGZ="$BACKUPFILE".gz

#Create backup and make tar archives
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /volume1/dataschijf/Domoticz_backup/database/$BACKUPFILE
tar -zcvf /volume1/dataschijf/Domoticz_backup/scripts/domoticz_scripts_$TIMESTAMP.tar.gz /volume1/@appstore/domoticz/var/scripts/
tar -zcvf /volume1/dataschijf/Domoticz_backup/www/domoticz_wwwfolder_$TIMESTAMP.tar.gz /volume1/@appstore/domoticz/www/

#Delete backups older than 31 days
/usr/bin/find /volume1/dataschijf/Domoticz_backup/database/ -name '*.db' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/scripts/ -name '*.tar.gz' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/www/ -name '*.tar.gz' -mtime +31 -delete
The backup is just stored as a .db file, the two folders (www & script) are compressed in a .tar.gz file. I prefer .zip, but have not yet found out how to configure the 'tar' parameters.

I run it every evening at 23:55 by a cronjob:

Code: Select all

55      23      *       *       *       root    sh      /volume1/@appstore/domoticz/var/scripts/bash/domobackup.sh
Thanks, I am using this script to backup the files to Onedrive via CloudSync (encrypted since one of the last updates).
Not using Domoticz anymore
Skorpion
Posts: 27
Joined: Thursday 15 January 2015 9:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Different Backups from Crontab to network

Post by Skorpion »

ThinkPad wrote:Just posting my script here, maybe someone can use it. It creates a backup of the database, the www folder (i have custom frontpage.html for my tablet in it) and the scripts folder.
It is based on locations on my NAS, and the backups are also stored on this same NAS.

Code: Select all

#Delete backups older than 31 days
/usr/bin/find /volume1/dataschijf/Domoticz_backup/database/ -name '*.db' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/scripts/ -name '*.tar.gz' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/www/ -name '*.tar.gz' -mtime +31 -delete
This is what I still needed. Thanks!

I am running Domoticz on a RPi and I store the backups on my Synology. A little problem that I am having is that it is searching for this directory on my RPi, which obviously cannot be found because this dir is located on my NAS. For now I am running this command on my NAS, but I would like to implement this in the backup script that I use on my RPi.

Does anyone know how to easily do this?
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by ThinkPad »

Maybe a nice tip, for uploading doorbell snapshots to Dropbox i used this script a while: https://github.com/andreafabrizi/Dropbox-Uploader
I had it running on my Raspberry, which worked fine. On my Synology NAS it doesn't work because it needs a real 'Bash' shell, Synology only has 'ash' which won't work according to the author of the script. But i now use the 'Cloud Sync' package on my NAS :)

But it might be useful to upload backups (.tar.gz) to Dropbox.... Benefit is that you also have version history with Dropbox.
Downside is that you can't do the auto-removal of old backups with this script, it can only push files to Dropbox, it doesn't work like a directory like on your PC.

I still use my backup script url this post. Saved my life already a few times :lol:
I am not active on this forum anymore.
Justintime
Posts: 228
Joined: Thursday 21 May 2015 9:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Different Backups from Crontab to network

Post by Justintime »

ThinkPad wrote:Just posting my script here, maybe someone can use it. It creates a backup of the database, the www folder (i have custom frontpage.html for my tablet in it) and the scripts folder.
It is based on locations on my NAS, and the backups are also stored on this same NAS.

Code: Select all

#!/bin/bash
DOMO_IP="192.168.4.4"  # Domoticz IP 
DOMO_PORT="8084"        # Domoticz port 
### END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
BACKUPFILE="domoticzbackup_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
BACKUPFILEGZ="$BACKUPFILE".gz

#Create backup and make tar archives
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /volume1/dataschijf/Domoticz_backup/database/$BACKUPFILE
tar -zcvf /volume1/dataschijf/Domoticz_backup/scripts/domoticz_scripts_$TIMESTAMP.tar.gz /volume1/@appstore/domoticz/var/scripts/
tar -zcvf /volume1/dataschijf/Domoticz_backup/www/domoticz_wwwfolder_$TIMESTAMP.tar.gz /volume1/@appstore/domoticz/www/

#Delete backups older than 31 days
/usr/bin/find /volume1/dataschijf/Domoticz_backup/database/ -name '*.db' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/scripts/ -name '*.tar.gz' -mtime +31 -delete
/usr/bin/find /volume1/dataschijf/Domoticz_backup/www/ -name '*.tar.gz' -mtime +31 -delete
The backup is just stored as a .db file, the two folders (www & script) are compressed in a .tar.gz file. I prefer .zip, but have not yet found out how to configure the 'tar' parameters.

I run it every evening at 23:55 by a cronjob:

Code: Select all

55      23      *       *       *       root    sh      /volume1/@appstore/domoticz/var/scripts/bash/domobackup.sh
I wish i could backup the WWW and Script folder. But i dont have a NAS server. I changed your script with my location but nothing happens.

Code: Select all

#!/bin/bash
    # LOCAL/FTP/SCP/MAIL PARAMETERS
    SERVER="192.168.1.1"   # IP of Network disk, used for ftp
    USERNAME="myuser"         # FTP username of Network disk used for ftp
    PASSWORD="Myspasswrd"         # FTP password of Network disk used for ftp
    DESTDIR="/opt/backup"   # used for temorarily storage
    DOMO_IP="DOMO_ip"  # Domoticz IP 
    DOMO_PORT="DOMO_port"        # 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 /Seagate_Expansion_Drive/Domoticz/scripts/domoticz_scripts_$TIMESTAMP.tar.gz /home/pi/domoticz/scripts
    tar -zcvf /Seagate_Expansion_Drive/Domoticz/domoticz_wwwfolder_$TIMESTAMP.tar.gz /home/pi/domoticz/www
    ### Send to Network disk through FTP
    curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEGZ" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/Seagate_Expansion_Drive/Domoticz/"
    			
    ### Remove temp backup file
    /bin/rm /tmp/$BACKUPFILEGZ
    ### Done!	
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by ThinkPad »

Justintime wrote:
ThinkPad wrote:Just posting my script here, maybe someone can use it. It creates a backup of the database, the www folder (i have custom frontpage.html for my tablet in it) and the scripts folder.
It is based on locations on my NAS, and the backups are also stored on this same NAS.
[...]
I wish i could backup the WWW and Script folder. But i dont have a NAS server. I changed your script with my location but nothing happens.
[...]
Sorry, can't help you. I don't use FTP so i don't know how to modify it to reflect to your situation :(
I am not active on this forum anymore.
mdo82
Posts: 9
Joined: Tuesday 17 November 2015 21:26
Target OS: -
Domoticz version:
Location: The Netherlands
Contact:

Re: Different Backups from Crontab to network

Post by mdo82 »

With this script, I keep an error.
I have no idea just what goes wrong

If i run: sudo domoticz_backup.sh the error i get is:

Code: Select all

sudo: domoticz_backup.sh: command not found
The information what i used is the following:

Code: Select all

#!/bin/bash
# LOCAL/FTP/SCP/MAIL PARAMETERS
SERVER="IP-ADDRESS Network Disk"         # IP of Network disk, used for: ftp mail scp
USERNAME="username"         # FTP username of Network disk used for: ftp mail scp
PASSWORD="password"               # FTP password of Network disk used for: f$
DESTDIR=""      # used for: local
DOMO_IP="IP-ADRESS Domoticz"      # Domoticz IP used for all
DOMO_PORT="8080"         # Domoticz port used for all

### END OF USER CONFIGURABLE PARAMETERS

TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
BACKUPFILE="domoticz_$TIMESTAMP.db"
BACKUPFILEGZ="$BACKUPFILE".gz
Do does anyone know where it is likely to go wrong?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests