It was a particularly sunny day, both in the real world and in the world of IT. There was no cause for alarm, no foreshadowing of pending doom. Yet, it happened. For reasons that I will not get into, there is a way (perhaps by overzealous children playing in the bathtub, or not properly sealed plumbing air vents, or something along that line – not trying to place any blame) that a huge torrential downpour of water will come through the sheetrock in the ceiling of the room housing my server, and there is a way that all of that water can get dumped right into the server itself, since it is on the top shelf and closest to the water. Either way, servers don’t run that well when they are full of water, and a Dell PowerEdge 1950 just isn’t waterproof.

After drying it out, I was able to get it to boot again. It sometimes would work, sometime not. At times it would run like a champ, and others it would give up and quit. The only consistent thing was the internal fan speeds were now set to maximum, because the speed sensor didn’t work for them anymore. So, it was time to get a new server.

A very good and generous buddy of mine donated a Dell PowerEdge R520 to me, completely free of charge, with dual Xeon 2.4GHz processors, 32GB of RAM, and over 4TB of disk storage. It was a gold mine indeed! He felt it was old, but compared to the PowerEdge 1950 I was running, this was a real powerhouse and a great gift!

Now I just had to put it to work.

First order of business was moving my Nextcloud instance from the old server to the new. That shouldn’t be too hard, since Nextcloud made a straightforward six step write-up on how to do just that. Unfortunately, it didn’t work when I tried it.

So, per step 1, I installed my preferred OS, in this case Ubuntu 20.04 onto the R520, and proceeded to follow my own write-up for installing LAMP, and followed the new install guide for Nextcloud to make sure I properly installed PHP and setup the MariaDB. Set up Apache2 web server with all my Let’s encrypt certs, etc. All seemed to be going well here.

Step 2 was to activate maintenance mode on your old Nextcloud instance, so on the 1950, I edited the nextcloud/config/config.php file and changed the line with ‘maintenance‘ from false to true. Again, everything seemed to be going well here.

Step 3 and 4 instructed me to make a backup of the data and database and copy it to the new machine. Fortunately, they were a little more specific with the instructions under the “backup” section. But essentially, I used rsync to transfer the files from the 1950 to the R520. And then I made a backup of the MariaDB per the instructions. More on that in a minute, as this was where, unbeknownst to me, the problem started. It shows and example, like this:

mysqldump --single-transaction -h [server] -u [username] -p[password] [db_name] > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak

I named it much simpler, no need for the date here. The later half of the fourth step was to restore the MariaDB, which I did, like the instructions say:

mysql -h [server] -u [username] -p[password] [db_name] < nextcloud-sqlbkp.bak

This did indeed restore the database from MariaDB on the other machine. I even checked, my database was there. Everything seemed fine.

From here, steps 5 is to test it, and steps 6 is to change your dns record to point to the new server. But I failed at step 5. I couldn’t get the Nextcloud to work. In fact, the only thing I saw was an error like this:

“Internal Server Error
The server was unable to complete your request.
If this happens again, please send the technical details below to the server administrator.
More details can be found in the server log.”

But there were no technical details. I tried to check the Nextcloud log, but it wasn’t showing any current information. The site was so down, it wouldn’t work enough to even log anything, I guess. So, I started shooting in the dark. What was the problem? How could I deduce the issue without logs? Well, I did some web searching and every instance of this seemed to be sql related.

So, I gave up for a while. Then, while doing something else, it hit me, like an epiphany. I restored the database, but not the users of the database! DUH! I jumped online to do a little research, and came across a great article on how to do just that, at This helped me do a full backup of the database data (not just Nextcloud) like so:

mysqldump -A -u root -p > backup.sql

     And restore it on the other machine like this:

mysql -u root -p < backup.sql

Then I found this great write-up from on how to migrate the users from one to another, like so:

# mysql -B -N -uroot -p -e "SELECT CONCAT('\'', user,'\'@\'', host, '\'') FROM user WHERE user != 'debian-sys-maint' AND user != 'root' AND user != ''" mysql > mysql_all_users.txt
# while read line; do mysql -B -N -uroot -p<put_password_here> -e "SHOW GRANTS FOR $line"; done < mysql_all_users.txt > mysql_all_users_sql.sql
# sed -i 's/$/;/' mysql_all_users_sql.sql

Now I had the file with all users and their permissions! I copied that over to the R520 and imported it with this simple line:

mysql -u root -p < mysql_all_users_sql.sql

And, praise God, after all that, my Nextcloud started working! I was really starting to get worried that I’d have to start over from scratch!

So, if you plan to migrate your Nextcloud from one server to another, keep in mind that the instructions tell you how to back up the data from your MariaDB/SQL database, but they don’t mention that you need your user information as well. Or that you will need to add said users after the fact. You all probably knew that already, but for a new to Nextcloud guy like me, this step was really important!

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *