Emoncms automatic data backup from EmonPi to Remote Computer

Good attitude!

Ya gotta be careful with that, though. It can bite ya in the backside when ya least expect it.

thumbsup

It would be nice if we could plugin a usb stick in to the Pi and run a nightly backup

Options as i see them are:
attach a USB stick on the Pi (which is easy - format it/mount it/ add an entry in /etc/fstab)
Change the backup script :slight_smile:
First set up some ssh-keys from the Pi to the backup server.
Have a base directory on the remote server to hold as “todays” backup area
($date is defined in the backup script)
define a new variable BACKUP_SERVER for your backup server

ssh $BACKUP_SERVER "cd $BACKUP_AREA ; mkdir $date"

edit the backup script

change mysqldump -u$username -p$password emoncms > $backup_location/emoncms.sql
to
mysqldump -u$username -p$password emoncms | ssh $BACKUP_SERVER "cd $BACKUP_AREA/$date ; > emoncms.sql"

change

to
tar -cf - $backup_location/emoncms.sql $emonhub_config_path/emonhub.conf $emoncms_location/settings.php --transform 's?.*/??g' 2>&1 | ssh $BACKUP_SERVER "tar -C $BACKUP_AREA/$date -xf - "

similarly
change
tar -vr --file=$backup_location/emoncms-backup-$date.tar -C $mysql_path phpfina
to (this one i’m guessing)
tar -cf - $mysql_path/phpfina | ssh $BACKUP_SERVER "tar -C $BACKUP_AREA/$date -xf - " ```

again same as above

tar -vr --file=$backup_location/emoncms-backup-$date.tar -C $mysql_path phptimeseries
to
tar -cf - $mysql_path/phptimeseries | ssh $BACKUP_SERVER "tar -C $BACKUP_AREA/$date -xf - " ```

In essence we are using unix’s power of redirecting stdout over the ssh tunnel to the remote server.
With the adjustments above you’ll not write to disc on the pi for any of the output.

worth a try :wink:

Thanks Dave,

There’s a lot there for me to digest. I’ll work on this over the weekend and report back.

Neil

2019-04-12T04:00:00Z

I had it figured out for the compression parts but not yet this part:

I’m having trouble generating SSH Keys for ssh’ing into a MacBook. Works when I ssh into a RPi but not the other way around. I don’t want my server pw exposed in plain text. I’ll figure that out.

For now I found a spare USB stick and used that. Simples :smile:

Thanks to everyone for your input. I’m amazed at how helpful everyone is, its a great learning experience for me.

Best wishes