Help - Search - Members - Calendar
Full Version: Ensim to cPanel scripts for 2nd HD mounted
The Planet Forums > Control Panels > cPanel/WHM > Cpanel/WHM HOWTOs
web1
This is for when you need to convert accounts from Ensim to cPanel and you have your old Ensim HD mounted as a second HD. At this time cPanel only transfers from Ensim if it is on another server.

If your ensim accounts are on another server, go look at the "Transfer" section in your WHM and use that, it's easier! (you may have to edit usernames)

YOU MUST HAVE KNOWLEDGE OF SHELL SCRIPTS to use this information!

WARNING: Use at your own risk, do what you want with the code, have fun, add to this, change it around, post your changes, but please don't bug me to fix it.

I was using the "vhbackup" script that automatically makes ensim compatible backup .tar files daily but this should work with normal ensim created backup files.

To make this clear, this will take a ensim backup tar file and copy all the html and cgi-bin files to the proper places in the new cPanel setup.

You will need to manually create each virtual site using cPanel, then create each user if there are extra ones for the site. I also had to make a script that shows what users belong to what site. This does not move any mail files, you need to do that manually.

After that, go root (via ssh and su - of course) and do everything from a shell console.

There are two scripts, the first one will extract one sites' tar file and copy all the html and cgi stuff over to the new virtual site.

You start with the tar file(s) in the working directory you are at including the scripts, you have to change two variables at the top of the script for each new site. Again, the scripts are put in the same directory as the tar file(s) for easy access.

The next script uses my vhbackup directory containing *all* tar files for all the sites. I CD into the directory and put the script there, it simply prints out all the virtual site names, and all the users for the sites. I used this to help me create the site users again on the cpanel side. I only run it once and save the printout.

If you are confused, go look inside one of the tar files and see how things are stored by ensim, it's pretty simple.

Hope all this helps someone.

I call this one "xfer.sh":

CODE
#! /bin/sh



# The new site must be created manually in cPanel !

# hidden files like ".htaccess" will be copied for

# the public_html folder only. If sub folders have

# hidden files they are not copied, sorry, talk to redhat



# change the two variables below for each site

# username is the cpanel username for site admin

SITE1="sitename.net"

USER1="username"





# the script begins....

WHERE1="/home/$USER1"



# unpack the backup tar file "sitename.net.tar"

tar -xpvf $SITE1.tar



# unpack etc, home, and var directories into "temp"

mkdir temp

tar -xzpvC temp -f $SITE1.tgz



# remove the cpanel created .htaccess file

rm -f $WHERE1/public_html/.htaccess



# copy files out to user directories

# copy to "public_html"

cp -pR temp/var/www/html/* $WHERE1/public_html/

# copy files like .htaccess because redhat changed things

cp -pR temp/var/www/html/.* $WHERE1/public_html/



# copy to "public cgi-bin"

cp -pR temp/var/www/cgi-bin/* $WHERE1/public_html/cgi-bin/



rm -fR temp



# change the user and group recursively

chown -R $USER1.nobody $WHERE1/public_html





I call this one "list-users.sh":

CODE
#! /bin/sh



# loop through all the file names in the directory

for i in *

do



# only work on files, no directories

if [ -f $i ]

then

# remove the ".tar" part of the site name

SITE1=`echo -n $i | sed 's/.tar//'`

echo SITE: $SITE1

# unpack the backup tar file "sitename.com.tar"

mkdir -p temp

tar -xpC temp -f $SITE1.tar

if [ $? -eq 0 ]

then

# unpack etc, home, and var directories into "temp"

mkdir -p temp/temp1

tar -xzpC temp/temp1 -f temp/$SITE1.tgz

cd temp/temp1/home/



# now loop through all and list the usernames

# and the size of any inbox they may have

for x in *

do



if [ -d $x ]

then

echo -n $x

INBOX1=../var/mail/$x

if [ -f $INBOX1 ]

then

echo

ls -al $INBOX1

else

echo " (no inbox)"

fi

fi

done

cd ../../../



fi



rm -fr temp



echo



fi

done







Now you need to work on securing your box.....
web1
A little info about shell scripts and stuff:

Shell scripts are just a simple step by step sequence of shell commands one line at a time. No loops, no "if" statements in the first script. It just saves you from typing in those commands over and over for each site. It's like a DOS batch ".bat" file.

The first time you use the script you can simply copy and paste into your terminal one command at a time and check to see what it did.

The scripts are changeable, that's the nice thing about them and why I posted it, since I have done all the hard stuff, you may only need to change a directory name or add a line to do something special for you.

If you have other commands you need to do for each site, it's simple to just add them at the end of the script.

My plan was to create all users on cpanel with the same names as they were on ensim.

As for the mysql databases I have on my server, it's not very hard to do a mysql export and import and I only have to do it on maybe 3 sites. I would create the databases using the cpanel interface, then do a import, not a big deal.

Look up (google) the commands "mysql" and "mysqldump". You can play with these commands on your existing system and then use phpmyadmin to check your results, just create a copy of an existing database or create some test tables. The commands look something like this and can be issued from a root console:

mysqldump db_name > database_file.sql

# import entire database
mysql --user=db_username --password=dbpasswd db_name < database_file.sql

You can go look at the "sql" text file it creates, it's not complicated, it's a simple text file and contains commands for mysql so it can rebuild the database line by line.

This one is fun:
mysqldump --all-databases > all_databases_file.sql

Do you think something like that could re-create all your databases on your new cpanel setup? I prefer to keep it simple and did it one at a time. Besides, cPanel names the databases differently than ensim did.

How does ensim store the database in the backup? It uses mysqldump just like you could and puts the file in the backup ".tar" archive..

As for the scripts, some confusion may occur when we use variables like "$USER1", but all the shell does is take the value we assigned at the top of the script "username" and insert it right there on that command line, so this:

USER1="the-main-user"
cp -pR temp/home/$USER1/public_html/* somewhere_else/public_html/

Would be the same as typing in this line manually:
cp -pR temp/home/the-main-user/public_html/* somewhere_else/public_html/

One other thing the script does is get rid of the temp directory we created:
rm -fr temp

You may ask "what does the "-fr" mean? You can always look up a command by typing "man rm", "man cp" or "man any_ command_name" at your console.

What was in "temp"? Simply the "etc", "var" and "home" directories from the ensim back up file, go look at the tar file.

This is basic scripting 101 but learning just this little bit may save you hours of work someday and should be part of your basic knowledge as a server admin.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.