Migrating an old Linode on Ubuntu 11.08 to Ubuntu 18.04
So I had a server on Linode that I had not updated for a while, and it was running Ubuntu 11.04 — which was so old that it was no longer easy for me to just update the OS from that server. Essentially, all the tools to upgrade that OS were so out of date that I couldn’t even download those files. So what I tried to do instead was create a new server and migrate things over there. This turned out to be trickier than I thought, and I really couldn’t find a guide for it, and had to put together a number of different things.
What I ended up doing essentially was:
- Creating a new Linode with the Ubuntu 18.04 distribution that I wanted
- Reinstalling a number of key packages
- Copying data from the filesystem to the new server
- Backing up and reimporting the database
- Updating many of the apache configurations
- Doing an IP swap within the same region
- Fixing a lot of issues that came up along the way as it didn’t “just work”
So one of the first recommendations that I received was to use scp to copy over data. I tried this, and it seemed like it worked, but it didn’t work and I don’t recommend this. This was the command to copy the home directory from my old server to my new server, as well as the www directory.
# OLD SERVER
root@myserver:/home# scp -r . firstname.lastname@example.org:/home
root@myserver:/var$ scp -r www email@example.com:/var
I installed a number of key packages.
# NEW SERVER
sudo apt update && sudo apt upgrade
sudo apt install apache2
root@localhost:~# sudo apt install python
I copied over sites-available for my apache configurations
root@myserver:/etc/apache2/sites-available$ scp * firstname.lastname@example.org:/etc/apache2/sites-available
This mostly worked — I had an old apache config that looked for any filenames, but the new config restricted it to files ending in .conf — while I could have changed that setting I instead just renamed some of the files.
root@localhost:/etc/apache2/sites-available# mv jeremykeeshin.com jeremykeeshin.com.conf
root@localhost:/etc/apache2/sites-available# sudo a2ensite jeremykeeshin.com.conf
Enabling site jeremykeeshin.com.
To activate the new configuration, you need to run:
systemctl reload apache2
root@localhost:/etc/apache2/sites-available# systemctl reload apache2
I needed php since I had a lot of wordpress sites.
sudo apt install php libapache2-mod-php php-mysql
I ran into a LOT of issues around my mysql install. I think part of it was a permissions issue since I was importing a new mysql table.
I had to create a new user account using
The issue with the files I ran into with scp was that I was copying thousands of files and there was no easy way to tell it just worked. There is a different command, rsync — which seems to handle this better and also works if you run repeatedly, which actually caught a number of places where I had permissions issues and things were broken. So the commands that worked better for me looked like this:
root@oldserver:/var/www$ sudo rsync -av . root@newserver:/var/www/
This reference was helpful for parts of it (but not all of it) https://linode.com/docs/platform/migrate-to-linode/migrate-a-lamp-website-to-linode/
This helps you export the database (they also recommend rsync).
# OLD SERVER
sudo mysqldump --all-databases --single-transaction --quick --lock-tables=false > full-backup-$(date +%F).sql -u root -p
Restore the backup on the new server
# NEW SERVER
sudo mysql -u root < full-backup-*.sql
You’ll need to flush privileges, and this didn’t work for me. In some cases mysql just stopped responding, I think after installing php, so I actually removed and re-installed mysql before getting it to work.
Here were the directions I found to swap IPs
Written by Linode The Remote Access section of the Linode Manager contains important network settings for your Linode…www.linode.com
- Log in to the Linode Manager.
- Click the Linodes tab.
- Select a Linode. The Linode’s dashboard appears.
- Click the Remote Access tab.
- Select the IP Swap link. The webpage shown below appears.
- Select both of the Move It checkboxes to verify that you want the IP addresses switched.
- Click Do it.
- Optional Enable Network Helper and reboot your Linode.
I forgot to reboot the linode on one of the times. So it seems like that should be good enough but that really didn’t “just work” for me, and many of my sites didn’t work, or ran into 500 errors, or something else. I was also in the process of trying to update them to HTTPS, so did that as well. I had to fix a number of permissions issues.
For wordpress and apache, having the right owners of the file was an issue I saw and had to resolve:
sudo chown -R www-data:www-data /var/www
Also there were cases where things weren’t writable in the correct way
sudo chmod -R 775 …/wp-content
So those were some of the key steps that helped me migrate most of my websites over, and many of them are working.