Well, there is a way to change IPs without re-establishing all your sources, but it's not for the faint of heart.
I'm posting here the process that worked for me, in case it helps anyone else.
My setup uses OpenElec, so some small aspects might differ from what you have. Also my machines are all Linux.
Some of my IPs: (replace with your own)
- my Kodi machine: 192.186.1.4
- old media server IP: 192.186.2.222
- new media server IP: 192.186.1.111
Note: I didn't want to have to do this process again and again, every time IP addresses change, so I decided to use a DNS name for the new media server. I decided to use "
diskstation" as the DNS name. If you'd like to do this too, then think of a one-word name and see the DNS Note in step 1 below.
So here goes...
STEP 1. ssh into your Kodi server:
If you've never done this before, you might have to google to find the right username/password for your setup. In my case it was root/openelec.
DNS Note:
If you want to use a DNS name instead of an IP address for your file server (which will save you from doing this process every time you renumber) then carry out these steps on the Kodi machine (as root):
- Edit your DNS hosts file. This is usually /storage/.config/hosts.conf, but can sometimes be /etc/hosts directly. In my case it was the former:
Code:
sudo nano /storage/.config/hosts.conf
- Add a new line consisting of the new IP address, then some whitespace (spaces or tab) then the hostname. Mine looked like this:
Quote:192.168.1.111 diskstation
- Save the file: Ctrl-O, and then exit nano Ctrl-X.
- If your edits were made in /storage/.config/hosts.conf, then reboot:
(this will close your ssh session)
- After Kodi machine has restarted, ssh into it again:
- Then check that your DNS name is active:
You should get a result similar to this:
Quote:# ping diskstation
PING diskstation (192.168.1.111): 56 data bytes
64 bytes from 192.186.1.111: seq=0 ttl=64 time=0.163 ms
64 bytes from 192.186.1.111: seq=1 ttl=64 time=0.171 ms
64 bytes from 192.186.1.111: seq=2 ttl=64 time=0.163 ms
[...]
- If that worked then in the following steps you can use "diskstation" (or whatever name you chose) instead of the new IP.
- Next time you renumber your media server, you can ignore all the following steps, and instead edit the line you just added same file (eg: /storage/.config/hosts.conf), changing the IP address.
STEP 2. Go into your kodi folder:
(I found
this page very helpful in working out where this is)
Code:
cd /storage/.kodi/userdata/
STEP 3. Find occurrences of the old IP:
Code:
grep -rc "192\.168\.2\.222" *
This will take a while. It outputs the names of the files that contain the old IP address, along with the number of lines in which it was found in each file. In my case, the following files were found:
Quote:Database/ViewModes6.db:4
Database/MyVideos90.db:12100
Database/Textures13.db:6236
sources.xml:3
So
sources.xml is a text file, great! That can be edited in place. Unfortunately the others are all SQLite databases. So...
STEP 4. Copy files to your local machine:
I preferred to work on my own machine, since I have a GUI there. There are SQLite command-line tools, but I wanted to see chunks of data as well, in order to confirm that I was doing things right. So I copied all the files to my local machine to work on them.
On my local machine:
Code:
#create a folder to work in
mkdir /tmp/kodi_files
cd /tmp/kodi_files
#copy all the files that contained the old IP address
scp [email protected]:/storage/.kodi/userdata/Database/ViewModes6.db .
scp [email protected]:/storage/.kodi/userdata/Database/MyVideos90.db .
scp [email protected]:/storage/.kodi/userdata/Database/Textures13.db .
Note: don't just copy the above if your set of files was different to mine. Adjust according to the files you found.
STEP 5. Load up your SQLite database manager:
I didn't have one, but found SQLiteMan in the Ubuntu Software Center and installed it.
It could also be installed through command line, like this
Code:
sudo apt-get install sqliteman
Once installed, run it, and open up one of the above files. eg: ViewModes6.db
Next we have to find which fields, of which tables, contain data that needs to be updated. This is a bit tedious so bear with me.
5. Dump the database:
I found that the easiest way to determine which fields needed updating was to dump the entire database to a .sql file. This creates a plain text file with a whole bunch of SQL INSERT statements that would re-create the same database. It is handy for us because it identifies the tables and fields we need to work on. I first thought there might be a better way to search the contents of all fields in all tables, but I couldn't find one. If anyone knows a better way, please advise.
In Sqliteman, the sequence of commands (starting from main menu) was:
Database >
Dump Database
Let's call the file by the same name, with a different suffix, eg:
ViewModes6.sql
STEP 6. Find occurrences of the old IP:
Back in the command-line prompt, find the first few occurrences of the old IP address:
Code:
grep "192\.168\.2\.222" ViewModes6.sql | head -10
This shows the first 10 lines that contained the old IP address. Each line starts with something like this:
Quote:INSERT INTO "view" VALUES(7,10025,'nfs://192.186.2.222/volume1/video/movies/' ...
This tells us what we need to know:
- the table is called "view" (may be different each time)
- the field containing the old IP is the 3rd field in the list of values (would be different each time)
STEP 7. Replace occurrences of the old IP in SQL:
- Back in SQLiteMan, double-click the "view" table (or whatever table was found) to open it. You should see rows of data on the bottom right, and space to write queries on top right.
- Click "Columns" on the left to open the list of fields. Get the field name by counting to the 3rd field. In this case it was called "path":
- Create an UPDATE statement to replace all occurrences of the old IP with the new one, eg:
Code:
UPDATE view SET path = REPLACE(path, '192.168.2.222', '192.168.1.111');
Note: if you chose to use a DNS name, instead of an IP, then use the DNS name in your query instead. It might look like this:
Code:
UPDATE view SET path = REPLACE(path, '192.168.2.222', 'diskstation');
- Enter that statement in the query pane, and run it by clicking the single green arrow:
- If no errors, then occurrences of the old IP in the path field of the view table have now been replaced, well done!
- Now go back to step 5 and repeat. You will find different tables and fields each time. I think I only needed to run 4 updates - it didn't take long.
- When the "grep" command in step 6 finds nothing, then you are done replacing, and can proceed to the next step.
STEP 8. Backup the files that are going to be changed:
On the Kodi machine (in your ssh session) make backups of all the affected files. Mine were:
Code:
cp /storage/.kodi/userdata/Database/MyVideos90.db /storage/.kodi/userdata/Database/MyVideos90.db.BAK
cp /storage/.kodi/userdata/Database/Textures13.db /storage/.kodi/userdata/Database/Textures13.db.BAK
cp /storage/.kodi/userdata/Database/ViewModes6.db /storage/.kodi/userdata/Database/ViewModes6.db.BAK
cp /storage/.kodi/userdata/sources.xml /storage/.kodi/userdata/sources.xml.BAK
(your files may be different, make sure you back them all up)
STEP 9. Copy your updated files back to the Kodi machine:
After checking the Kodi isn't actually busy reindexing or otherwise working with its database go back to you local machine then go ahead and copy those updated files back to Kodi.
In my case, these copy commands were:
Code:
scp MyVideos90.db [email protected]:/storage/.kodi/userdata/Database/MyVideos90.db
Quote:MyVideos90.db 100% 17MB 16.5MB/s 00:01
Code:
scp Textures13.db [email protected]:/storage/.kodi/userdata/Database/Textures13.db
Quote:Textures13.db 100% 6560KB 6.4MB/s 00:01
Code:
scp ViewModes6.db [email protected]:/storage/.kodi/userdata/Database/ViewModes6.db
Quote:ViewModes6.db 100% 20KB 20.0KB/s 00:00
Don't forget we still have to edit
sources.xml:
Code:
nano /storage/.kodi/userdata/sources.xml
Change all occurrences of the old IP into the new IP (or DNS name). In my case there were 3 occurrences that had to be edited. Then save (
Ctrl-O) and exit (
Ctrl-X) when done.
Last step, reboot Kodi:
And you're done!
For me, this worked, and after the last reboot Kodi could find everything where it was supposed to be.
Hope it works for you too!
P.S. This entire process could totally be scripted, maybe someone adventurous wants to give that a try? Actually, it should really be built into Kodi...
G.