EMCopy is a command-line file based migration tool that is used to replicate SMB files/directories including ability to replicate ACL permissions and ownership., another similar file based migration tools are SecureCopy and RoboCopy.

EMCopy usage/switches:

Usage: EMCOPY srcdir destdir
[name [name]…] [/nosec] [/o] [/a] [/secfix] [/secforce] [/hda <account>] [/lg] [/lu] [/i] [/create] [/s] [/lev:n] [/d] [/de] [/sd] [/l] [/z] [/r:n] [/w:n] [/th n] [/cm <content|md5>] [/sidmapfile <mapping_file>] [/ignoredhsm] [/purge] [/stream] [/chunk] [/nocase] [/sdd] [/xjd] [/q][/tee][/compress <ignore|forcefile|forcedir|forceall> [/trfwindow <transfer window size in MB> [/f] [/c] [/BackupSD] [/RestoreSD] [/nd:domain_name] [/preserveSIDh] [/nodf] [/xd dir [dir]…] [/xf file [file]…]

Explanation of the switches where copied from emcopy version 4.17 (which is the latest copy available at the time of this post)

The “/nosec” option disables the copy of the NT security properties of the file or the directory. By default, discretionary access control-lists are replicated on the created file or directory. This option takes priority on the “/o”, “/a”, “/lg”, “/i” options.

The “/o” option enables the copy of a file’s owner. Without this option, the account used for the copy will be the owner of the copied files and directories.

The “/a” option enables the copy of auditing information’s. The “Manage Auditing” privilege must also be granted by the user account.

The “/secfix” option enables to update of the NT security properties even if the destination file or directory already exists. When destination object exits, security from source is merged with security from destination.

The “/secforce” option enables to force update of the NT security properties even if the destination file or directory already exists. When destination object exists, security from source overwrite the destination security.

The “/hda <account>” option enables the homedir migration mode. In that mode security information is derived from the security information of the target directory when it exists or from the security information of its parent directory.

The “/lg” option enables the copy of local group security entries. Without this option, local group entries are ignored.

The “/lu” option enables the copy of local user security entries. Without this option, local user entries are ignored.

The “/i” option is useful to ignore security entries with local users. By definition, local users are only unknown for the NT server or worktstation where they are created. To avoid security replication error on the dextination server, it is possible to remove this type of user in the copied properties.

The “/create” creates 0 file length rather than copy the data.

The “/s” option enables the copy of the subdirectories.

The “/lev:n” sets the depth level of scanned directories.

The “/d” option provides to copy only source files which have the LAST MODIFICATION time greater than the existing target copy.

The “/de” option provides to copy the source file when its last modification time is not equal to the destination file’s modification time or when files size are differents.

The “/xjd” option force emcopy to ignore directories that are mount point or DFS link. By default emcopy considers these kinds of directory as regular directories.

The “/sd” option is to preserve the security. In this case, the file content is not copied if any error occurred during the security setting.

The “/sidmapfile <mapping_file>” specifies a file that contains mapping records to be used for SID translation.

The “/ignoredhsm” option forces emcopy to remove any DHSM specific information and to remove the OFFLINE attribute when present.

The “/l” option evaluates the number of files to copy without to do any file duplication. Compares also the NT security if the “/secfix or /secforce” option security. In that case, the “/o” and “/a” switches are used to specify the owner and the audit properties comparison. When differences occur, the properties of both the source and destination files or directory are printed.

The “/c” switch allows the process to continue after the retries.

The “/z” switch is the restartable mode: the restartable mode is no more supported, usage of this switch doesn’t have any effect.

The “/r:n” option specifies the maximum number of retries. By default it is set up to 100.

The “/w:n” option specifies the time in seconds to wait between two retries. By default it is set up to 30 seconds.

The “/th n” option specifies the maximum number of thread. By default it is set up to 64.

The “/cm content” option enables a file content comparaison mode. Content of source and target files are binary compared after the copy or when doing an evaluation of the copy.

The “/cm md5” option enables a file content check after the copy using md5 signatures computed on both source and target files.

The “/purge” option enables the deletion of the files and directories from the destination tree which do not exist in the source one.

The “/compress ignore” option forces emcopy to ignore the compress attribute on files and directories.

The “/compress forcefile” option forces emcopy to set the compressed attribute on files.

The “/compress forcedir” option forces emcopy to set the compressed attribute on directories.

The “/compress forceall” option forces emcopy to set the compressed attribute on files and directories.

The “/sdd” option forces the target directory’s dates to be synchronized with the source directory’s dates.

The “/stream” option enables the copie of files and directories datastreams. Without that option only the main datastream of files are copied.

The “/log:filename” option allows to redirect the console messages to a new file.

The “/log+:filename” option appends the new messages to an existing file.

The “/u” option force logfile to be filled up with unicode character set.

The “/q” switch allows the user to disable the print of the files on stdout.

The “/f” switch allows the user to ask for the fullpath print, both the source and the destination paths are printed. By default, only the source path is printed.

The “/BackupSD” and “/RestoreSD” switches allow to backup and restore the security properties without copying the file content. There is no local group translation and local SID suppression.

The “/nd:domain_name” switch allow to translate SD using new domain domain_name instead of original domain.

The “/preserveSIDh” switch allow to preserve SID from previous domain. By default emcopy replace obsolete SID by corresponding SID in current domain.

The “/nodf” switch allow to only do a name filtering on file. By default directories and files are processed only if they feet with the list of names that are specified in the command line.

The “/xd dir [dir …]” switch allow to excludes directories with the specified names, paths, or wildcard characters.

The “/xf file [file …]” switch allow to excludes files with the specified names, paths, or wildcard characters.

The “/tee” switch allow to push the output of the copy job to the colsole during testing to review what is occuring and view errors. you should not use this switch while running real copy jobs as it can impact the performance of the migration

 

We will provide two example scenarios on how you can use EMCopy as a file based migration tool:

Scenario 1:
We would like to copy files from Server1 to Server2 as part of evergreen or moving files to another server.Example command:
emcopy64.exe c:\source c:\target /ignoredhsm /o /sd /s /de /sdd /th 16 /secforce /purge /c /r:3 /w:1  /log+:c:\migration_log.txt
You can use the above command to do the initial copy and all the consecutive differential copies.
Also this command will delete any file that the user deleted on the source, in this way the source and the target are mirrored.

 

Scenario 2:
We would like to consolidate two windows file servers to one array with the same directory structure.Example scenario as the following:
Server1:
C:\source\dir3
Server2:
C:\source\dir1
C:\source\dir2
Target should look like:
C:\target\dir1 <== adding Server2 dir1
C:\target\dir2 <== adding Server2 dir2
C:\target\dir3 <== adding Server1 dir3

Note that /xd switch needs the source and the target directory structure to be identical, so in this example you need to create dir3 on server2 to execute the task successfully.

Solution:
We should create “dir3” directory on server2:
C:\source\dir1
C:\source\dir2
C:\source\dir3  <== create an empty directory with the same name as destination
To
C:\target\dir1
C:\target\dir2
C:\target\dir3

Example command:
Server1:
emcopy64.exe c:\source c:\target /ignoredhsm /o /sd /s /de /sdd /th 16 /purge /secforce /c /r:3 /w:1 /log+:c:\migration_log.txt
Server2:
emcopy64.exe c:\source c:\target /ignoredhsm /o /sd /s /de /sdd /th 16 /purge /secforce /c /r:3 /w:1 /xd c:\source\dir3 /log+:c:\migration_log.txt