Set up automatic backup Domoticz database
The importance of a backup
Making a backup is often underestimated. The value of a backup is only appreciated when the damage has already been done. Now I use Domoticz as a hobby and it is interesting to keep track of data, operate things remotely, etc.
For backing up data I use the 3-2-1 rule:
- 3: Provide at least 3 copies of your data.
- 2: Save the copies on at least two different media.
- 1: Keep at least one copy outside your organization.
Should the data of Domoticz be lost for whatever reason, there is (for me) no man overboard and I start again. But prevention is better than cure, so I make sure that the Domoticz database is automatically stored in the cloud. For this I use duplication.
With Duplicati you can back up to different Cloud platforms such as Backblaze B2, Tardigrade, Microsoft OneDrive, Amazon S3, Google Drive, box.com, Mega, hubiC, etc. Duplicati is open source software and free!
Step 1: Install Mono Framework
Install it mono framework to use Duplicati.
sudo apt install mono-complete ca-certificates-mono -y
The entire framework is installed with this. Of ca-certificates-mono -y
SSL certificates are installed to get HTTPS connections. If you experience problems with making HTTPS connections, it is advisable to install this as well.
Step 2: Sync the certificates
sudo cert-sync /etc/ssl/certs/ca-certificates.crt
Step 3: Install Duplicate
wget https://updates.duplicati.com/beta/duplicati_2.0.6.1-1_all.deb sudo apt-get install ./duplicati_2.0.6.1-1_all.deb -y
Step 4: Install missing program files
sudo apt -f install -y
Step 5: Create and edit the service file
sudo nano /etc/systemd/system/duplicati.service
The service file should look like this:
[Unit] Description=Duplicati web-server After=network.target [Service] Nice=19 IOSchedulingClass=idle EnvironmentFile=-/etc/default/duplicati ExecStart=/usr/bin/duplicati-server $DAEMON_OPTS Restart=always [Install] WantedBy =multiuser.target
Copy and paste the above code into the configuration file and save it.
Step 6: Configure the init script
sudo nano /etc/default/duplicate
# Defaults for duplicati initscript # sourced by /etc/init.d/duplicati # installed at /etc/default/duplicati by the maintainer scripts # # This is a POSIX shell fragment # # Additional options that are passed to the Daemon. DAEMON_OPTS="--webservice-interface=any --webservice-port=8200 --portable-mode"
Step 7: Start Duplicati service
To start the service we use the following commands.
sudo systemctl enable duplicati.service
sudo systemctl daemon-reload
sudo systemctl start duplicati.service
sudo systemctl status duplicati.service
Step 8: Open the Duplicati web interface
http:// :8200
After opening the Duplicati web interface you will see the message below. Choose “No, my machine has only a single account”.
Step 9: Add Backup
Click the “Add Backup” button in the menu and select “Set up a new backup”.
Step 10: General Backup Settings
Give the backup a clear name, description and possibly password. Be sure to keep the password in a safe place if you ever need to restore a backup. You can also choose not to enter a password.
Step 11: Select destination backup location
- Select the storage type where you want to save the backup.
- Specify the path on the server.
- Enter username and/or password if necessary.
Step 12: Select source backup location
Select the folder /home/pi/domoticz/
as a source. Everything in the domoticz/ folder will be backed up.
Step 13: Schedule the automatic backup
Specify when the backup should be performed. I always back up twice a day. Once during the day and once at night.
Step 14: Backup Options
Within the options you can specify the file size of the volumes. If you choose 50 MB and your backup is 144 MB, the backup will be split into two volumes of 50 MB and one volume of 44 MB.
Under “Backup retention” choose an option that suits you best. Also take into account the available space of the target location.
Step 15: Additional Options
It is possible to send e-mails via additional settings if a backup has been performed (incorrectly). on https://forum.duplicati.com/t/how-to-configure-automatic-email-notifications-via-gmail-for-every-backup-job/869 it explains step by step how to do this.
Dit delen:
- Klik om te delen met Twitter (Wordt in een nieuw venster geopend)
- Klik om te delen op Facebook (Wordt in een nieuw venster geopend)
- Meer
- Klik om dit te e-mailen naar een vriend (Wordt in een nieuw venster geopend)
- Klik om op LinkedIn te delen (Wordt in een nieuw venster geopend)
- Klik om te delen met Reddit (Wordt in een nieuw venster geopend)
- Klik om op Tumblr te delen (Wordt in een nieuw venster geopend)
- Klik om te delen op Telegram (Wordt in een nieuw venster geopend)
- Klik om te delen op WhatsApp (Wordt in een nieuw venster geopend)
I do it like this:
Create a script file: backups.sh for example
#!/bin/bash
# LOCAL/FTP/SCP/MAIL PARAMETERS
SERVER=”xxx.xxx.xx.xx” # IP of your hosting account you ftpt to.
USERNAME=”yourusername” # FTP username
PASSWORD=”passwordhere” # FTP password
DESTDIR=”/opt/backup” # for temporary storage
DOMO_IP=”xxx.xxx.xx.x” # Domoticz IP
DOMO_PORT=”8080″ # Domoticz port
### End of configurable items
TIMESTAMP=
/bin/date +%Y%m%d%H%M%S
BACKUPFILE=”domoticz_$TIMESTAMP.db” # backups will be named “domoticz_YYYYMMDDHHMMSS.db.gz”
BACKUPFILEGZ=”$BACKUPFILE”.gz
### Make a backup, ZIP it and restart Domoticz
/usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /tmp/$BACKUPFILE
gzip -9 /tmp/$BACKUPFILE
### Send to your hosting environment via FTP
curl -s –disable-epsv -v -T”/tmp/$BACKUPFILEGZ” -u”$USERNAME:$PASSWORD” “ftp://$SERVER/”
### Remove temp backup file
/bin/rm /tmp/$BACKUPFILEGZ
### Done!
store
Make file executable:
chmod +x backups.sh
Test if it works
./backups.sh
Create a crontab:
.crontab -e
4 5 * * * /home/domoticz/backups.sh
Now a daily backup of your database is saved in your hosting environment.
Hi Mr Marcie,
There are several roads to Rome (luckily). And everything has its pros and cons. In your case I would make sure that the folder in which the data is stored is not accessible to other people. The folder must therefore be secured with a login.
Thanks for sharing your script.