[Solved] Migrating to new server - various problems

11 posts / 0 new
Last post
#1 Wed, 12/27/2017 - 05:19
michaldybczak

[Solved] Migrating to new server - various problems

I found this instruction:

https://www.virtualmin.com/documentation/system/migrate

It's simple and quick way to migrate sites to another server and I done it, however, the results are far from being perfect. I followed it to the letter and yet I encounter issues.

I was transfering 2 sites (2 virtual servers) and 1 subdomain (one sub-virtual server)

On the first glance:

  • in preview sites cannot connect to a mysql database (why? it should create the same databases, users, passwords, the same config files)
  • when I try to use phpmyadmin panel I get ERR_SSL_PROTOCOL_ERROR, so there is a issue with ssl, etc.

Here are the highlights of the process:

  • backups were done successfully
  • backups were sent to another server successfully
  • restoring was mostly successful but had few errors concerning ssl and AWstats, (I'll try to make the errors bold if I can):
virtualmin restore-domain --source /root/backups/virtualmin.tar.gz --all-virtualmin
Checking for missing features ..
.. all features in backup are supported
Checking for errors in backup ..
.. no errors found
Starting restore..
Extracting backup archive file ..
.. done
Restoring Virtualmin settings ..
    Restoring Virtualmin configuration ..
    .. done
    Restoring templates and plans ..
    .. done
    Restoring email templates ..
    .. done
    Restoring custom fields, links, categories and shells ..
    .. done
    Restoring custom script installers ..
    .. done
    Restoring scheduled backups and keys ..
    .. done
   Restoring DKIM settings ..
    .. not installed
    Restoring greylisting settings ..
    .. not supported on source system
    Restoring rate limiting settings ..
    .. not configured on this system
    Restoring mail server configuration ..
    .. done
.. done
Restore completed successfully.
virtualmin restore-domain --source /root/backups/ --all-domains --all-features
Checking for missing features ..
.. all features in backup are supported

Checking for errors in backup ..
.. no errors found
Starting restore..
Extracting backup archive files ..
.. done
Re-creating virtual server site1.pl ..
    Creating administration group site1..
    .. done
    Creating administration user site1 ..
    .. done
    Creating aliases for administration user ..
    .. done
    Adding administration user to groups ..
    .. done
    Creating home directory ..
    .. done
    Creating mailbox for administration user ..
    .. done
    Adding new virtual website ..
    .. done
    Adding webserver user www-data to server's group ..
    .. done
    Performing other Apache configuration ..
    .. done
    Setting up scheduled Webalizer reporting ..
    .. done
    Creating SSL certificate and private key ..
    .. done

   ** Adding new SSL virtual website ..
    .. certificate authority file is not valid : Data does not start with line -----BEGIN CERTIFICATE-----*

    Setting up log file rotation ..
    .. done
    Creating MySQL login ..
    .. done
    Creating MySQL database site1 ..
    .. done
    Setting up AWstats reporting ..
    .. done

**Use of uninitialized value in string eq at /usr/share/webmin/virtualmin-awstats/virtual_feature.pl line 222.**

    Setting up password protection for AWstats ..
    .. done
    Creating Webmin user ..
    .. done
    Applying web server configuration ..
    .. done
    Re-loading Webmin ..
    .. done
    Saving server details ..
    .. done
Restoring backup for virtual server site1.pl ..
    Restoring virtual server password, quota and other details ..
    .. done
    Updating administration password and quotas ..
    .. done
    Restoring Cron jobs ..
    .. done
    Extracting TAR file of home directory ..
    .. done
    Setting ownership of home directory ..
    .. done
    Restoring Apache virtual host configuration ..
    .. done
    Checking restored PHP execution mode ..
    .. mode FCGId OK for this system
    Updating home directory in PHP configuration ..
    .. done
    Restoring Apache log files ..
    .. done
    Restoring Webalizer configuration files and Cron job ..
    .. done
    Restoring Logrotate configuration ..
    .. done
    Restoring allowed MySQL hosts ..
    .. done
    Re-loading MySQL database site1 ..
    .. done
    Restoring Webmin ACL files ..
    .. done
    Restoring AWstats configuration file ..
    .. done
    Updating Webmin user ..
    .. done

Re-creating virtual server site2.pl ..
    Creating administration group site2 ..
    .. done
    Creating administration user site2 ..
    .. done
    Creating aliases for administration user ..
    .. done
    Adding administration user to groups ..
    .. done
    Creating home directory ..
    .. done
    Creating mailbox for administration user ..
    .. done
    Adding new virtual website ..
    .. done
    Adding webserver user www-data to server's group ..
    .. done
    Performing other Apache configuration ..
    .. done
    Setting up scheduled Webalizer reporting ..
    .. done
    Setting up log file rotation ..
    .. done
    Creating MySQL login ..
    .. done
    Creating MySQL database site2 ..
    .. done
    Setting up AWstats reporting ..
    .. done

**Use of uninitialized value in string eq at /usr/share/webmin/virtualmin-awstats/virtual_feature.pl line 222.**

    Setting up password protection for AWstats ..
    .. done

    Creating Webmin user ..
    .. done
    Applying web server configuration ..
    .. done
    Re-loading Webmin ..
    .. done
    Saving server details ..
    .. done
Restoring backup for virtual server site2.pl ..
    Restoring virtual server password, quota and other details ..
    .. done
    Updating administration password and quotas ..
    .. done
    Restoring Cron jobs ..
    .. done
    Extracting TAR file of home directory ..
    .. done
    Setting ownership of home directory ..
    .. done
    Restoring Apache virtual host configuration ..
    .. done
    Checking restored PHP execution mode ..
    .. mode FCGId OK for this system
    Updating home directory in PHP configuration ..
    .. done
    Restoring Apache log files ..
    .. done
    Restoring Webalizer configuration files and Cron job ..
    .. done
    Restoring Logrotate configuration ..
    .. done
    Restoring allowed MySQL hosts ..
    .. done
    Re-loading MySQL database site2 ..
    .. done
    Restoring Webmin ACL files ..
    .. done
    Restoring AWstats configuration file ..
    .. done
    Updating Webmin user ..
    .. done
Re-creating virtual server test.site1.pl ..
    Creating home directory ..
    .. done
    Adding new virtual website ..
    .. done

    **Performing other Apache configuration ..
    .. configuration failed : Failed to copy /etc/php/7.0/cgi/php.ini to /home/site1/domains/test.site1.pl/etc/php7.0/php.ini : cp: cannot create regular file '/home/site1/domains/test.site1.pl/etc/php7.0/php.ini': No such file or directory**


    **Creating SSL certificate and private key ..
    .. SSL website failed! : Failed to open /home/site1/domains/test.site1.pl/ssl.cert.webmintmp.1393 : No such file or directory at ../web-lib-funcs.pl line 1433, <readout77> line 1.**

    Setting up log file rotation ..
    .. done
    Applying web server configuration ..
    .. done
    Re-loading Webmin ..
    .. done
    Saving server details ..
    .. done
    Updating Webmin user ..
    .. done
    Re-loading Webmin ..
    .. done
Restoring backup for virtual server test.site1.pl ..
    Restoring virtual server password, quota and other details ..
    .. done
    Extracting TAR file of home directory ..
    .. done
    Setting ownership of home directory ..
    .. done
    Restoring Apache virtual host configuration ..
    .. done
    Checking restored PHP execution mode ..
    .. mode FCGId OK for this system
    Updating home directory in PHP configuration ..
    .. done
    Restoring Apache log files ..
    .. done
    Restoring Logrotate configuration ..
    .. done
    Updating Webmin user ..
    .. done
Enabling PHP modules for restored scripts ..
.. the following PHP modules were installed : mcrypt gd curl
Applying web server configuration ..
.. done
Re-loading Webmin ..
.. done
Restore completed successfully.
Wed, 12/27/2017 - 07:07
michaldybczak

UPDATE

I noticed that several settings where completely not transferred correctly, despite the output. For example, ssl wasn't enabled on restored servers, wrong certs were pointed to, quotas were default instead used from the first server and many others. Despite fixing those settings, issues persist.

So I checked validate servers option and I got that there is no databases for each domains (or subdomains) which is not true... So I checked to edit those databases and got:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

That's crazy and very concerning. So far automatic migration is a big failure. It suppose to be the easiest, quickest and the LEAST PROBLEMATIC way of migrating sites but it turned out to be complete crap. So it would see that the whole webmin/virtualmin backup options were also crap and none functioning properly.

The sites were transferred from ubuntu 16.04 server into vanilla ubuntu 16.04 server with freshly installed virtualmin/webmin so it all should go smoothly.

Is there a way to submit that as a bug or loads of bugs?

I tried to log in as root to mysql:

mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

So I checked sockets: find / -type s

and I can't see any mysql.sock which worries me even more. So I did:

service mysql start Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

So I checked:

systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since śro 2017-12-27 14:20:10 CET; 15s ago
  Process: 10491 ExecStart=/usr/sbin/mysqld (code=exited, status=2)
  Process: 10481 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 10491 (code=exited, status=2);         : 10492 (mysql-systemd-s)
    Tasks: 2
   Memory: 12.3M
      CPU: 573ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─10492 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─10556 sleep 1

Starting MySQL Community Server...
gru 27 14:20:10 site1.pl systemd[1]: mysql.service: Main process exited, code=exited, status=2/
journalctl -xe
AVC apparmor="DENIED" operation="open" profile="/usr/sbi
gru 27 14:22:43 stolmet-zywiec.pl audit[11226]: AVC apparmor="DENIED" operation="open" profile="/usr/sbi
gru 27 14:22:43 stolmet-zywiec.pl kernel: audit: type=1400 audit(1514380963.033:200): apparmor="DENIED"
gru 27 14:22:43 stolmet-zywiec.pl kernel: audit: type=1400 audit(1514380963.033:201): apparmor="DENIED"
gru 27 14:22:43 stolmet-zywiec.pl kernel: audit: type=1400 audit(1514380963.033:202): apparmor="DENIED"
gru 27 14:22:43 stolmet-zywiec.pl systemd[1]: mysql.service: Main process exited, code=exited, status=2/
gru 27 14:23:13 stolmet-zywiec.pl systemd[1]: Failed to start MySQL Community Server.
-- Subject: unit mysql.service się hasn't succeeded
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service się hasn't succeeded
--
-- Result: failed.

I'm not an advanced server user and rising difficulties start to add up. Do I see it correctly that apparmor blocked mysql? Why? What virtualimin did to trigger it? Shouldn't it be compatible with ubuntu server and thus handle such things automatically during restoring backups?

Last time I had a problem with connection to mysql as root, I had to reinstall the whole serwer since mysql cannot be re-installed with virtualmin - too many dependencies I mean, I was able to uninstall mysql but wasn't able to install because of virtualmin conflicts.

It turned out that also apache crashed but I was able to restore it when I removed virtual servers. Unfortunately mysql isn't staring and most probably I will have to reinstall the whole system again... and move sites manually :(.

Wed, 12/27/2017 - 09:49
7stars

did you create a detailed issue about it? It seems not... better to explain step by step by issue, starting from your exact OS config etc.

bye

Wed, 12/27/2017 - 15:20
michaldybczak

Not sure what are you talking about. I'm new on that forum. What a detailed issue? I gave lot of details above, I may give more if needed but the thing is: there are so many of them that I don't know what is relevant so sorry if I didn't provide what you think of.

Tomorrow I will be reinstalling the system anyway and putting fresh virtualmin - again. This time I won't use aromatic backup/restore because it always damages mysql irreparably on the second server. I have no idea why, there are no mysql errors during backup/restore. But the issue is not only with mysql and many things are not identical with the old server so it seems the backup/restore tool is not reliable and just doesn't work.

Wed, 12/27/2017 - 21:56
tpnsolutions
tpnsolutions's picture

Hi,

Are both the origin and destination server setup identically?

I have found in the past, if you have different settings on each server, the migration may fail or have differences as a result of.

Best Regards,
Peter Knowles | TPN Solutions
Email: pknowles@tpnsolutions.com | Skype: tpnassist
Thu, 12/28/2017 - 03:23
michaldybczak

As far I know they are similar. I can't tell they're identical, because on previous server system is set by provider, on second server system is installed by me (from Ubuntu 16.04 server iso) so there can be some package differences and some small setting differences. However, if backup/restore utility requires to have system really identical in every way with every small setting - this is ridiculous, it won't work most of the time. So once again what "identical" means in that context. Which settings must be identical? If such requirement is there, there must be some guidelines for it or scripts checking it. And yet, nothing like that exists so it seems, backup/restore utility is massively flawed and works only some small cases with idealized conditions and no one knows them for sure.

Before scratching the system, I have some idea to play with. Servers have different root passwords, which is normal and sane thing to have. However, mysql root is set by virtualmin to be default with root and password is encrypted within mysql db so there is no changing it manually. Maybe, MAYBE, virtualmin replaces that database and since setting "password the same as root" stays the same and it doesn't check password compatibility between tables (a big flaw in vurtualmin utility). My second guess is, myqsl unlike other processes needs this root password to launch it's process and the password must be provided by systemd. When this password doesn't match, launching mysql fails. That would make sense from security point of view (hackers process could impersonate systemd but without password it cannot access mysql and exploit it).

The fact that mysql works after restore and breaks after first reboot can suggest that I might be right or some similar protection is set. Maybe apparmor is checking that password after all?

I am just fishing... so I will play with root passwords and see if it helps. If it doesn't pan out, I'm out of ideas and my only option is to reinstall the system.

Thu, 12/28/2017 - 04:09
tpnsolutions
tpnsolutions's picture

Hi,

I noticed there were errors during the restore process as noted in your original post. Those errors may point to the cause of some problems you are experiencing.

Best Regards,
Peter Knowles | TPN Solutions
Email: pknowles@tpnsolutions.com | Skype: tpnassist
Thu, 12/28/2017 - 04:34
michaldybczak

OK, here are the errors:

  1. ** Adding new SSL virtual website .. .. certificate authority file is not valid : Data does not start with line -----BEGIN CERTIFICATE-----**

Really? This is automated tool, why is it doing it wrong? I don't see any fault from my side. ssl works on first server, it should work on second one but it doesn't because it fails in too many areas.

It does copy cert files correctly, so what is the problem with that error?

It doesn't set virtual servers as ssl websites (although that's the setting on original server). This is weird because I thought it just copies appache2 confs, so I am confused here, does the conf include ssl and other configs are forgotten or does it mess with apache2 confs (which it shouldn't) so they are not identical? Also, cert files seems to be copied to new server. Manually enabling ssl to a virtual server on a new server doesn't helps, ssl still produce issues.

  1. Use of uninitialized value in string eq at /usr/share/webmin/virtualmin-awstats/virtual_feature.pl line 222.

I have no idea what it is about but AWstats works well after the restore and all past data are there.

  1. Performing other Apache configuration .. .. configuration failed : Failed to copy /etc/php/7.0/cgi/php.ini to /home/site1/domains/test.site1.pl/etc/php7.0/php.ini : cp: cannot create regular file '/home/site1/domains/test.site1.pl/etc/php7.0/php.ini': No such file or directory

Why? This is nothing unusual, in fact having php is very basic thing on each website server. And why does it try to copy it from etc instead just restoring the ones that were originally there? Or maybe it did but it wanted to override with etc files and failed hence the error? And after checking those files are there so this is puzzling and probably has no negative effect since those are standard files and they are where they suppose to be.

  1. Creating SSL certificate and private key .. .. SSL website failed! : Failed to open /home/site1/domains/test.site1.pl/ssl.cert.webmintmp.1393 : No such file or directory at ../web-lib-funcs.pl line 1433, line 1.

No idea what it is about but this is a test subdomain, it may not work so this doesn't matter really. I never checked it, because it needs refreshing anyway from the original.

That was it and yet problems are mainly with mysql. Weirdly, when I deleted virtual servers, it didn't fix mysql... yesterday. I went to sleep, check out server today and mysql seems to be working... But I can't log in to server with ssh, because users are not there and root somehow has problem with key, it asks for passphrase then asks for password which I give and it doesn't accept it so I am lost. Does restore changed root pass to for the one from the first server? I try this, nothing. Maybe it changed to the virtualmin original root password on the first server before I changed root password? But at this time I was blocked, probably by fail2ban and somehow I can't restore the connection. This is what happens when there are too many layers and I have no idea what is happening really, which ones are affected by virtualmin and which are not.

This is so time consuming, I am losing my patience. I would have reinstall system quicker.

Thu, 12/28/2017 - 09:20
Neo X

Hmm. May be create an issue here to let developers know: https://www.virtualmin.com/project/issues

This time go for manually moving files to new hosting. Backup databases and files, move them, move SSL certificate and point your domain to that server IP.

Thu, 12/28/2017 - 10:16
michaldybczak

Since mysql was working I was tempted to install virtual servers and move site manually without reinstalling whole system.

I noticed, that when deleting virtual servers, virtualmin failed to remove mysql databases and users associated with virtual server users... So I deleted them manually.

From there I created first virtual server, moved cert and needed files, fresh wordpress site works, all looks ok, ssl works now. However, it couldn't be so easy... Some new, unexpected problem showed up. I cannot successfully import database... because some tablespace exists... So I went to mysql directory of this table and found culprits - 2 files that were abandoned even when table suppose to be empty. I deleted those files and... still not out of the woods yet.

I get:

"SQL query:
-- --------------------------------------------------------

--
-- Table structure for table `wp_domain_mapping`
--

CREATE TABLE `wp_domain_mapping` (
  `id` bigint(20) NOT NULL,
  `blog_id` bigint(20) NOT NULL,
  `domain` varchar(255) NOT NULL,
  `active` tinyint(4) DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1

MySQL said:
#1030 - Got error 168 from storage engine

I don't get it. I do import on empty table. Directory of that database shows correctly only db.opt file. Now instead the tablespace exists, error changed into something else but with the same table.

UPDATE: Those deleted files come back... Sometimes I delete tables and they are gone and sometimes they stay. I get even info that the wp_domain_mapping already exists when previously there is nothing (no files in database directory). The weirdest thing is, THIS TABLE DOESN'T EXISTS in imported database. So why is it showing out of the thin air and blocking query? This is madness :(.

Thu, 12/28/2017 - 17:26
michaldybczak

Thanks to help on #mysql irc channel I was able to resolve my problems.

Because deleting virtual servers left mess inside mysql and because I deleted manually database directories (couldn't do that by normal, proper means), I had to refresh the whole installation (clean all databases and initialize mysql anew, then renew mysql root connection) which fixed the issue. This was quite a hassle and I wouldn't done it by myself.

  1. Renewing mysql
  • stop mysql
  • potentially do database dump (backup) if you want to restore some databases later
  • delete all directories and files from /var/lib/mysql/
  • issue a command as root: mysqld --initialize --user=mysql

This restores basic files and basic databases, but not webiste database.

  1. Restoring root connection (Ubuntu 16.04)
  • stop the mysql server.
  • edit /etc/mysql/mysql.conf.d/mysqld.cnf, add "skip-grant-tables" under [mysqld]
  • start mysqld
  • connect with commands: "mysql -u root" and do mysql command "FLUSH PRIVILEGES;"
  • if 5.7+, do mysql command: "ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPassword';"
  • If 5.6 or earlier, do: "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newPassword');"
  • remove the added line from /etc/mysql/mysql.conf.d/mysqld.cnf
  • restart mysqld.
  1. Create website database and user for it, check in virtualmin if database is assigned to proper virtual server and if all credentials are correct
  2. Import database for website (this time without error).

After all that, mysql works normally, I could import database and in general move site to that server. Everything works perfectly now as far I can tell.

Topic locked