Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am getting a server in a different location from where the current one is and getting rid of the current one.

I am needing to find a way to seamlessly transfer the following:

  • User's directories in /home
  • Apache configuration
  • MySQL databases, users, and configuration
  • Awstats information (already processed statistics included)

I'm mainly worried about the MySQL databases, is it as simple as copying over a folder structure and everything works again (of course after installing MySQL on the new server)? What about file permissions for user's sites? I know a few users are using forum systems, and those usually have certain directories that require permissions like 775. Is there any way to preserve that?

share|improve this question
I have experienced something like this. I recommend you to compress anything you need and transfer it via ssh, and restore on the new server. Take a look at this. – mert Aug 14 '12 at 22:45

Files and Directories

For this, you have two tools that you can start with.

For the user's directories, Apache configuration and Awstats files, you can use tar.

# tar cvpzf myfiles.tgz *

This will copy sub-directories, retain permissions and create a single archive that you can untar on the new system. What I am a little unsure of is how it will preserve user permissions on your new server if the UID is changing for each user.

To restore the tar file on the new server it will look something like this. Run it in the current directory you wish to expand the directory structure to.

# tar xvpzf myfiles.tgz

As a side note, you can also look into the tar file and see the table of contents. This lets you check how everything looks inside the file without needing to extract the contents.

# tar xvzf myfiles.tgz

MySQL - mysqldump for backup and restore

For MySQL, don't take a short cut here. Use mysqldump to make a backup of your databases and ideally make one backup for each database.

# mysqldump -u [user] -p[password] [database_name] > [database_name].sql

On the new system you can restore the file using mysqldump as well. Just make sure you have already done created the database on the new server as I think the backup may not have the CREATE DATABASE option in the SQL backup file.

# mysqldump -u [user] -p[password] [database_name] < database_name.sql

Good luck.

share|improve this answer

One thing you can do is synchronize the old with the new server. First thing to do may be to add users of /etc/passwd and groups of /etc/group into the corresponding files of the new server. You may try to use the same uid and gid

For data, you have rsync that may be used with the following options:

--compress (optionally - compress data for faster transfer of data)
 -e 'ssh -p 2234' (use ssh for secure connection between servers)

The first time, you can rsync every directory that contains relevant data. Permissions will remain the same, as you used the --archive option. After this, you can try to simulate access to the new server and check if accesses are working fine: for mysql, http, other...

You don't say if the centos version is the same or not. If not, you should verify whether mysql version is a major upgrade (for example, 5.1 in old server and 5.5 in new one) or not. If it's a major upgrade, you should read the mysql documentation and probably run mysql_upgrade. As you'll be using centos in both server, I presume, the user mysql runs under should be the same. Mysql should run fine if you copy or rsync the data between the two servers.

At a certain point you will need to synchronize again data and cut off the old server and bring the new one for live status. When this moment comes, you should stop mysql and rsync data using two more options:

--update  (transfers only new data)
--delete  (deletes data in new server that doesn't exist anymore in old server)

For the most part, I think you can follow these guidelines.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.