Blackpool Computer Club is sponsored by: ThisHosting.Rocks

User Tools

Site Tools


7. Using the XCOPY command

XCOPY for Microsoft operating systems. It implements every important feature of backups except cataloguing, and saving files that won't fit on a single backup media. Here are some command line examples.

Command lines for FULL backup:

cmd.exe /k xcopy /c /e /f /h /i /s /v /y /z “source” “destination”

cmd.exe /c attrib -a *.* /s

Command line for INCREMENTAL backup:

cmd.exe /k xcopy /c /e /f /h /i /m /s /v /y /z “source” “destination”

Command line for DIFFERENTIAL backup:

cmd.exe /k xcopy /c /e /f /h /i /a /s /v /y /z “source” “destination”

Note that the “/k” can be change to “/c” which will cause the backup window to close automatically instead of staying open after the backup is done, as happens with the “/k” command line switch.

The “source” and “destination” are folders on the disk drives where the files to be copied (source) are backed up to (destination). It is useful to enclose the folders in quotation marks as shown, because in Windows, spaces are often used in folder names, and not using quotation marks confuses the XCOPY utility.

Here's a more realistic command line for an incremental backup:

cmd.exe /k xcopy /c /e /f /h /i /m /s /v /y /z “C:\Documents and Settings\Mortimer Snurd\My Documents\*.*” “F:\Backups\MSnurd”

Explanation of command lines

The first command lines, for the FULL backup are used as follows. First, the “cmd.exe” creates a command prompt window. The “/k” switch (the portion of the commands with a slash and additional subcommands are called “switches”) for the “cmd.exe” command causes the command prompt window to stay open after the commands are executed. This may be useful if you want to see the messages written to the command prompt window afterwards. It's not necessary to do this, though. Instead of the “/k” switch, you can use “/c” for the “cmd.exe” command. This will cause the command prompt window to close automatically after the command line is finished.

The rest of the line gets fed into the command prompt interpreter. The first line is the actual XCOPY command. This is what does the work.

Notice that the "/m" and "/a" switches are not used for the full backup 
as they are in the incremental and differential backups.

The second line of the full backup is used to clear the archive flags of all the files. Because the XCOPY command without the “/m” switch doesn't reset archive flags, and that's how the first line was invoked, we want to be sure that we explicitly reset all the archive flags.

That's what the “attrib” command does in the second line.

The command line for the Incremental Backup uses only one line. It isn't necessary to reset archive flags with the “attrib” command. Note that there is a switch “/m” on the command line.

The "/m" switch for XCOPY does two things. 
First it specifies that only files with the archive flag set be copied. 
Second, it resets the archive flag after the file is backed up.

The command line for the Differential Backup also uses one line.

The command line switch for the differential backup is "/a" instead of "/m". 
The "/a" switch for XCOPY   does one thing only. 
It specifies that only files with the archive flag set be copied. 
It does not reset the archive flag, though.

A full backup unconditionally backs up each candidate file (without respect to the last time it was modified, and without respect to whether it was modified since the last backup.) Then the backup program turns off the backup flag for the file. In Windows (R) the flag is called the “archive” flag. Turning off the archive flag insures that the file doesn't get backed up again by either an incremental or differential backup procedure. Note that the full backup doesn't depend on the state of the archive flag, but does turn it off, whether it was on or off before the backup.

Full backups take more storage space than incremental or differential backups because in a full backup, every candidate file is selected then backed up even if it has been backed up since it was last modified. The advantage of a full backup is that it give a baseline for future incremental or differential backups.

If a disk drive fails immediately after a successful full backup, the data can be loaded onto a new disk drive and put to work immediately. Only one restore operation (of the data) is required. No additional restorals (other than operating system files, if the data files are stored on the operating system disk) are needed. One operation restores the data files. When there are incremental and/or differential backups, the full backup has to be restored, then any required incremental or differential backups have to be restored.

Why not do a full backup each time? On a computer with lots of files, it can take an hour or longer to do a full backup. Also, the storage space for a full backup can be very high.

3b. Incremental backup

An incremental backup looks at each candidate file to see if the archive flag (see Full Backup above for an explanation of the archive flag) is set. If it is set, the file gets backed up. Additionally, the incremental backup program sets the archive flag off for the files that it backs up. Setting the archive flag off prevents the file from being backed up again by an incremental backup (or by a differential backup) program. The archive flag will get set on only if the file changes again, or if a special program turns it on.

The incremental backup is typically used as an adjunct to a full backup. A common backup scenario for low volume computer useage is to perform a full backup monthly then do an incremental backup weekly. If disaster strikes, only the most recent week of work will be lost. So if it's the 27th of the month, and you have the most recent full backup, plus three incremental backups, you can recover your data by restoring from the full backup, then restoring each of the three incremental backups.

The reason that the three incremental backups are needed is that files in the first weekly incremental backup are not backed up in the second incremental backup. They were backed up the first week, then flagged as having been backed up, so they don't get backed up in the second incremental backup. Likewise, the files from the third incremental backup don't include any unchanged files that were backed up in the first or second incremental backup.

Clearly, restoring a full backup and set of several additional incremental backups is time-consuming. That's why differential backups are sometimes used. But incremental backups have a definite use.

A second benefit of incremental backups is that a set of files can be restored to the state they were in at a particular point in time. If a project changes significantly, the work done since a specific point in time may be irrelevant. Data files can be restored to their condition at the time of the full backup. Then incremental backups can be restored in sequence up to the date when the project changed.

One disadvantage of an incremental backup is that several sets of backup media must be maintained. The full backup must be kept, regardless of the backup strategy. Then all the incremental backups since the last full backup must be kept available. In many cases this is an onerous burden, in others, it is not.

3c. Differential backup

The differential backup is also a useful method. It, of course, depends on a full backup having been done. Furthermore, it is used with the assumption that only differential backups will be used in addition to the full backups.

With a differential backup, only those files with the archive flag (see Full Backup above for an explanation of the archive flag) set are backed up. So far, this is the same as with an incremental backup. But the difference with the differential backup is that after the files are backed up, the archive flag is not set off. In other words, the file will again be backed up by the next backup procedure.

If a differential backup strategy is used, the backup media will use two backup sets: the full backup, and the most recent differential backup. If things have been done properly, that is to say, no incremental backups have been performed intermixed with full and differential backups, only two sets of backup media are required to restore the files. Specifically, with the differential backup approach, to restore to the most recent files, it is necessary to restore the most recent full backup and the most recent differential backup.

The advantage for the differential backup is that fewer backup sets are needed: the full backup and the most recent differential backup. The disadvantage of differential backups is that every file modified since the last full backup gets backed up every time a differential backup is peformed. That's because the differential backup program doesn't ever set the archive flag off. It usually takes more time than the incremental backup because the number of files with the archive flag set increases without getting reset in the differential procedure. On a day-to-day basis (assuming that backups are done daily) the backup takes more time for a differential backup. Every file changed since the last full backup is backed up every day, plus any new files created since the previous day's differential backup also get backed up. With an incremental backup, only those changed since the last full backup OR last incremental backup get backed up.

3d. Deciding between incremental and differential backups

The decision between incremental and differential backups is often based on the the length of time to do backups on a daily basis versus the length of time it will take to recover files at the time of reinstalling the files on a new disk drive (or reinstalling on an existing drive). If you create 10 new files each day and also modify 10 existing files daily (not the same as a recently created “new” file), then you do a backup daily, the amount of time required to perform the backups will vary by backup type.

With an incremental backup, each day, you'll backup up 20 files: the ten files that already existed and the ten new files created that day. With a differential backup, you'd back up the ten files that already existed, plus the ten new files from that day, the ten files from the previous day, the ten files from two days previous, the ten files from three days previous, … , etc.. With an incremental backup, it takes the same amount of time to back up the files from day to day. With a differential backup, it takes longer each day to do the day's backup.

When it comes time to restore files, the opposite condition exists. The full backup has to be restored, regardless of whether incremental or differential backups are done. Then the additional restorals are applied. For incremental backup sets, EVERY backup set must be applied because the most recent incremental backup only contains 20 files. On the other hand, with a differential backup, the full backup and ONLY the MOST RECENT differential backup set must be restored.

Both the incremental and differential backups require time to perform. The key is this: do you want to spend more time each day backing up your files, but less time if you have to do a restore, or do you want to spend less time daily, but spend more time when a restore operation is needed? That will determine which method you will use for daily (presumably) backups. Both are good. Both have advantages and disadvantages. If you need help figuring out which is

xcopy.txt · Last modified: 2018/08/09 11:15 by admin