Restoring Dropbox-archive backups

A bit drastic I know… but I decided to crash test the viability of manually restoring ‘dropbox-archive’ backups to emoncms, so if I do have future problems, I can be confident that they can be rectified.

Test Preparation
Firstly, I made a full partition backup in case I ran into problems, then deleted my emoncms phpfiwa, phpfina & phptimeseries directories, dropped my ‘emoncms’ database, and for good measure totally nuked all node-red user data, including flows & creds.

Prepare Backup Data
Download the dropbox backup.tar.gz archive to a new clean directory.
This can be done a number of ways, but I’ve found it easiest to use a small script contained in your dropbox-archive/lib directory which enables you to download the archive from dropbox direct to your Rasp Pi.
Navigate to the dropbox-archive/lib directory and run the script - ./dropShell.sh
Type cd backups followed by ls which will display a list of your remote backups.
Download whichever backup you wish by typing get archive_???.tar.gz and it will be downloaded to your dropbox-archive/lib directory.
Type exit to exit the script.
Now move the archive to a new clean directory, change directory to it, and extract it’s contents;
sudo tar -zxvf backup.tar.gz and the extracted data sub-directories will appear in the current directory.

Restore Emoncms Data
If you have existing emoncms data folders in /var/lib then delete them first, and copy the new ‘backup’ folders to /var/lib
Then set their ownership;
sudo chown -R www-data:root /var/lib/{phpfiwa,phpfina,phptimestore,phptimeseries}

Import MYSQL Database
Presuming you are replacing an existing emoncms database which is corrupt or contains incorrect data, it is necessary to firstly delete it, followed by re-creating a new clean emoncms database which will hold your imported data.
Log into MYSQL and enter your MYSQL ‘root’ password;
sudo mysql -p -u root
Delete (drop) the existing emoncms database;
mysql> DROP DATABASE emoncms;
Recreate a new empty database;
mysql> CREATE DATABASE emoncms;
Exit MYSQL - mysql> exit, then change directory to where your new extracted .sql backup file is stored (lets call it backup.sql).
Then import the MYSQL backup - again adding your MYSQL root password;
sudo mysql -p -u root emoncms < backup.sql
then exit;
mysql> exit

Restore Node-red
Delete the existing node-red data directory;
rm -rf /home/pi/.node-red
and copy the new extracted .node-red directory to replace it.
Change the directory/files ownership;
sudo chown -R pi:pi /home/pi/.node-red

Outcome
A quick reboot, and both node-red & emoncms seamlessly continued, with the only data loss being between the time of the dropbox-archive, and the time of restoring it, which is as expected.
Perhaps it would also be useful to include the emoncms ‘settings.php’ in the backup archive?

Paul

2 Likes

A post was merged into an existing topic: Emoncms backup to Dropbox