The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
Tranferring websites/users from one box to another 21 May 2000
Need more help on this topic? Click here
This article has no comments
Show me similar articles
When I was setting up my new web server, I had to copy the files from one box to another.  But if you just do a tarball and ftp, you won't get what you expect.   Specifically, the permissions may be fuggered.  So here's what I did to avoid that problem.
It's all about permissions and groups
Access to files and directories is determined by the permissions set upon the directory tree.  The permissions are related to users and groups.  Users and groups are defined by numbers as set in the password and group files.  When we do "ls -l", we see the owner of the file, such as "www".  However, that name is just for our benefit.  The underlying system actualy uses a number (a user id, or UID) which is associated with that name.  To find out what number is used, run vipw and look for www.  You'll see something like this:
www:*:99:99::0:0:apache Daemon:/nonexistent:/sbin/nologin

This means that www has a UID (user id) of 99 and a default group id (GID) of 99.   It's those numbers which are important.  If we just copy files from one system to another without first ensuring that the users on the new system have the same UID and GID as the old system, we may find the results suprising at least.  And nasty at worst.  For example, you might find that someone else already has the UID for www.   That would allo them to read/write the files for which www previously had exclusive access.  This can be quite a serious issue.  Be wary.

Copy/paste
What I did was open vipw on both the source and destination boxes.   Then I did a copy and paste from one box to the the other.  There, done.   Then I did the same thing with /etc/group.  You do have to be careful when doing this.  Make sure that the two systems are using the same password encryption method.  You can usually tell that by looking at the passwords involved.   Either they all start with $1 or they don't.  Ask someone who knows more about this.  Better still, if you know, please add your comments.
Copying the files from one box to the other
I chose tar and NFS to do this (see drive to drive backup and NFS for preliminary details).  You could also just tar up the directories on one box, and ftp them over, then extract them.  Or you could use rsync.

First I exported the directory I wanted to backup.  Then I mounted that volume.  I did an ls on both boxes to make sure I was seeing the correction user and group names.

Then I issued the following commands on the destination box:

# cd /path/to/source/nfs/mount/point
# tar -cvlf - . | ( cd /path/to/local/dest; tar xpf -)

Then I needed to merge the apache.conf files from one box to the other.  I took everything after the default virtual hosts, changed the names for virtual hosts.  I had serveral lines like this:

<VirtualHost    192.168.1.1>

Which needed to look like this:

<VirtualHost    192.168.0.78>

So I started vi, and issued this command:

%s/192.168.1.1/192.168.0.78/

And it was done.


Need more help on this topic? Click here
This article has no comments
Show me similar articles