How to migrate Node-RED from an old Raspberry Pi to a new one, with all your configurations, plugins and flows. If you haven’t already setup your new Raspberry, have a look at my post Setup a Raspberry Pi 4 with USB SSD. Additional I have a tutorial how to setup Node-RED on the new Raspberry Pi 4. The easiest way to get the data to your new System is with a USB SD Card adapter. Find my description in the dollowing post How to mount a USB Device.
Now you are ready, so let’s start with the migration.
Stop Node-RED on your target Raspberry Pi
Before you start with the migration, make sure, that your target system is already setup properly. Your system should be running with Node-RED installed, and the data from your old Node-RED instance at hand. Check out my posts, which are linked in the intro of this post, if you haven’t all ready.
Stop the running Node-RED instance with the command line tool which was installed with Node-RED.
Backup your actual Node-RED Folder
Backup your actual configuration, just in case something went wrong. You will be able to switch back to the state before you started the migration. In the next steps you will overwrite the configuration with the files from your old instance. Therefore you should do this on a new Node-RED installation without any configurations. If you have changes in this new instance you have to add them manually after this migration.
The default folder for Node-RED is in your Home directory, with the name .node-red. Just copy the whole folder to a new one with the ending .bak.
cp -R ~/.node-red ~/.node-red.bak
Migrate / Restore Node-RED on your Raspberry Pi
Next use your USB adapter with the SD Card of your old device with the Node-RED Data you want to migrate to your new Raspberry Pi. If you followed my guide How to mount a USB Device on your Raspberry, you have the needed data mounted in /media/usb. The Node-RED default folder is in the Home directory, and the Raspberry default user is pi. Therefore the directory after the mount point is /home/pi/.noder-red. Change this, if your old Node-RED installation was running under a different user or installed in another directory.
Next, copy all json Files and the settings.js file to your new Instance.
cp /media/usb/home/pi/.node-red/*.json ~/.node-red cp /media/usb/home/pi/.node-red/settings.js ~/.node-red
If you had additional plugins installed, which has additional persistent data stored, make sure to copy them also. There are thousands of plugins so check what you have installed, and if you need some additional informations. For example if you use the HomeKit plugin, you should also copy the HomeKit-persist folder in your Node-RED root directory. If you use the Alexa Plugin the Authentication token is stored in the directory you have configured in the Configuration node. In my case it’s stored in the Users home folder, with my given name alexa_token.
So copy all additional Information from your specific plugins, for example HomeKit and Alexa, this depends on your settings, and the following are just examples!
cp -R /media/usb/home/pi/.node-red/homekit-persist ~/.node-red cp /media/usb/home/pi/alexa_token ~
Rename the Flow File
If the server name between your old and your new Raspberry Pi is different, the Flow File Names also have to be changed. When starting Up Node-Red you get the output where your Flow-Files are stored. You could also just look into the Log and search for this information. You get the log with the Node-RED command line tool.
Next you have to change the previous copied flow names to the correct ones for your new instance. If the hostname changed for example from raspberrypi3 to raspberrypi4 just rename that file. Do not rename the *_cred.json File, this is encrypted with a machine specific Key and if you have moved this from another server you would get an error!
Replace the source and target filenames with your specific File Names
mv ~/.node-red/flows_raspberrypi3.json ~/.node-red/flows_raspberrypi4.json
Plugin Installation with NPM
To get all your previous installed plugins from the old instance running again, with all their dependencies, you have to Re-Build the NPM Packages. Just change into the Node-RED Home directory and run rpm install. Depending on the number of your installed plugins, this could take a while.
cd ~/.node-red npm install
You are now ready to start your new Node-Red instance on your new Raspberry Pi with the migrated installation from your previous instance. Just start it with the Node-RED command line tools.
Check your running Node-RED
Check your Log Files and the Web Site from your Node-RED Instance. Everything should be up and running again. You could use this steps also to backup and restore your settings, if you are interested, leave me a comment and I’ll write a specific blog for Backup/Restore your Node-Red.
With this short tutorial you migrated Node-Red to a new Raspberry Pi. You copied the needed Node-RED files from the old Raspberry Pi with an USB SD Card Adapter to the SSD or SD card of your new Raspberry Pi 4.
If you have any questions or suggestions, or if you would like further information, please let me now in the comments.