Automatic backup: Every day or week

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Automatic backup: Every day or week

Post by Ritmeester »

Automatic backup.

I installed a new Pi 3+ as Master. I forgot to make the last manual DB backup but this is not a big problem because I didn’t change anything after the last DB backup.

The only thing what I miss is my 1-Wire (6 sensors) data.

So is there an option or script what can send every day or week the DB and scripts folder to: *

* I have a in my network an Synology NAS and I have Dropbox.

What will be the best way to backup this and how?

(WhatsApp has for example an everyday backup to Google Drive. )
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Automatic backup: Every day or week

Post by EdwinK »

I just followed the steps outlined here. And it works great.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Automatic backup: Every day or week

Post by Ritmeester »

Tanks EdwinK,

I missed this :-( I will take look to it.

Thanks.
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Automatic backup: Every day or week

Post by HansieNL »

I have a NSF share (Synology) mounted on the Raspberry Pi. I created a backup script that runs via a crontab job every night.
If the backup is older than 14 days it will be deleted.

Code: Select all

#!/bin/bash
### PLACE THIS SCRIPT IN:/home/pi/domoticz/scripts as domoticz_backup.sh
DOMO_IP="192.168.2.1"  # Domoticz IP 
DOMO_PORT="8080"        # Domoticz port 
### END OF USER CONFIGURABLE PARAMETERS
TIMESTAMP=`/bin/date +%Y%m%d%H%M`

BACKUPDBFILE="domoticz_$TIMESTAMP.db"
BACKUPFILES="domoticz_$TIMESTAMP.tar.gz"

echo -e "\n\e[1;33mBacking up Domoticz. Please standby...\e[0m\n"
 
#Create backup and make tar archives
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /mnt/backupz/$BACKUPDBFILE
sudo tar --exclude='domoticz.db-shm' --exclude='domoticz.db-wal' --exclude='/home/pi/domoticz/www/dashticz/.git' -zcvf /mnt/backupz/$BACKUPFILES -T /home/pi/domoticz/scripts/domoticz_backup.lst
 
#Delete backups older than 14 days
/usr/bin/find /mnt/backupz/ -name '*.db' -mtime +14 -delete
/usr/bin/find /mnt/backupz/ -name 'domoticz_*.tar.gz' -mtime +14 -delete

echo -e "\n\e[1;33mBacking up Domoticz finished!\e[0m\n"
domoticz_backup.lst
Spoiler: show
/etc/fail2ban/filter.d/domoticz.conf
/etc/fail2ban/jail.local
/etc/fstab
/etc/init.d/domoticz.sh
/etc/logrotate.d/domoticz
/home/pi
Blah blah blah
astrapowerrr
Posts: 141
Joined: Tuesday 31 January 2017 20:34
Target OS: -
Domoticz version:
Contact:

Re: Automatic backup: Every day or week

Post by astrapowerrr »

hi

just installed the backup like in the wiki.
when i test the script it makes a backup..
but it doesnt make the backup automaticly..

followed the wiki exactly..
pi@raspberrypi:~ $ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
# * * * * * commando dat uitgevoerd moet worden
# - - - - -
# | | | | |
# | | | | +--------------------- dag van de week (0 - 6) (zondag=0)
# | | | +-------------------- maand (1 - 12)
# | | +--------- dag van de maand(1 - 31)
# | +----------- uur (0 - 23)
# +--------- minuten (0 - 59)
#------------------------------------------------------------------------
0 1 * * * sudo home/pi/domoticz/scripts/domoticz_backup.sh
0 3 22 * * /mnt/backup/system_backup.sh
but when i

Code: Select all

sudo home/pi/domoticz/scripts/domoticz_backup.sh
it makes a a backup perfectly
also tried

Code: Select all

sudo ~/domoticz/scripts/domoticz_backup.sh
and tried without sudo, and tried with pi instead of sudo.. but nothing
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Automatic backup: Every day or week

Post by waaren »

astrapowerrr wrote: Saturday 20 April 2019 23:14 0 1 * * * sudo home/pi/domoticz/scripts/domoticz_backup.sh
Try to use a full qualified path
0 1 * * * sudo /home/pi/domoticz/scripts/domoticz_backup.sh
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
astrapowerrr
Posts: 141
Joined: Tuesday 31 January 2017 20:34
Target OS: -
Domoticz version:
Contact:

Re: Automatic backup: Every day or week

Post by astrapowerrr »

waaren wrote:
astrapowerrr wrote: Saturday 20 April 2019 23:14 0 1 * * * sudo home/pi/domoticz/scripts/domoticz_backup.sh
Try to use a full qualified path
0 1 * * * sudo /home/pi/domoticz/scripts/domoticz_backup.sh
Will try that tomorrow. I als tried it like sudo ~/Domoticz just like in the wiki. That should also work I thought.


Verzonden vanaf mijn iPhone met Tapatalk
astrapowerrr
Posts: 141
Joined: Tuesday 31 January 2017 20:34
Target OS: -
Domoticz version:
Contact:

Re: Automatic backup: Every day or week

Post by astrapowerrr »

nope.. not working :roll:

when i enter

Code: Select all

~/domoticz/scripts/domoticz_backup.sh
i get as a result all is finished with no problems.

when i look at my server folder i have a perfect backup.
so script is working and also manual.
but when i use contrab its not making any backup.
here is my file

Code: Select all

pi@raspberrypi:~ $ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
# *     *     *   *    *        commando dat uitgevoerd moet worden
# -     -     -   -    -
# |     |     |   |    |
# |     |     |   |    +--------------------- dag van de week (0 - 6) (zondag=0)
# |     |     |   +-------------------- maand (1 - 12)
# |     |     +--------- dag van de maand(1 - 31)
# |     +----------- uur (0 - 23)
# +--------- minuten (0 - 59)
#------------------------------------------------------------------------

18 20 * * * sudo ~/domoticz/scripts/domoticz_backup.sh


pi@raspberrypi:~ $
how is this possible…?
the time is for me to try over and over.. as this is for 20:18 everyday if i understand correctly.
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: Automatic backup: Every day or week

Post by Minglarn »

Is it possible to make the bash script archive into same tar?

I've these folders backed up every night 01:00.

Code: Select all

    ### 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"
    curl -s --disable-epsv -v -T"/tmp/plugins_scripts_$TIMESTAMP.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS
Is it possible to make only 1 archive instead of 4?
When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Automatic backup: Every day or week

Post by waaren »

astrapowerrr wrote: Monday 22 April 2019 20:23 nope.. not working :roll:
how is this possible…?
If you type sudo crontab -l you will see the crontab for root.
in that crontab the command sudo ~/domoticz/scripts/domoticz_backup.sh
will try to execute the script /root/domoticz/scripts/domoticz_backup.sh (because executed as root)
That's why I suggested to use the full qualified name being /home/pi/domoticz/scripts/domoticz_backup.sh
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
astrapowerrr
Posts: 141
Joined: Tuesday 31 January 2017 20:34
Target OS: -
Domoticz version:
Contact:

Re: Automatic backup: Every day or week

Post by astrapowerrr »

waaren wrote:
astrapowerrr wrote: Monday 22 April 2019 20:23 nope.. not working :roll:
how is this possible…?
If you type sudo crontab -l you will see the crontab for root.
in that crontab the command sudo ~/domoticz/scripts/domoticz_backup.sh
will try to execute the script /root/domoticz/scripts/domoticz_backup.sh (because executed as root)
That's why I suggested to use the full qualified name being /home/pi/domoticz/scripts/domoticz_backup.sh
Yes! Thanks!!


Verzonden vanaf mijn iPhone met Tapatalk
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest