Development Roadmap 2019 - Robust Backup Process

Yes I’m on master.

No problem, I’ll wait for you to merge all the changes in and then look at a pull request.

Import is now working fine for me on a non emonSD install. After applying the php upload config in the backup module readme, fixing the import and export script to read the emoncms database name from settings.php and only stopping and starting services if they exist.

Not sure about the menu visibility @borpin, here’s what it should look like:

The Backup entry appears top-left after selecting from the Setup menu.

1 Like

I would really like a way to plug in a USB pen drive into the emonbase/emonpi and backup periodically to the pen drive. The backup module would need to scan for removable media and automatically mount disks on the pi, which could be complicated…?

… and perhaps stream the export rather than build the tar on the emonSD SD card. There are php libraries to export a compressed zip as a stream but I imagine a fair bit of work to implement.

1 Like

The main steps for a manual backup are (this is essentially what the backup module script does):

  1. Export the emoncms mysql database, e.g on a emonSD install:

    mysqldump -u emoncms -p emoncms > emoncms.sql

password: emonpiemoncmsmysql2016

The mysql database contains emoncms meta data such as the user table, the list of feeds, feednames etc. If your using the standard emoncms feed engines there will be no timeseries feed data in the emoncms database.

  1. Copy the content of /var/lib/phpfina, phptimeseries & phpfiwa (if it exists) or /home/pi/data/phpfina… (location on emonSD installations). This is the feed data.

  2. Copy /home/pi/data/emonhub.conf

  3. Copy /var/www/emoncms/settings.php

Optional: manually create a tar.gz file to hold the backup, this is what the assembled backup should look like:

A backup with this structure can be imported with the backup module.

1 Like

It occured to me how the services were being handled. Relates to this post I’ve just done, but there is a mixed environment out there right now.

I’ll have another go at pulling it in but your view is different to mine! Backup used to appear under setup.

Interestingly I do not see schedule either

drwxrwxr-x 15 www-data www-data 4096 Jan 15 17:20 .
drwxrwxr-x  9 www-data www-data 4096 Jan 17 16:30 ..
drwxrwxr-x  3 www-data www-data 4096 Jan 17 17:16 admin
drwxrwxr-x  7 www-data www-data 4096 Jan 11 22:44 app
lrwxrwxrwx  1 www-data www-data   20 Jan 15 17:20 backup -> /root/backup/backup/
drwxrwxr-x  7 www-data www-data 4096 Jan 17 16:13 dashboard
drwxrwxr-x  6 www-data www-data 4096 Dec 27 11:20 device
drwxrwxr-x  3 www-data www-data 4096 Oct 12 22:36 eventp
drwxrwxr-x  5 www-data www-data 4096 Jan 11 22:50 feed
drwxr-xr-x  6 www-data www-data 4096 Jan 11 22:44 graph
drwxrwxr-x  4 www-data www-data 4096 Jan 11 22:50 input
drwxrwxr-x  4 www-data www-data 4096 Oct 12 22:36 process
drwxrwxr-x  4 www-data www-data 4096 Oct 12 22:36 schedule
drwxrwxr-x  2 www-data www-data 4096 Oct 12 22:36 time
drwxrwxr-x  5 www-data www-data 4096 Oct 12 22:36 user
drwxrwxr-x  6 www-data www-data 4096 Oct 12 22:36 vis

I solved the issue - it was permissions.

One thought - it would be worth loading the contents of the config file so you can see before you start what the config is. It could also do a few checks on the paths etc.

The main heading would be better named Backup & Restore - I’d actually call the sections the same instead of Export & Import.

Could this not be included in the emoncms ‘core’ modules, the scripts in the scripts folder and the settings etc pulled into the main settings.php file?

Now I can see the page I’ll sort out the settings and try to create the backup file. :smile:

@TrystanLea, I have tried it and it is silently failing - no errors in backup log or main log. Not even any friendly INFO entries. It is loading the config file.

I’ve tried to work out where it is failing without success.

I should say that I have had to put it in it’s own folder outside of a home directory but it is where $homedir points to.

The export script works fine when run from the commandline.

Thanks for trying @borpin, could it be session related? The backup module requires administration privileges https://github.com/emoncms/backup/blob/master/backup/backup_controller.php#L29 it is currently hidden with any other level of access. You may need to disabled rememberme cookie based login if your using that…?

@TrystanLea - no I don’t think so. I can switch to the Admin screen. Just to be clear, I can now get to the backup page, just when I try an Export, I can see the export and import logs being called (in a separate admin page) but nothing appears in the log screen and no export is created.

The backup process is triggered by service-runner, is that still running?

