Raspberry pi Backup to remote server

Hi All.
I want to set up a Network backup of my Raspberry pis. ( Non-OpenHAB )
the are my Remote DB that is spread over my House .
there main function is to collect all my sensor data and do specific monitoring and controll.

  1. Alarm monitoring
  2. ventilation controll
  3. Bathroom extraction

My openhab runs on ubuntu With Openhabian installation.this also runs my 4Tb hard drive for Media sharing.

So to the point.
I want to backup the raspberry pi’s over the network to my Openhab Server. and what to set up a daily backup ( something like rsync or the same) .
I am still new to the whole line environment ( a MAC BOY LOL )
but I am learning. and just not sure how to start with this.

I am from a sunny South Africa and as noted we sometimes battle with power outages and I realised with a bang that some times the pi’s do not like being interrupted . and then I have to start all over with the setup and node red controls setup on them.

if you guys point me in the right direction I can get it tested and sorted and wright a how to if any one would want it.

Thanks for all your help

Hello there :slight_smile:
Questions first, what do you want to backup from the RaspBerryPI?
The local Database?
I created a /backup folder with a mysqlbackup.bash script

echo "Backing up whole database..."
mysqldump -u root -pMySuberSecretPassword --all-databases | gzip > /backup/database_$(date +%d-%m-%Y_%H:%M:%S_Uhr).sql.gz #>/dev/null 2>&1
echo "Finished Backup Job, exit.."

Just a quick note, this script is a quick and dirty solution. There are better ways just google a little :slight_smile:

This script is getting executed by crontab.

0 0,6,12,18 * * * root /backup/mysqlbackup.bash

created with https://crontab-generator.org/

Further more, you could create a simple bash script with rsync commands what to backup, and execute that via crontab.
That would be a manual approach.

You could also checkout http://duplicity.nongnu.org/

Install Amanda from the openHABian menu. It’s preconfigured to backup the openhabian box but can easily be extended to include other machines into its backup (even Windows & Mac).
See https://wiki.zmanda.com/index.php/How_Tos#Client

My main concern to backup is my scripts and node red flows. I think that is the DB important part. As i hade to redo it over the week end. And to get to the DB is n big task. And i lost the termination sheet for the DB. Should have
Stuck it in the panel. So hade to take everything down to get the schedule re drawn.


With scripts I assume they are just local files, backing up those isn’t that hard.
But the node-red part tho, I just took a quick look at my setup (docker-based), my node-red folder has a flows.json which contains all created flows, if it’s just a file that can also easily backuped.

Hi Thanks for the reply’s.

Yes it is all local files.

I think it is just that one file for node red’s flow’s that needs to be copied.

when I use to use windows I used copy in the windows environment. at my clients to do remote of site backups. not sure if copy would work . and my script for it use to be a manual triger from windows.

as I am still in the learning phase . on linx I am not sure how to do that.

Did you read/checkout the information given by @mstormi?
Just for convenience here is the README.md from openHABian on the Amanda Topic.

on the db I did not install using openhabian . what I will do is install Amanda manual and start from there.

Question is, on the DB Server, do you really need Amanda just for the backup of the database?
I don’t know your Backup solution, I would assume a setup like this from your information.
openHAB Server, Database Server and a backup storage NAS or something?

If there is a dedicated backup server, simple self written scripts would be good for me. But that’s my flavor :slight_smile:
If it’s just a single job/task I don’t want an extra software for the backup.

I think it would be best if you give some information about your Setup.
What Servers, which operating system yada yada

This way the community can help better :slight_smile:

Thats the thing.
as I have a server running openhab on ubuntu . ( to where I want to make my backups.)
all I want to do is keep backups of my flows and scripts that is running on my DB. so a simple script should be more then proper to do the backup. all it must do is compare what is backed up and if there where changes copy the new file over to the server . it is a simple solution , but it is just to save me some time if something goes astray . and then I don’t need to re do every thing and try and remember my changes.
or maybe I just should use git to make a ver control like I run my openhab configs.

Thank god there is a default linux tool that just does that :smiley: called rsync which can do a differential backup, which you described. (Only backup what changed since time xyz)

The RaspBerryPi needs sshd (ssh Server) enabled.

# check the status of the sshd service
sudo systemctl status sshd.service

# If Status tells the service is stoped - start the sshd serive
sudo systemctl start sshd.service

# Want the service to be started on boot?
sudo systemctl enable sshd.service

Next steps would be to generate an ssh-key for the Ubuntu Server

# On Ubuntu

Now we need to enable the Ubuntu Server to communicate with the RaspBerryPi without a password via ssh-key authentication.

# On Ubuntu - assuming you run the script as root and RaspBerryPi username is openhabian
ssh-copy-id -i /root/.ssh/id_rsa.pub openhabian@192.168.178.X 

You can test if everything worked fine when you try to login to your Pi with SSH and don’t get asked for a password

# login to Pi from Ubuntu
ssh openhabian@192.168.178.X

Thats done? Good

Next step is to have a list of Folders and Files you want to Backup from the Pi

Example I want to backup the /etc/openhab2/ Folder

# From Ubuntu
rsync -avrl openhabian@192.168.178.X:/etc/openhab2 /backups/openhab2_conf

Worked? Good :smiley:
Now you could create a simple bash script an place it in /backups/

echo "Starting Backup Job"
rsync -avrl openhabian@192.168.178.X:/etc/openhab2 /backups/openhab2_conf
rsync -avrl # more things you want to backup
echo "Backup Job Completed"

I use Crontab-Generator (Task scheduler)

# Create the crontab task
crontab -e
# example job from crontab-generator
0 0 */5 * * /backups/back_me_up.bash > /var/log/cron_backup.log
# This would run the backup script every 5 days on midnight
# and would save the output from the script to /var/log/cron_backup.log

And I just noticed that openHAB is running on Ubuntu :rofl:
Well then you have to do described steps for the “Database Server”.
I already posted a script which backups all databases, just append it with the rsync.

Hope my little HowTo is not tooooooo confusing :slight_smile:

I will test it tonight . I only have remote cases to my Server. I need to go and check my DB as it seems my power has failed to it. will let you know.

Thanks for All The help

Thank you it works


Nice to hear it all worked out for you :slight_smile:

ps: you can edit your messages, no need to delete them.

Also if you write something because you got stuck at a certain point, no wrong shame! Other users will get stuck at the same point, the more information you provide the better you can help others :call_me_hand:
(I have no clue what was inside those deleted messages. Just assuming since that is what happens very often =) )

I actually asked how do I do the Bash script. but then I googled it and bam.
got it to work