[ Back to Table of Contents ]
[ << ]
[ >> ]
XXCOPY TECHNICAL BULLETIN #11
From: Kan Yabumoto tech@xxcopy.com
To: XXCOPY user
Subject: XXCOPY Cookbook: Recipes of common usages
Date: 2001-03-03
===============================================================================
A few examples are often more useful than pages of rigorous and
boring definitions and reference material.
--------------------------------------------------------------------
Select files that are made on or after February 1st, 2000.
XXCOPY c:\srcdir\ d:\dstdir\ /DA:2000-02-01
--------------------------------------------------------------------
Select files that are made before January 1st, 2000.
XXCOPY c:\srcdir\ d:\dstdir\ /DB:1999-12-31
Note: The date for /DA and /DB is inclusive of the date.
--------------------------------------------------------------------
Select files that are made today.
XXCOPY c:\src\ c:\temp\ /Do:. /S
Note: /DB:. selects files of yesterday or earlier
/DA:. selects files of today (and with future dates)
(see below for a variation)
--------------------------------------------------------------------
Select all the files in the entire volume which are made today
XXCOPY c:\ c:\temp\ /Do:. /S /CCY
Note: this is a case of cyclic copy situation where the
destination is a part of the source directory (the root),
which requires the /CC switch to avoid a recursive meltdown.
Here, /CCY (with the Y at the end) suppresses the warning
message for the case.
XXCOPY c:\ c:\temp\ /Do:. /SX /CCY
This variation (with /SX) creates a flat list of files
in the \temp directory. By substituting the subdirectory
delimiter character (backslash) by another character,
the files in the destination are easily examined.
--------------------------------------------------------------------
Select files that are modified (or newly created) today (or after).
XXCOPY c:\srcdir\ d:\dstdir\ /DA:.
XXCOPY c:\srcdir\ d:\dstdir\ /DA#.
XXCOPY c:\srcdir\ d:\dstdir\ /DA#0
All of the above will give you exactly the same result.
Note: the single dot "." is a shortcut for TODAY's date
when used with the "After" prefix.
Although in most system, you seldom find a file with a future
date, the operating system does not prohibit a program from
setting any legal time.
--------------------------------------------------------------------
Select files that are created today (or after).
XXCOPY c:\srcdir\ d:\dstdir\ /FC/DA:.
XXCOPY c:\srcdir\ d:\dstdir\ /FC/DA#.
XXCOPY c:\srcdir\ d:\dstdir\ /FC/DA#0
All of the above will give you exactly the same result.
Note: the single dot "." is a shortcut for TODAY's date
when used with the "After" prefix.
Although in most system, you seldom find files dates which
are "newer" than the current time, the operating system does
not prohibit a program from setting file time as such.
--------------------------------------------------------------------
Select files that are made within the past 45 minutes.
XXCOPY c:\src\ c:\temp\ /S /DA#30M
Note: /DA#30M The age parameter after /DA# (or /DB#) may be
appended with a suffix (D, H, M, or S for Days,
Variations:
/DA#10 10 days (Days if no suffix)
/DA#365D 365 days
/DA#90M 90 minutes (1 hr 30 min)
/DA#330S 330 seconds (5 min 30 sec).
/DB#36H 46 hours or before
--------------------------------------------------------------------
Select files that are made on or before yesterday.
XXCOPY c:\srcdir\ d:\dstdir\ /DB:.
XXCOPY c:\srcdir\ d:\dstdir\ /DB#.
XXCOPY c:\srcdir\ d:\dstdir\ /DB#1
All of the above will give you exactly the same result.
Note: the single dot "." is a shortcut for YESTERDAY's date
when used with the "Before" prefix.
Caution: The meaning of the dot "." character used in conjunction
with the "B(efore)" prefix is different from that with
the "A(fter)". That is because "On-or-Before-Today" is
hardly ever used and there is no use to designate a
special shortcut for it. On the other hand, the number
of days specified with the "#" prefix always counts the
days from today (which is designated by #0).
--------------------------------------------------------------------
Select files that are older than 30 days.
XXCOPY c:\srcdir\ d:\dstdir\ /DB#31
Note: /DB#30 would include the 30th day.
--------------------------------------------------------------------
Select files that are 30-60 days old.
XXCOPY c:\srcdir\ d:\dstdir\ /DB#30 /DA#60
--------------------------------------------------------------------
Select files that are *NOT* 30-60 days old.
XXCOPY c:\srcdir\ d:\dstdir\ /DA#29 /DB#61
--------------------------------------------------------------------
Select files that are 6-12 hours old.
XXCOPY c:\srcdir\ d:\dstdir\ /DB#6H /DA#12H
--------------------------------------------------------------------
Copy files and remove extra files in the destination
XXCOPY \src\ \dst\ /Z
The /Z switch remove all files in the destination whose
counterpart is not present in the source. In this most
primitive form, the /Z switch itself does not check whether
the remaining files are the same or not. But, in this
particular case, all files in the \src directory will be
copied to the \dst directory. If the file to be copied to
the destination is brand new (no file with the same name
exists in the destination), then the file will be copied
quietly. The file that exists in the destination will give
you a warning for overwrite (Yes/No/All). If you say No,
then, the old file will be left alone --- possibly causing
some mismatch in file. You may automate this command by
adding /Y which is equivalent of typing 'Y' to all prompts.
But, for each extra file to be deleted from the destination,
XXCOPY will give you another warning with Yes/No/All prompt.
XXCOPY \src\ \dst\ /Y /ZY
This variation suppresses the two types of warning prompts.
But, in order to make the two directories really the same,
a number of additional consideration must be made.
1. hidden and system files are not included in a normal copy.
2. subdirectories in the directory should be included.
3. you may want to preserve the file attributes exactly.
4. a read-only file in destination would prevent an overwrite.
So, you need a combination of more switches to really make
two directory the same (see below).
Caution:
The /CLONE, /Z, and /ZY switch performs deletion of extra
directories and files in the destination. If you inadvertently
specify a wrong destination, the consequence will be very
severe. Some careless users have lost many files by this!!!
--------------------------------------------------------------------
Variations in directory synchronization to F: (e.g., a Zip disk).
XXCOPY "C:\My Documents\" F:\ /KS/H/E/R/Q/Y/BI/ZY
This example is the standard way to duplicate the source
directory at the destination.
/KS Keeps the file attributes of the source exactly
/H Includes hidden and/or system files
/E Copies subdirectories including empty ones
/R Overwrites existing files that are read-only
/Q Suppresses display for skipped files
/Y Suppresses the Y/N/A prompt for a file overwrite
/BI Backs up incrementally (skips file with same size/time)
/ZY Deletes extra files in destination (without Y/N prompt)
Note that the first argument was surrounded by a pair of
double-quotes ("). This was necessitated by the presence of
embedded space (between My and Documents).
Caution:
The /CLONE, /Z, and /ZY switch performs deletion of extra
directories and files in the destination. If you inadvertently
specify a wrong destination, the consequence will be very
severe. Some careless users have lost many files by this!!!
XXCOPY "C:\My Documents\" F:\ /CLONE
The /CLONE switch is equivalent to typing the /KS/H/E/R/Q/Y/BI/ZY
combination.
XXCOPY "C:\My Documents\" F:\MYDOC /CLONE/I
XXCOPY "C:\My Documents\" F:\MYDOC\ /CLONE
These variations show the use of subdirectory in the destination.
The /I switch or the trailing backslash in the destination name
suppresses a possible Y/N prompt in case the destination
directory does not exist.
When you use a removable media (e.g., a diskette, or Zip disk),
you should just reverse the action on the target system.
XXCOPY F:\ "C:\My Documents\" /CLONE
In this example, any extra files that exists on the target
system will be deleted. If you do not want to delete any of
existing files (or directories), you should do the following:
XXCOPY F:\ "C:\My Documents\" /CLONE /Z0
The /Z0 switch after /CLONE will negate the /ZY switch which
is declared within the super /CLONE switch. This command
will leave any additional files and directory in the destination
untouched.
Note that if any opposing or mutually exclusive switches exist
on a command line, they are interpreted from left to right.
Therefore, if you place /Z0 before /CLONE, the effect of /Z0
will be lost.
--------------------------------------------------------------------
Cloning a DOS/Win9x drive to another
XXCOPY C:\ D:\ /CLONE
Cannot be simpler than this!!! The above section scrutinizes
exact meaning of /CLONE in terms of its true switch components.
This command is repeatable (first time, you run this command
in background while you continue using the system). While you
are running this command, you may type a Ctrl-C or Ctrl-Break
to abort the command. You can always run the exactly same
command to resume where you stopped the last time. While you
are running this command in the background, a number of files
may be created. No problem. When you are ready for the final
round, just stop all activities and just run the command once
more. It will quickly save the newly created file. Usually,
the virtual memory swap file (WIN386.SWP) cannot be accessed
when you run Win9x. For all practical purposes, this file
need not be duplicated in order to use the drive as the system
(bootable) drive. You need not format the hard disk as the
system disk prior to running this XXCOPY command. Nor you need
to run the SYS.COM command (to transfer the system files).
All hidden/system files necessary to boot the system will be
there.
Caution:
The /CLONE, /Z, and /ZY switch performs deletion of extra
directories and files in the destination. If you inadvertently
specify a wrong destination, the consequence will be very
severe. Some careless users have lost many files by this!!!
Note:
The only thing which may be missing from the newly cloned disk
is the Master Boot Record (MBR) which is not really a file.
The first logical sector (512 bytes) on the drive is called MBR
which must be initialized by FDISK (or by some third party
products). Keep a bootable diskette with FDISK.EXE handy.
After connecting the new drive as the first drive (FDISK
call the first drive DISK 1), reboot the system using the
bootable diskette, run FDISK and make the first Primary DOS
partition Active.
Note:
We do not recommend using XXCOPY16 to clone the entire drive.
(details are discussed the XXCOPY10.HTM article).
A complete discussion is found in another article (XXTB #10)
--------------------------------------------------------------------
Coping files from another computer on a network.
XXCOPY \\myserver\c\yourdocs\*.doc c:\mydocs\
This command copies all .DOC files (Microsoft's Word document)
from a computer named "myserver", drive named 'C'. directory
named \yourdocs\. The source name starting with two consecutive
backslashes are so-called UNC (Universal Naming Convention) name.
When a resource (such as a hard disk) is made sharable to other
users outside the computer, the resource must be given a name.
Usually Drive C is named just 'C' by convention (NetWare encouraged
the naming like "DRIVEC"). Therefore, the "root" of the remote
resource over the network will not be the computer name alone.
At the minimum, you need to specify the resource name for the
drive (such as \\myserver\c\" which will act as the root directory
of the volume). In this example, the source directory is locally
(on the computer) known as C:\dest\.
--------------------------------------------------------------------
Coping files to another computer on a network.
XXCOPY c:\mydir\*.doc \\myserver\c\dest\
The UNC path specifier can be used for the destination directory.
Caution: If the target resource is available on a read-only
basis, then, it cannot be made the destination of copy operation.
Some system allows you to access only on a read-only basis. In
that case, you can read the files but cannot write to the
directory, rename or, delete. Any modification of the contents
is considered a write-access.
Check with your network administrator for details.
--------------------------------------------------------------------
List up device driver files of certain date.
XXCOPY c:\Windows\*.DLL /S /L /DO:1999-04-23
The date shown here happens to be one of the Microsoft release
dates. The DLL files originally installed from the setup
CD-ROM will be listed by this command.
XXCOPY c:\Windows\system\*.DLL /L /DO:1999-04-23
This is a variation of the above, without /S so that the listing
is made only from the specified directory.
--------------------------------------------------------------------
Create a list of all files in the volume.
XXCOPY c:\ c:\mylist\ /H /E /TR0 /CCY /KN
This command creates a directory entry for each and every file
in the volume in the destination directory. The file contents
are not copied (using /TR0 to limit the new file to be 0 byte).
It effectively create a catalog of existing files. /CCY prevents
the cyclic copy meltdown. /H includes hidden files. /KN is an
optional switch to convert hidden/system files to visible file
for your convenience (you may drop this switch).
XXCOPY c:\ c:\mylist\ /KS /H /E /R /Q /Y /BX /ZY /TR0 /CCY
A variation to the one before. This command synchronizes the
file list created earlier by removing extra files (/ZY) and
adding those files that has different file time (/BX). Although
we could have chosen /KN as before. But, we chose to use a
different way to save the file attributes using /KS. It retains
the same file attributes as they are in the source directory
--- which in turn necessitates /R which is needed to overwrite
read-only files. Here, the /BX is a superior choice to /BB
because /BX rewrites the file which had a different file time
whereas /BB would skip the file which already exists --- leaving
files with old file time without being updated). /BX is better
than /BI (which checks both file time and file size). That's
because with /BI, the presence of /TR0 forces the file size to
be different (0 byte) for nearly all files, almost all files
would be rewritten.
Caution:
The /CLONE, /Z, and /ZY switch performs deletion of extra
directories and files in the destination. If you inadvertently
specify a wrong destination, the consequence will be very
severe. Some careless users have lost many files by this!!!
--------------------------------------------------------------------
Copy files and delete them from the source (i.e., move files).
XXCOPY \src\ \dst\ /RCY /S
The /RC switch stands for Remove-after-Copy. The Y suffix
suppresses the (Y/N/A) prompt on each file delete. To suppress
the (Y/N/A) prompt for file-overwrite cases, add /Y. /S goes
through subdirectories. Of course, you may add other common
switches such as /H (include hidden/system files), and
/R (overwrites even read-only files),
--------------------------------------------------------------------
Delete files which are present in the reference directory
XXCOPY c:\src\*.doc d:\reference\ /RS /U
The /RS switch removes files in the first (src) directory which
matches the template (*.doc). The /U switch specifies that the
delete operation will be performed on files that are present
in both the ssrc directory and the reference directory. To
understand the file selection mechanism, first consider this is
an ordinary file-copy operation. If so, the /U switch (which
stands for "update") selects files which exists on the
destination directory. The /RS switch changes the mode of
operation from file-copying to file-deletion. But, the file
selection mechanism is identical.
--------------------------------------------------------------------
Clean up the Windows temporary directory
XXCOPY %TEMP%\ /RS /DB#1 /R /H /PD0 /Y /ED
/RS Removes files in the source (the only) directory
/DB#1 Selects files made on or before yesterday
/R Deletes even a read-only file
/H Deletes even a hidden/system file
/PD0 Suppresses the prompt which would appear on a directory
/Y Suppresses the prompt prior to each file-delete
/ED Preserves the directory even if it becomes empty
In the standard Win9x system setup, the %TEMP% Environment
variable is set to the Windows designated temporary directory
(usually C:\Windows\temp).
By specifying the files that were made on yesterday or earlier,
this command will not accidentally delete files that may be
still in use in the current session (i.e., files created today).
--------------------------------------------------------------------
Treatments of redundant files
XXCOPY c:\src\*.doc d:\dst\ /BI /S
This command is a common case where incremental backup is
performed on a selected (*.doc) files in the source (and its
subdirectory). The /BI switch skips files that are already
present in the destination with the same file time and size.
That is, files which are different or the files that are
new to the destination will be copied.
XXCOPY c:\src\*.doc d:\dst\ /BS /S
This is a hypothetical command and such an operation is seldom
carried out. But, it helps understand what /BS does. /BS is a
strange switch for an ordinary copy operations. That is because
/BS (Backup Same) is exact opposite of /BI (Backup Incremental).
It selects and copies files that are identical in file date and
the size --- which results in no net change!!! The /BS is not
useful under normal circumstances (unless you want to exercise
the hard drive for testing purposes).
XXCOPY c:\src\*.doc d:\reference\ /RS /BS /S
The funny /BS switch now makes a lot of sense when combined
with /RS (remove files in source). Files which are present
in both the source and reference directories will be examined
with respect to the file time and file size.
Here, the files with the same file time and size which matches
the pattern (*.doc) in the source directory (/S specifies its
subdirectories) will be removed.
XXCOPY c:\src\*.doc d:\reference\ /RS /BS /S /L
The /L switch gives you a list of files which would be
selected by the duplicate-elimination operation.
XXCOPY c:\src\*.doc d:\reference\ /BS /S /L
For that matter, the presence of /RS makes no difference
because, /L has precedence over /RS. Therefore, the operation
becomes file-listing only.
--------------------------------------------------------------------
Eliminate redundant files (delete identical files)
XXCOPY c:\src\*.doc d:\reference\ /RS /BS /S
This is another RS variation. Again, two directories are
given (the second directory provides the reference files for
comparison). /BS is a strange switch for an ordinary copy
operations. That is because /BS (Backup Same) is exact opposite
of /BI (Backup Incremental). The BI switch compares a pair
of files between the source and destination and checks whether
the pair of files have the same file-time and size. If both
matches, the two files are considered to be the same and file
copy will be skipped. Being the exact opposite of /BI, the BS
switch would normally copy only identical files --- which
results in no net change!!! But, the file selection mechanism
makes a lot of sense when it is applied for file deletion.
Here, the files with the same file time and size which matches
the pattern (*.doc) in the source directory (/S specifies its
subdirectories) will be removed.
XXCOPY c:\src\*.doc d:\reference\ /RS /BS /S /L
The /L switch gives you a list of files which would be
selected by the duplicate-elimination operation.
XXCOPY c:\src\*.doc d:\reference\ /BS /S /L
For that matter, the presence of /RS makes no difference
because, /L has precedence over /RS. Therefore, the operation
becomes file-listing only.
--------------------------------------------------------------------
Remove files in all subdirectories but leave certain files.
XXCOPY c:\mydir\ /RMDIR /Y /Xtemplate.* /X*.doc
/RMDIR is like DELTREE. Here, /Y suppresses confirmation.
The two /X switches specify filename patterns to avoid
deletion.
--------------------------------------------------------------------
Three-way Differential Backup
The scheme works like this:
1. Initially you make a full backup from \src\ to \ref\.
2. Later, you want to perform a daily differential backup
from \src\ to \dst\ using the difference between \src\ and \ref.
The initial step is usually a full backup
XXCOPY \src\ \ref\ /CLONE
The daily differential backup requires three steps as follows
(for illustration purpose, common switches are deliberately left
out here).
XXCOPY \src\ /AZ
XXCOPY \src\ \ref\ /AA /BI
XXCOPY \src\ \dst\ /A
The first step clears the archive bit of every file in the source.
The second step sets the archive bit of the files you select.
The third step performs the actual file copy.
Very common cases (subdirectory included, hidden files also copied)
XXCOPY \src\ /AZ /S
XXCOPY \src\ \ref\ /AA /BI /S /H
XXCOPY \src\ \dst\ /A /S /H /KS
With a twist of incrementally do the three-way differential backup
to the same destination every day (remove extra files)
XXCOPY \src\ /AZ /S
XXCOPY \src\ \ref\ /AA /BI /S /H
XXCOPY \src\ \dst\ /A /S /H /KS /ZY
Caution:
The /CLONE, /Z, and /ZY switch performs deletion of extra
directories and files in the destination. If you inadvertently
specify a wrong destination, the consequence will be very
severe. Some careless users have lost many files by this!!!
--------------------------------------------------------------------
Differential Backup using a skeleton directory.
This scheme is similar to the Three-way differential backup
described above. In that case, the reference directory \ref\,
consumes a relatively large storage space just to provide the
reference (where the file contents are never referenced).
This variation drastically cuts down the storage usage by the
reference directory by storing only zero-length files. It
still allows you to compare filename and the file date as the
criteria for differential backup. In other words, the skeleton
directory serves as a file set specifier for regularly performed
backup.
The initial step here uses /TR0 to make zero-length files.
XXCOPY \src\ \ref\ /CLONE /TR0
You may remove whatever files you are not interested in
backing up (such as WIN386.SWP), thereafter in order to
make the most desired file set in the reference directory
The daily differential backup in this case uses /U to
(for illustration purpose, common switches are deliberately left
out here).
XXCOPY \src\ /AZ /S
XXCOPY \src\ \ref\ /AA /S /H /U /BX
XXCOPY \src\ \dst\ /A /S /H /KS
Note: the second step here uses /U (selects files that are
present in the reference directory) and /BX (exclude files
with the same file date).
Caution:
The /CLONE, /Z, and /ZY switch performs deletion of extra
directories and files in the destination. If you inadvertently
specify a wrong destination, the consequence will be very
severe. Some careless users have lost many files by this!!!
This page will remain forever under construction...
© Copyright 2016 Pixelab All rights reserved.