Restoring data into emoncms

There are lots of forum posts, blog posts & backup scripts to assist users in backing up data from emoncms, but very little about restoring it after things have gone wrong.

I always presumed that it would done by halting apache & emonhub, and replacing the phpfiwa, phpfina, phptimeseries folders with the backup folders (disregarding mysql for the moment), and then restarting the services.

But that does not seem to work!
I tried this process not through necessity, but to ensure that I could restore if I needed to.
The result I got was that all my historical data was intact as far as I could see, but emoncms seemed to struggle with current data inputs;

  1. The current inputs are showing being updated in the inputs page, although the 'last updated' time fluctuated randomly - 2s, 4m, 30s, 5s, 3m, despite the input being updated every 7 seconds.
  2. The current values were not being recorded in a corresponding graph, and checking the graphs at current time showed no datapoints.

The apache error log showed;

[Sun Nov 09 18:58:59 2014] [error] [client 127.0.0.1] PHP Warning:
fopen(/var/lib/phpfiwa/1_0.dat): failed to open stream: Permission denied
in /var/www/emoncms/Modules/feed/engine/PHPFiwa.php on line 154

so I tried;

sudo chown www-data:root /var/lib/phpfiwa
sudo chmod 755 /var/lib/phpfiwa

...for each of the directories, but got exactly the same result.

Paul

pb66's picture

Re: Restoring data into emoncms

what are the permissions for the files within the directories ? If you run

ls -la  /var/lib/phpfiwa

​are they www-data:root? if not you could try adding a -R (recursive) switch to chown ie

sudo chown -R www-data:root /var/lib/phpfiwa

​Paul

Paul Reed's picture

Re: Restoring data into emoncms

Hi Paul, well spotted! 
The file permissions were pi:pi and not www-data:root.

So for future reference, the data folders restore process should be;

1) Stop emonhub & apache

$ sudo service apache2 stop
$ sudo service emonhub stop

2) Replace the data folders phpfiwa, phpfina, phptimeseries in /var/lib/ with your 'backup' folders.

3) Set the permissions for the data folders

$ sudo chown -R www-data:root /var/lib/phpfiwa
$ sudo chown -R www-data:root /var/lib/phpfina
$ sudo chown -R www-data:root /var/lib/phptimeseries

​4) Restart emonhub & apache

$ sudo service apache2 start
$ sudo service emonhub start

Paul

pb66's picture

Re: Restoring data into emoncms

I guess you could even just pause emonhub from posting to emoncms for the duration of the restore and then allow it to catch up so you have no loss of data.

If you add a setting  " pause = out " (pause output only) to [[emoncms]][[[runtimesettings]]] in emonhub.conf it would continue to collect data in the buffer without sending it to emoncms and would therefore not need to stop, when you finished the restore and have restarted apache2, delete, comment out or set it to " pause = off " to post the buffer contents and continue business as usual.

Paul

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.