Manually editing "rogue" data + upgrading from 10.0.1

Yes but upgrade so the old file/folder layout

You will need to do some work on that as it wants the new 3 partitions.

I’ve looked at the backup.php in usefulscripts and it expects the structure as above so it might work.

@alexbloor gave me the login and I went through the usb-import.sh script manually copying commands to work with the structure that he had. It’s all up and running now.


For anyone reading this thread with a similar issue around unrecognised structure, this is the process i went through based on the usb-import script: backup/usb-import.sh at master · emoncms/backup · GitHub

The usb import script had already created the old_sd_root and old_sd_boot mount directories, so I mounted the SD card with:

sudo mount -r /dev/sdb2 /media/old_sd_root/
sudo mount -r /dev/sdb1 /media/old_sd_boot/

You can check at this point that the disk did mount and that you can see the files in each partition.
Next stop running scripts:

sudo systemctl stop emonhub
sudo systemctl stop feedwriter
sudo systemctl stop emoncms_mqtt
sudo systemctl stop mariadb

Check or find the old mysql data directory:

ls /media/old_sd_root/var/lib/mysql/emoncms/

Delete the directory on the new SD card:

sudo rm -rf /var/lib/mysql/emoncms

Copy the old mysql data directory across in it’s place:

sudo cp -rv /media/old_sd_root/var/lib/mysql/emoncms /var/lib/mysql/emoncms

Correct the permissions:

sudo chown mysql:mysql /var/lib/mysql/emoncms
sudo chown -R mysql:mysql /var/lib/mysql/emoncms

Start mariadb:

sudo systemctl start mariadb  

Check/repair tables (password: emonpiemoncmsmysql2016)

mysqlcheck -A --auto-repair -uemoncms -p

Update database:

php /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php

Copy data files across (luckily in @alexbloor’s case only PHPFina no PHPFiwa to convert)

sudo cp -rfv /media/old_sd_root/var/lib/phpfina /var/opt/emoncms/phpfina
sudo cp -rfv /media/old_sd_root/var/lib/phptimeseries /var/opt/emoncms/phptimeseries

If the files copy to /var/opt/emoncms/phpfina/phpfina you will need to move them back to /var/opt/emoncms/phpfina Im not sure what I did wrong here but I had to do that…

Correct permissions:

sudo chwon -R www-data:root /var/opt/emoncms/phpfina
sudo chown -R www-data:root /var/opt/emoncms/phptimeseries/

Lastly you may want to copy your existing emonhub configuration, or I would suggest it might be better to use the new configuration and remap inputs and feeds if required.

The old configuration can be found here:

sudo nano /media/old_sd_root/etc/emonhub/emonhub.conf 

Restart all the scripts:

sudo service emonhub restart
sudo service feedwriter restart
sudo service emoncms_mqtt restart

Check that emonhub is running and that data is coming through:

tail -f /var/log/emonhub/emonhub.log 

Check your inputs and feeds, remap inputs as required.

2 Likes

Brilliant - thanks.

Could the usb-import script be adjusted to cope with the old structure? I think it might be adjusting the mount points.

2 Likes

Thanks @borpin I think @alexbloor was running a custom build not an old emonSD image that we shipped in any volume, so it’s probably not worthwhile adding to the script.

1 Like

I am about 99% positive that is correct.

I installed EmonCMS/etc onto an existing Raspian. So it’s totally non standard and probably wrong in many ways.

Just to make my public thanks to @TrystanLea for the help this evening.

And also @borpin for the pointers which also progressed the solution, albeit my own skill ran out.

1 Like

For future reference, in case others run across this seemingly odd behavior…

This part of the log explains why it went to sdd. (I’ve had this happen many times)
If a USB drive is removed, then reinserted before the OS has had time to “realize”
the drive is no longer present, it’ll bump the drive letter up each time that happens.

I’m not sure how long one needs to wait to prevent that from happening, but I’ve had good
results by waiting ~5 seconds, perhaps a bit more, before reconnecting the USB device.

1 Like

Thanks, good to know :slight_smile: