Using the XCopy Tool
Backing up your data is vital, whether it's your holiday photos or your business, and there are many products out there that all do the same thing: backup your data. XCopy can also be used as a quick deployment solution.
Adverts Blocked Please disable AdBlocking software and allow me to set cookies so that I can continue providing free content and services.
First, let's bring up the command prompt and look at xcopy.
C:\Documents and Settings\....\>xcopy /? Copies files and directory trees. XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/EXCLUDE:file1[+file2][+file3]...] source Specifies the file(s) to copy. destination Specifies the location and/or name of new files. /A Copies only files with the archive attribute set, doesn't change the attribute. /M Copies only files with the archive attribute set, turns off the archive attribute. /D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time. /EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. Each string should be in a separate line in the files. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like obj or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively. /P Prompts you before creating each destination file. /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /V Verifies each new file. /W Prompts you to press a key before copying. /C Continues copying even if errors occur. /I If destination does not exist and copying more than one file, assumes that destination must be a directory. /Q Does not display file names while copying. /F Displays full source and destination file names while copying. /L Displays files that would be copied. /G Allows the copying of encrypted files to destination that does not support encryption. /H Copies hidden and system files also. /R Overwrites read-only files. /T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories. /U Copies only files that already exist in destination. /K Copies attributes. Normal Xcopy will reset read-only attributes. /N Copies using the generated short names. /O Copies file ownership and ACL information. /X Copies file audit settings (implies /O). /Y Suppresses prompting to confirm you want to overwrite an existing destination file. /-Y Causes prompting to confirm you want to overwrite an existing destination file. /Z Copies networked files in restartable mode. The switch /Y may be preset in the COPYCMD environment variable. This may be overridden with /-Y on the command line. C:\Documents and Settings\>_
Looks pretty intimidating doesn't it? But don't worry, I'll show you how to do a differential backup or deploy a website solution. The technique is the same; in fact the only difference is the target server.
For this example we will assume that my documents are located in C:/My Documents/ and that I want to copy them to another drive (can be a mapped network drive)
xcopy "c:\my documents\mywebsite\*.*" "z:\inetpub\wwwroot\mywebsite"
When you run this command you will get the message "Does z:\inetpub\wwwroot\mywebsite specify a file name or directory name on the target?". This is because the command can't tell if you want to copy to a folder or a file called my backup. This can be remedied using the /I switch to force the destination as a folder.
This will now copy all the files in c:\my documents\mywebsite to z:\inetpub\wwwroot\mywebsite. All well and good, but this will not copy sub directories, to do this we need to add /E to the end of the command. It would also be a good idea to verify the data we are coping to be sure it hasn't been corrupted by adding /V to the command. We can then put this command into a batch file that we can run to create a simple deployment solution.
Create a new batch file and enter in our new command:
xcopy "c:\my documents\mywebsite\*.*" "z:\inetpub\wwwroot\mywebsite" /I/E/V
When this is run it will copy the entire contents of c:\my documents\mywebsite to z:\inetpub\wwwroot\mywebsite including all sub directories. When run again however you will get a message stating "File creation error - Cannot create a file when that file already exists." What we need to do now is tell the command to overwrite existing files, so add /Y and /R to the command.
There are a few other switches that we are going to use, /C will continue, even id there is an error. This prevents the backups from halting all together. /H will copy any hidden and system files such as thumbs.db (Windows Explorer Thumbnails), /K will also copy over file attributes such as Read-Only, Hidden etc... /D and /M will copy files if they have been modified since the last backup.
Our command should now look like this:
Differential backup using XCopy
xcopy "c:\my documents\mywebsite\*.*" "z:\inetpub\wwwroot\mywebsite" /C/E/H/R/K/D/M/Y
What we have here is a differential backup batch file using xcopy.
You can add multiple lines to the batch file to deploy or backup more than one folder.
If you only wish to update/copy/backup/deploy a particular file extension (e.g. all the jpeg images) all you need to do is specify *.jpg instead of the *.* source pattern.
Last updated on: Saturday 17th June 2017
Find Files easily, once the Microsoft tool is fixed
Turn off automatic rebooting for Windows Updates