Is it the right one?
There’s 3 x service runners:

  1. a cron-driven bash based service-runner that is triggered by flag files stored in the filesystem
  2. a cron-driven bash based service-runner that is triggered by a redis value
  3. a systemd managed python based service-runner that is triggered by a redis value.

yip - it is your vastly improved version :smile:

[email protected]:/var/www2/backup# systemctl status service-runner.service
● service-runner.service - Emoncms service-runner Input Script
   Loaded: loaded (/usr/lib/systemd/system/service-runner.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-01-18 20:38:20 GMT; 9h ago
 Main PID: 823 (python)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/service-runner.service
           └─823 /usr/bin/python /var/www/emoncms/scripts/services/service-runner/service-runner.py

Jan 18 20:38:20 DietPi-EmoncmsVM systemd[1]: Started Emoncms service-runner Input Script.
Jan 18 20:38:49 DietPi-EmoncmsVM service-runner[823]: Starting service-runner
Jan 18 20:38:49 DietPi-EmoncmsVM service-runner[823]: Connected to redis-server

Ok, from memory it should log whenever it runs a process - is there anything in the log? There’s nothing in the log extract that appears in your post just now… I wonder if the backup process isn’t pushing the right value to redis?

There is nothing in the log when I push the button. The code looks OK. Debug set to 1 in EmonCMS.

I meant the log for service-runner… but I’ve just tested it here and (despite there being “print” statements in the script) there doesn’t appear to be anything logged in the syslog :frowning:

I’m sure that worked previously…

1 Like

Ok, turns out there IS stuff in the syslog!
Here’s my syslog:

[email protected](ro):~$ tail /var/log/syslog
Jan 19 06:35:17 emonpi service-runner[6731]: Got flag: /home/pi/backup/emoncms-export.sh /tmp/emoncms-flag-export>/home/pi/data/emoncms-export.log
Jan 19 06:35:17 emonpi service-runner[6731]: STARTING: /home/pi/backup/emoncms-export.sh /tmp/emoncms-flag-export > /home/pi/data/emoncms-export.log 2>&1

I have no idea why journalctl -u service-runner says nothing could be found…

What do you get if you run: grep service-runner /var/log/syslog ?

I’m running dietpi in ramlog mode so there is no syslog file! I can access by journctl, but like you there is nothing there.

[edit]
journalctl --system | grep service-runner gives me the same except this warning (which is interesting).

Jan 18 20:48:04 DietPi-EmoncmsVM systemd[1]: Configuration file /usr/lib/systemd/system/service-runner.service is marked executable. Please remove executable permission bits. Proceeding anyway.

Turns out I need sudo to use journalctl :frowning:

[email protected](ro):~$ sudo journalctl -u service-runner
-- Logs begin at Wed 2019-01-02 02:20:01 UTC, end at Sat 2019-01-19 07:02:26 UTC. --
Jan 19 06:35:17 emonpi service-runner[6731]: Got flag: /home/pi/backup/emoncms-export.sh /tmp/emoncms-flag-export>/home/
Jan 19 06:35:17 emonpi service-runner[6731]: STARTING: /home/pi/backup/emoncms-export.sh /tmp/emoncms-flag-export > /hom
Jan 19 06:35:17 emonpi sudo[7459]: pi : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/rm /home/pi/data/emoncms.sql
Jan 19 06:35:17 emonpi sudo[7459]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 19 06:35:18 emonpi sudo[7459]: pam_unix(sudo:session): session closed for user root
Jan 19 06:35:18 emonpi sudo[7470]: pi : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/sbin/service feedwriter stop
Jan 19 06:35:18 emonpi sudo[7470]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 19 06:35:18 emonpi sudo[7470]: pam_unix(sudo:session): session closed for user root
Jan 19 06:45:38 emonpi sudo[10175]: pi : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/sbin/service feedwriter start
Jan 19 06:45:38 emonpi sudo[10175]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 19 06:45:46 emonpi sudo[10175]: pam_unix(sudo:session): session closed for user root
Jan 19 06:45:46 emonpi service-runner[6731]: COMPLETE: /home/pi/backup/emoncms-export.sh /tmp/emoncms-flag-export > /hom

Since you’re running as root, that shouldn’t be your issue. Service-runner should be logging something if it is triggered though - maybe check redis to see if the key is logged?

I was reasonably sure service-runner was working as I think the mqtt output uses it now? If not is there any way to test it?

How can I check redis?

If you stop service-runner first, then trigger a backup, there should be a command waiting in redis for service-runner to execute.

You can grab that command using redis-cli lpop service-runner from a bash prompt - as long as service-runner is not running when you triggered the backup :slight_smile:

1 Like