move domain alias

Hey there,

I am doing a cPanel migration to another server and it had everything as subdomains under the main domain. So I wanted to move them out as parent servers. In order to do that I had to convert them to sub-servers and then to parent servers.

When converting to parent servers I got an error:

For ****.com : Moving home directory ..
.. move failed : mv: cannot move '/home/****/domains/****.com' to '/home/****/domains/****.com': No such file or directory

It only gives an error when I enter a different username and password when converting to parent.

Check this thread for more info:

https://www.virtualmin.com/node/12563#comment-54507

Thanks!

Ryan

Status: 
Active

Comments

So does the first directory in that error message really not exist?

The first directory exists. /home/user1/domains/****.com

The second directory does not. /home/user2/domains/****.com

[root@server home]# mv /home/user1/domains/****.com /home/user2/domains/****.com
mv: cannot move '/home/user1/domains/****.com' to '/home/user2/domains/****.com': No such file or directory

Could the problem be that there is no domains folder inside the /home/user2 folder?

Ah .. that would explain it. Does creating a domains folder fix this?

Ok, I see a Virtualmin bug that can cause that domains folder to be not created when moving a virtual server with alias domains. I'll fix this in the next release.

Make sure that domains folder is owned by the domain's user and group, not root.

Does creating a domains folder fix this? Well I don't think so. I don't know how it could since its during the conversion to a parent and the folder is left where it was instead of being moved.

Make sure that domains folder is owned by the domain's user and group, not root. The /home/user1/domains folder is owned by user1. I suspect if you create a domains folder it does have to be chown to user2.

There also seems to be another folder left inside the /home/user1/public_html folder which contains a Maildir folder. So having the Maildir inside the public_html folder doesn't seem right to me either. Something doesn't seem quite right maybe from the migration process in the first place.

They have just said to me that they plan to gather the money to upgrade to the unlimited Pro license in the next few days so I don't know if this is a bug in both GPL and Pro but it sounds like I will be testing it in both.

Is there some way to see all the commands that its doing so I can try to turn it into a loop in some sort of script somehow? I don't really want to have to manually do this entire process to all 511 of them of converting them to parent servers and doing all these fixes and whatnot. It will take ages and this has to be up and working by the 13th.

If you like, I could email you a fix that will create the domains folder properly during the move process?

I would like that very much. That would be awesome =) Thank you!

Thank you Jamie! A whole package and all =) I went and installed it as a webmin module and it said it went ok. It seems like the files are on the server because I used WinMerge to compare the directories and I can see that no files are different from the package and whats on the server, and that some of them are different than an original Virtualmin GPL installs files. However when I go in and convert the next server on the list from sub-domain to sub-server to parent server it still has the same error. Therefore maybe what you changed is something during the migration process and then maybe what I would have to actually do is re-import the migration from the beginning again and maybe thats when it will create the domains folder to begin with. If that is the case it should be ok if it works. Once the 13th comes along I am going to have to create a new cPanel backup and transfer it across and migrate it for the last time. Hopefully at that point it goes smoothly. I will test again tonight and let you know if it doesn't work =)

Now, how do I remove 511 Virtual servers in one go so I can get on with it? I hope I don't have to delete each one individually.

Edit: Ok, nevermind, after I deleted the first few that I had converted to parent, and then deleted the main one, all other ones went with it =)

So you are still seeing the same error? That's odd, this update should have fixed it.

I presume that this sub-server you are converting has its own alias or sub-domains?

Yes I am persently experiencing the same error but I did not re-import anything yet. It's actually still deleting them at this point. I think it might be almost done though.

Well maybe I have to provide more info. This server was on a really crappy host that I dislike very very much due to more than this servers poor experiences. This particular clients server has been on this host when it was small and hosted on a VPS but currently is on a dedicated server which we are moving it off of. It was hacked by hackers with an irc botnet thing by the looks of it but that may have been on the old VPS. It was also taken down by some other thing at one point. Then now it just mysteriously deleted all files on the server. Now this new server we are moving it to is just ridiculously powerful, at least I think so, and hosted on a different host that we know is reliable already from past experiences.

So that being said, it is possible that through its travels it has accumulated some poor configuration. It seems to create a subdomain and redirects the domain towards it in cpanel. In Virtualmin once migrated it has the main domain with all other domains as sub-domains. There are aliases of them all. Most have one which is the domain itself and not the subdomain of the main domain if that makes any sense. Maybe some are broken due to the crash or something.

Also I should mention what I have learned about cPanel. I have a PHP script that I developed which actually clones a Joomla install out of a snapshot of one and it can build a ton of Joomla sites out of one snapshot by uploading a CSV of the information to inject into the site. I plan to integrate this somehow into Virtualmin in order to deal with these sites it has created on cPanel. These sites include only a particular division of their stuff. The reason I mention these particular sites is because they are all copies created automatically using the script I wrote for it using cPanel through its URLs and I have to convert that to use Virtualmin instead to do it. However what I have learned while creating domains through cPanel (at least this install of it) are that the alias redirects is just the way cPanel seems to have worked... each domain has to have a redirect added to cPanel in order to work properly or it won't connect to the site. It isn't my choice to have a subdomain and domain alias for each one but thats just what cPanel seems to do and so now it has created the redirects for all these domains in the main cPanel users public_html. These folders seem to be staying there but maybe they are related to the mv failing. I will be able to tell after this next import test.

Also there are over 100 of these automatically created sites and each one is just a copy of a Joomla install but in order to get it to actually show up in cPanel I have to create domains, and redirects, along with emails and forwards and run queries on the DB and update the config files and all that fun stuff. These particular sites could all be under one user but they don't have to be as long as Virtualmin can create domains, domain redirects/aliases, users, ftp, email accounts and forwards through the API which seems like thats exactly what it does. However there are many other sites on the server that are unrelated and should have different users and so I have setup suexec. Therefore this is also why I must be able to have the option to copy in the /etc/skel folder and substitute the variable somehow. The variable I am substituting is the path to the tmp folder in the php/php.ini. But how do I do all this? I have no idea, yet... hehe

Now I just noticed something in the virtualmin command line api. When I try the following commands it looks like its saying its possible to delete all domains because it outputs some help and there are *s at the end of the line like they could go there as part of the command but it doesn't work when I actually type the command. All I get is a help output again.

virtualmin delete-domain * or virtualmin delete-domain --domain *

Since I am typing commands this is the command I use to migrate the backup file if it matters at all.

virtualmin migrate-domain --source /home/backup-12.2.2009_11-00-22_****.tar.gz --type cpanel --user user1 --pass pass1

Ok, ok, I guess this is a long enough post hopefully it will have some info that helps somehow =)

If you want to delete and re-import a domain, the simplest way is to add the --delete-existing flag to the migrate-domain command. Or you could delete all domains with a command like :

for dom in \`virtualmin list-domains --name-only --toplevel\`; do
  virtualmin delete-domain --domain $dom
done

Be careful with that though!

As for the original problem with the missing domains directory, is it still missing even after you install the update I sent and re-try a sub-server conversion?

Ok thanks for the info, that will make it easier to test =)

I re-imported the migration file overnight and I just tested. Converting from the initial sub-domain to sub-server theres no errors there. It is only when I convert from sub-server to parent server and it seems the error still exists here when its trying to move out the domain alias.

I have something that looks like this in Virtualmin:

maindomain.com
   |_mainalias.com (Alias of maindomain.com)
   |_mainalias2.com (Alias of maindomain.com)
   |_mainalias3.com (Alias of maindomain.com)
   |_mainalias4.com (Alias of maindomain.com)
|_subdomain.maindomain.com (sub-domain of maindomain.com)
   |_seconddomain.com (Alias of subdomain.maindomain.com)

And then there are hundreds of those subdomain servers on there each with their own alias domain pointing at the sub domain. I can see how this might be useful to see the site without the domain but I don't really need that in every single case, if any. If I do I can just create it like that. I don't see why cPanel has to do it this way but thats how it did it. I don't know if theres an option to turn that on and off or what the deal is but it seems that it creates the subdomain and alias domain for that automatically when adding a new addon domain.

In cPanel I just created a new test domain, and immediately after that I can access it at domain.maindomain.com and if the domain was actually pointing at the server I would be able to also access it at domain.com.

That is fine to have the domains as aliases of the subdomains in cPanel but in Virtualmin it is probably not a good thing because it also is putting the Maildir in these servers folders which are located in the public_html folder.

Another thing to note is that cPanel has been upgraded a great deal over the years this server has been in operation and things may have changed some but it still seems to be doing basically the same thing.

Another thing is that when there are redirects for a domain it will sometimes use the /home/username/public_html/domain.com folder to store a .htacess file with the redirect in it but in some cases for some strange reason it puts the redirect code in a universal /home/username/.htacess with a bunch of others. Strange considering there is a folder and blank .htaccess file for the domains that use that universal one and some of them are just using their own .htaccess file in their own folders which were created inside the main domains public_html folder when the domain was added.

Here is the info on their current cPanel:

cPanel Version 11.24.5-RELEASE
cPanel Build 37453
Theme x3_
Apache version 1.3.37 (Unix)
PHP version 5.0.5
MySQL version 5.0.81-community-log
Architecture i686
Operating system Linux
Kernel version 2.6.9-55.0.2.ELsmp
cPanel Pro 1.0 (RC1)

Output when converting from the initial migrated cPanel sub-domain to sub-server:

Converting domain.maindomain.com to sub-server .. Updating document directory in website configuration .. .. done

Saving server details .. .. done

Updating Webmin user .. .. done

Applying web server configuration .. .. not running!

Re-loading Webmin .. .. done

.. done

Apache doesn't start because its missing the fcgi files and whatnot still.

Here are the locations of the files: [root@server domains]# pwd /home/username/domains

[root@server domains]# ls -aR domain.com domain.com: . .. homes logs

domain.com/homes: . ..

domain.com/logs: . .. .nodelete

[root@server domains]# ls -aR domain.maindomain.com domain.maindomain.com: . .. homes logs public_html

domain.maindomain.com/homes: . ..

domain.maindomain.com/logs: . .. access_log error_log .nodelete

domain.maindomain.com/public_html: . .. Maildir

domain.maindomain.com/public_html/Maildir: . .. cur new tmp .trash

domain.maindomain.com/public_html/Maildir/cur: . ..

domain.maindomain.com/public_html/Maildir/new: . ..

domain.maindomain.com/public_html/Maildir/tmp: . ..

domain.maindomain.com/public_html/Maildir/.trash: . .. cur new tmp

domain.maindomain.com/public_html/Maildir/.trash/cur: . ..

domain.maindomain.com/public_html/Maildir/.trash/new: . ..

domain.maindomain.com/public_html/Maildir/.trash/tmp: . ..

Also there is a folder inside /home/username/public_html/domain with a Maildir inside it.

Converting from sub-server to parent server:

Converting virtual server domain.maindomain.com to a parent server ..

For : Creating administration group domain .. .. done

For : Creating administration user domain .. .. done

For : Creating aliases for administration user .. .. done

For : Adding administration user to groups .. .. done

For domain.maindomain.com : Moving home directory .. .. done

For domain.maindomain.com : Setting ownership for home directory .. .. done

For domain.com : Moving home directory .. .. move failed : mv: cannot move /home/username/domains/domain.com' to/home/domain/domains/domain.com': No such file or directory

For domain.com : Setting ownership for home directory .. .. done

For domain.maindomain.com : Updating mailbox users .. .. done

For domain.maindomain.com : Changing home directory in website configuration .. .. done

For domain.maindomain.com : Changing username in website configuration .. .. done

For domain.maindomain.com : Adding Apache user apache to server's group .. .. done

For domain.com : Creating Webmin user .. .. done

Saving server details .. .. done

Updating Webmin user .. .. done

Applying web server configuration .. .. not running!

Re-loading Webmin .. .. done

Now the /home/username/domains/domain.maindomain.com folder does not exist but has been moved to /home/domain and seems to contain the same contents as above.

The /home/username/domains/domain.com folder does exist in the same place with the same contents above.

There is still a folder inside the main domains public_html folder with the Maildir in it. This folder doesn't appear to exist in every case. Haven't figured out the pattern yet. It could be that some of the folders were missing on the old server due to the crash.

Ok I am figuring things out. I notice I can convert the seconddomain.com to a sub-server and to a parent-server instead of the seconddomain.maindomain.com and then convert the seconddomain.maindomain.com server and there is no error but something seems to be not quite right.

The domain servers don't contain any content inside their public_html folders because in cPanel they were just redirects, it is inside the seconddomain.maindomain.com public_html folder.

During this converting of the seconddomain.com server it actually adds in the fcgi and php.ini files substituting the variables so thats good.

But when converting the seconddomain.maindomain.com server to sub-server and then to parent-server it places its folder (seconddomain.maindomain.com) inside the /home/user2/seconddomain.com and there is no domains folder in here. Even when I manually create the domains folder first before converting the seconddomain.maindomain.com sub-server to a parent-server it is still just placing it into the folder but not into the domains folder, eventhough the folder is chown to the proper user, at least I think its the proper one. It seems like maybe the owner of the files changed when I converted the seconddomain.maindomain.com server.

Something is also wrong when I try to convert the seconddomain.maindomain.com server back to a sub-server of the maindomain.com server. It is taking the entire folder which used to belong to the seconddomain.com server and moving it into /home/user1/domains/seconddomain.maindomain.com and then that folder still contains the files which were originally placed by the first conversion of the seconddomain.com server, including the folder that the conversion of the seconddomain.maindomain.com server placed there which actually contains the public_html folder which contains the websites files which are supposed to be viewable by the public when going to seconddomain.com in their browser.

I can do a bunch of tests and show you the before and after results of everything if you like.

Ok well I did the tests anyway... and I may as well post the results here for you. Hopefully thats ok =)

I will use user1 as the main username of the top level domain. There is only one top level domain right after migration.

All other domains other than the initial top level domain are "sub-domain" servers and actually are named sub-domains of the main domain. i.e. subdomain.maindomain.com

I will use the domain name as user2 for an example domain which I will convert.

I will show you a listing of before and after each step of converting to a parent level domain and show each directory and you will be able to see what happens because I think I figured it out.

During conversion to a parent-server I am entering a new username and password because I have it set up to run with suexec.

user1.com
...
    |_user2.user1.com
        |_user2.com

As I have discovered there is no error with moving files when I convert user2.com before converting user2.user1.com but if I convert user2.user1.com first it gives an error moving the files to a non existing directory.

user2.com - converting to a sub-server

     Before:
          /home/user1/public_html/user2
               -contains a Joomla installation

          /home/user1/domains/user2.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

          /home/user1/domains/user2.user1.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

     After:
          /home/user1/public_html/user2
               -unchanged

          /home/user1/domains/user2.com
               -contains the following folders and files:
                    cgi-bin
                    fcgi-bin
                    homes
                    logs
                    php
                    public_html
                    tmp
                    .bash_logout
                    .bash_profile
                    .bashrc

               -public_html folder is empty
               -has copied in the fcgi-bin and php folders from the /etc/skel folder substituting variables in
                        
          /home/user1/domains/user2.user1.com (contains a blank homes folder and a logs folder with an empty .nodelete file)
               -unchanged

user2.com - converting to a parent-server

     After:
          /home/user1/public_html/user2
               -unchanged
              
          /home/user1/domains/user2.com
               -moved to /home/user2
         
          /home/user1/domains/user2.user1.com
               -unchanged

At this point I am guessing that this domain would function, if it had anything in its public_html folder but its public_html folder is still in the user2.user1.com sub-domain server.

user2.user1.com - converting to a sub-server after converting user2.com to parent-server

     Before:
          /home/user1/public_html/user2
               -contains a Joomla installation
              
          /home/user2
               -contains the following folders and files:
                    cgi-bin
                    fcgi-bin
                    homes
                    logs
                    php
                    public_html
                    tmp
                    .bash_logout
                    .bash_profile
                    .bashrc

               -public_html folder is empty
               -has copied in the fcgi-bin and php folders from the /etc/skel folder substituting variables in
               -logs folder has links in it to log files

          /home/user1/domains/user2.user1.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

     After:
          /home/user1/public_html/user2
               -moved to /home/user1/domains/user2.user1.com/public_html
         
          /home/user2
               -unchanged
              
          /home/user1/domains/user2.user1.com
               -now contains a public_html folder with the Joomla install in it
               -logs folder has links in it to log files
              
user2.user1.com - converting to a parent-server

     After:
          /home/user1/domains/user2.user1.com
               -moved to /home/user2/user2.user1.com

          /home/user2
               -contains the following folders and files:
                    user2.user1.com
                    cgi-bin
                    fcgi-bin
                    homes
                    logs
                    php
                    public_html
                    tmp
                    .bash_logout
                    .bash_profile
                    .bashrc
         
user2.user1.com - converting to a sub-server before converting user2.com to parent-server
     Before:
          /home/user1/public_html/user2
               -this contains a Joomla installation in this case

          /home/user1/domains/user2.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

          /home/user1/domains/user2.user1.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

     After:
          /home/user1/public_html/user2
               -moved to /home/user1/domains/user2.user1.com/public_html

          /home/user1/domains/user2.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

          /home/user1/domains/user2.user1.com
               -contains a blank homes folder and a logs folder with an empty .nodelete file

user2.user1.com - converting to a parent-server before converting user2.com to parent-server

     During:
          This error turns up:
    
               For user2.com : Moving home directory ..
               .. move failed : mv: cannot move '/home/user1/domains/user2.com' to '/home/user2/domains/user2.com': No such file or directory

     After:
          /home/user1/domains/user2.user1.com
               -moved to /home/user2
               -contains the following files and folders:
                    homes
                    logs
                    public_html
              
          /home/user1/domains/user2.com
               -unchanged

I re-read one of your previous posts about creating the domains folder and it dawned on me that I may have misunderstood what you meant. If I convert user2.user1.com before converting user2.com to a sub-server and then before converting it to a parent-server I go into /home/user1/domains/user2.user1.com and create a domains folder and chown it to user1 which is who the owner of the other files there is no mv error.

Then I have a /home/user2/domains/user2.com folder but the fcgi-bin and php folders aren't copied into the /home/user2 folder as they are when I convert the user2.com server first.

Also in some cases it seems that for whatever reason it puts a Maildir into /home/user1/public_html/user2.com/MailDir. When I go into the user2.com server and check for mail users it only has the option for Edit Mail Aliases and in there it says Same mailbox in domain user2.user1.com. So I go to the user2.user1.com server and it has Same mailbox in domain user1.com. However it also has a Edit Mail and FTP Users which obviously has the user2 username. But why is it putting this out there? Is it a setting somewhere that I have to change or is it a bug? I don't remember Virtualmin every just putting Maildirs in the public_html folder by default like that.

Hopefully this is helpful in helping in some way =)

Edit: I'm not really sure why things are misaligned but they aren't when I am editing it. Maybe its the tabs. So I just converted all tabs to 5 spaces and it still looks ok when editing. Lets see how it looks now when I save.

Sorry for so many huge posts but I just wanted to say that it should be noted that not all of the domains are equal to the same as the sub-domains. For example one could be thisname.domain.com but the domain redirecting at it might be thatname.com. And not necesarily user2.user1.com and user2.com as I have above.

Is there any chance I could login to your system myself to see what is going wrong here?

It may be simpler if I was to try the migration and conversion of some domains myself ..

Yeah, you sure can. Thank you for helping!!! If thats the best way to do it then so be it. Nobody is using it yet for anything except me trying to make things work before the 13th.

What is the best way to send you the info? Should I send it to your email you sent me something from?

I have created some scripts inside the /root/vm folder but you definitely would want to look them over before using them. One is the one you helped with to delete them. And one does a whole bunch of different things to try to fix them named fix-cpanel-domains.sh. I am having problems getting it to move the public_html and Maildir directories to what I figure should be the proper places. Then I have to figure out how to delete all the unneeded user2.user.com servers which are all subdomains off the main domain and I think aren't really needed once I can move out their public_html folder.

Right now I am actually running the delete script on there to remove everything completely since they are all messed up from my testing. Then if you like you can migrate them in yourself to see whats going on but I suspect it will take ages. I usually just leave it import them over night since it takes so long.

First though before you try it you might like it better if I were to create a new, smaller cPanel backup file. It is also a little bit different because I added a lot of the domain redirects on the old cPanel server since they can't wait to get some of their sites back up.

None of the databases were deleted in their crash just all the files inside the /home/user1 folder including mail and some cPanel files which it stores there by the looks of it. The host brought backups from 2 years ago in because the client didn't download any recent ones due to how large they were. So maybe thats the only problem and maybe it has nothing to do with Virtualmin. But thats why I have this fix-cpanel.domains.sh file to fix it. If it only worked right it might just do the trick. I don't know how to program in BASH I was just following bits of code and whatnot that I found around the net.

One thing to note is that those automatically generated domains are unique because their actual final public_html folders are supposed to be viewable from a subdirectory of another domain which is where they are all stored at. However theres probably no link to these folders since the domain redirects are supposed to direct at some affiliate tracking thing they have set up and from there it gets redirected to the subdirectory.

I am creating a new backup file in cPanel and will transfer it over once its done... whenever that is. Its going to be much much much smaller and I want to see if it excludes the unnecessary folders properly this time since I changed the way its trying to locate them in the cpbackup-exclude.conf file.

Anyway, the servers are all done being removed. The cPanel backup is being created. It may take a long long time since thats just what they do. And then I will transfer it into /home/old where the other one is.

I know this is a huge time consuming process so if you need a few extra dollars for your time just let me know and I'll send them the bill =)