Pro Tip: How to Copy Files from One Server to Another

Copying files from one server to another is a fairly frequent task that system administrators face. As with most things in IT, there are many ways to accomplish this task.  The method you choose will depend on your situation and your personal preferences.  The information below assumes that both of your servers are on the same domain.

If you don’t like the command line, you could just drag and drop the files to the new server.  But Windows Explorer doesn’t have any real error handling or logging, so if anything goes wrong, you end up having to guess what caused the problem.  There are several good third-party tools out there to enhance Explorer, but most admins prefer to keep their servers as lean and clean as possible.

In the modern world of Virtual Machines, another option is to just make a copy of the entire VM file and then attach that as a secondary drive to the destination server.  This is only viable if you want all of the files and all of the same permission settings.  If that is your goal, it’s easy to do and works well.

How to Copy Files to a Server Using Robocopy

If you only want to copy some of the files to a server, you will probably want to use Robocopy.  It’s been around since Windows Server 2003 and is a very powerful tool.  With Robocopy you can copy a single file, stripping all permissions, mirror an entire drive while keeping all NTFS permissions in place, and pretty much anything in between.  You can run Robocopy from your workstation, specifying the source and destination file servers, but running it directly on one of the servers will be faster and will generate less network traffic.

If you want to copy folder DATA on Server1 to Server2, for instance, you could use this command:

  • Robocopy \\server1\data \\server2\data /mir /copyall /dcopy:T

This will create an exact copy of the source folder structure, including all permissions and time stamps.  Because it’s creating a mirror, it will also delete anything in the destination that doesn’t match the source.  It is perfect for copying to blank destinations but is potentially hazardous if there is already data there.

If you want to copy an entire folder, but don’t want to keep the permissions or delete anything from the destination folder, you could use the following command:

  • Robocopy \\server1\data \\server2\data /e

But Robocopy doesn’t just do simple copying.  As mentioned earlier, it’s a very powerful tool.  You can set it to monitor (/mon) the source folder and copy it again if changes are detected.  You can set it to list only (/l) to preview results without actually copying anything.  You can set it to only copy files with the hidden attribute set (/ia:H) or to exclude (/xa:H) hidden files.

You can also do some things that don’t involve copying files.  Perhaps you used the /copyall option because you wanted all permissions copied over but then had to change some of the permissions on the source.  You can use /sec /nocopy to update the permissions without having to copy the files from the server again.

There are many other ways you can use this tool, including full logging capabilities.  Here is a full list of Robocopy parameters: Robocopy Command Line Reference.

IT professional with more than 25 years of experience. Larry manages Windows networks, moderates an online IT community forum, and shares his experience of handling everyday sysadmin tasks in the most effective and creative ways.