Domain Migration to a Unix Server

Share this article

To switch Web providers or install a new server entails the migration of all your domain’s Web pages and other files. While we won’t cover implementation and configuration of a virtual domain here, we will focus on how to transfer the files from your previous server to the new one.

Why Migration isn’t as Simple as it Looks

At first glance, this task may seem straightforward enough: simply download the files by FTP to your local system, and then upload them again to the new server.

However, this approach has several serious drawbacks:

  • file permissions will not be preserved
  • file ownership will change
  • ASCII files carrying an unknown extension may be treated as binaries
  • the files will be down- and uploaded in uncompressed form, which wastes time, bandwidth and system resources.

If you proceed in this manner, you’ll be in for a lot of adjustment work to make everything run as it did before. This applies especially to CGI scripts where directory and file permissions are critical to ensure functionality.

Migration Made Easy

Here’s a method that will simplify your migration and slash unnecessary work in the process.

  1. Log in to your old server by Telnet (e.g. as user "domainowner").
  • Navigate to your domain directory (e.g. :cd /usr/www/htdocs/yourdomain).
  • Next, compress the files into an archive by entering the following on the command line:
    tar -cpz --same-owner -f yourdomain.tar.gz * .htaccess

    The "tar" command requires the following syntax:
    tar -function -option file
     function:   c create archive
     option:     p extract all protection information
       z compress data with gzip
       --same-owner create extracted files with the same ownership
       f use archive file

    In our example above, the achive file "yourdomain.tar.gz" will be generated. You may chose any file name you prefer, as long as you stick to the extension ".tar.gz". The wildcard character "*" (second-last in the command above) specifies that all files, including those that reside in subdirectories, will be included in the archive. However, because this won’t include files that begin with a period, you will have to list those files explicitly. In our example this is file ".htaccess".

  • Now, on the new server, you will have to configure user account "domainowner" and the directory "/usr/www/htdocs/yourdomain". Note that if the directory names on your previous server are not identical to those on your new server, you may have to modify the path variables in your CGI scripts. Hence, it’s strongly recommended that you simply clone directory names.
  • Now, to upload the archive file "yourdomain.tar.gz" to your new system. There are two possible ways to do this:
    • directly, by logging in to your new server and downloading the file from there using whatever FTP client is available, e.g. WU-FTP. Consult the program’s documentation to learn how to do this as we cannot cover it here.
      or
    • by downloading the file to your local system first, and then uploading it to the new server from there.
  • On the new system, log in via Telnet e.g. as user "domainowner".
  • Switch into your domain directory e.g. by typing: cd /usr/www/htdocs/yourdomain
  • Next, you’ll need to unpack the archive file. Enter the command:
  • tar -xz -f yourdomain.tar.gz 

       function:   x extract files from an archive
       option:     z uncompress data with gzip
                   f use archive file

    There – you have now successfully duplicated the previous, familiar environment on your new system!

    However, I’d recommend that you test the new domain setup thoroughly, especially your CGI scripts, before you launch it officially.

    Synchronize your Systems

    Should some files on your previous server have been modified or added before actual launch of your new setup, you can synchronize the two systems in the following manner:

    1. Log in via Telnet on your old server e.g. as user "domainowner".

  • Switch to your domain directory, e.g. by entering:
    cd /usr/www/htdocs/yourdomain

  • List all new and modified files, using this command:
    /usr/bin/find -newer yourdomain.tar.gz > newerfiles.txt

    This command will compare the files with the archive file you generated in Step 3 above. All new and modified files will now be listed in the file "newerfiles.txt".

  • Edit the file "newerfiles.txt" and delete the line "." and the lines including directories, e.g.: "./graphics" You can do this in two ways. To complete the changes locally, download the file first and open your text editor (ASCII format only!). Or, to carry out the changes online, open your favorite online editor.
  • Next, the new and modified files must be packed into an archive with this command:

    tar -cpz --same-owner -f yourdomain-new-files.tar.gz -T  
    newerfiles.txt
    option:   T get names to extract or create from file F
  • Now, upload the newly generated archive file, "yourdomain-new-files.tar.gz", to your new server as explained above in Step 5 above.
  • To unpack the archive, enter this command:
  • tar -xz -f yourdomain-new-files.tar.gz
    
    

    Congratulations! All the files on your old and your new systems have been synchronized and you can activate the migrated domain on its new hosting server.

    Dirk BrockhausenDirk Brockhausen
    View Author

    Dirk is the co-founder and principal of fantomaster.com (UK) and fantomaster.com GmbH (Belgium), a company that specializes in Webmaster software development, industrial-strength cloaking and search engine positioning services.

    Share this article
    Read Next
    Get the freshest news and resources for developers, designers and digital creators in your inbox each week
    Loading form