Merge branch 'vendor/SENDMAIL'
[dragonfly.git] / bin / cpdup / cpdup.1
1 .\" (c) Copyright 1997-2009 by Matthew Dillon and Dima Ruban.  Permission to
2 .\"    use and distribute based on the DragonFly copyright.  Supplied as-is,
3 .\"    USE WITH EXTREME CAUTION.
4 .\"
5 .Dd November 24, 2009
6 .Dt CPDUP 1
7 .Os
8 .Sh NAME
9 .Nm cpdup
10 .Nd mirror filesystems
11 .Sh SYNOPSIS
12 .Nm
13 .Op Fl C
14 .Op Fl v Ns Op Cm v Ns Op Cm v
15 .Op Fl d
16 .Op Fl u
17 .Op Fl I
18 .Op Fl f
19 .Op Fl F Ar ssh-arg
20 .Op Fl s0
21 .Op Fl i0
22 .Op Fl j0
23 .Op Fl l
24 .Op Fl q
25 .Op Fl o
26 .Op Fl m
27 .Op Fl H Ar path
28 .Op Fl M Ar file
29 .Op Fl V
30 .Op Fl S
31 .Op Fl k
32 .Op Fl K Ar file
33 .Op Fl X Ar file
34 .Op Fl x
35 .Oo Oo Ar user Ns Li @ Oc Ns Ar host : Oc Ns Ar source_dir
36 .Oo Oo Ar user Ns Li @ Oc Ns Ar host : Oc Ns Ar target_dir
37 .Sh DESCRIPTION
38 The
39 .Nm
40 utility makes an exact mirror copy of the source in the destination, creating
41 and deleting files and directories as necessary.  UTimes, hardlinks,
42 softlinks, devices, permissions, and flags are mirrored.  By default,
43 .Nm
44 asks for confirmation if any file or directory needs to be removed from
45 the destination and does not copy files which it believes to have already
46 been synchronized (by observing that the source and destination files' sizes
47 and mtimes match).
48 .Nm
49 does not cross mount points in either the source or the destination.
50 As a safety measure,
51 .Nm
52 refuses to replace a destination directory with a file.
53 .Pp
54 The following options are available:
55 .Bl -tag -width flag
56 .It Fl C
57 If the source or target is a remote host, request that the
58 .Xr ssh 1
59 session be compressed.
60 This is the same as
61 .Fl F
62 .Fl C .
63 .It Fl v Ns Op Cm v Ns Op Cm v
64 Set verboseness.  By default
65 .Nm
66 does not report its progress except when asking for confirmation.  A single
67 .Fl v
68 will only report modifications made to the destination.
69 .Fl vv
70 will report directories as they are being traversed as well as
71 modifications made to the destination.
72 .Fl vvv
73 will cause all files and directories to be reported whether or not
74 modifications are made.
75 .It Fl d
76 Print directories as they are being traversed.
77 Useful to watch the progress;
78 this typically produces much less output than
79 .Fl vv .
80 .It Fl u
81 Causes the output generated by
82 .Fl v
83 and
84 .Fl d
85 to be unbuffered.
86 This can be useful for obtaining prompt progress updates through a pipe.
87 .It Fl I
88 will cause
89 .Nm
90 to print a summary at the end with performance counters.
91 .It Fl f
92 Forces file updates to occur even if the files appear to be the same.  If
93 the
94 .Fl H
95 option is used, this option will force a byte for byte comparison
96 between the original file and the file in the hardlink path, even if
97 all the stat info matches, but will still use a hardlink if they match.
98 .It Fl F Ar ssh-arg
99 Pass
100 .Ar ssh-arg
101 to ssh.  For example
102 .Dq Fl F Fl p222 .
103 Note the lack of a space.
104 .It Fl s0
105 Disable the disallow-file-replaces-directory safety feature.  This
106 safety feature is enabled by default to prevent user mistakes from blowing
107 away everything accidentally.
108 .It Fl i0
109 Do not request confirmation when removing something.
110 .It Fl j0
111 Do not try to recreate CHR or BLK devices.
112 .It Fl l
113 Line buffer verbose output.
114 .It Fl q
115 Quiet operation.
116 .It Fl o
117 Do not remove any files, just overwrite/add.
118 .It Fl m
119 Generate and maintain a MD5 checkfile called
120 .Pa \&.MD5.CHECKSUMS
121 in each directory on the source
122 and do an MD5 check on each file of the destination when the destination
123 appears to be the same as the source.  If the check fails,
124 the source is recopied to the destination.  When you specify a destination
125 directory, the MD5 checkfile is only updated as needed and may not be updated
126 even if modifications are made to a source file.  If you do not specify a
127 destination directory the
128 .Nm
129 command forcefully regenerates the MD5 checkfile for every file in the source.
130 .It Fl M Ar file
131 Works the same as
132 .Fl m
133 but allows you to specify the name of the MD5 checkfile.
134 .It Fl H Ar path
135 .Nm
136 will create a hardlink from a file found under
137 .Ar path
138 to the target instead of copying the source to the target if the file found
139 via
140 .Ar path
141 is identical to the source.
142 Note that a remote host specification should not be used for this option's
143 .Ar path ,
144 but the
145 .Ar path
146 will be relative to the target machine.
147 .Pp
148 This allows one to use
149 .Nm
150 to create incremental backups of a filesystem.  Create a direct
151 .Sq level 0
152 backup, and then specify the level 0 backup path with this option when
153 creating an incremental backup to a different target directory.
154 This method works so long as the filesystem does not hit a hardlink limit.
155 If the system does hit a hardlink limit,
156 .Nm
157 will generate a warning and copy the file instead.
158 Note that
159 .Nm
160 must record file paths for any hardlinked file while operating and therefore
161 uses a great deal more memory when dealing with hardlinks or hardlink-based
162 backups.  Example use:
163 .Pp
164 .Dl cpdup \-i0 \-s0 \-I \-H /backup/home.l0 /home /backup/home.l1
165 .Pp
166 WARNING: If this option is used
167 .Nm
168 must record the paths for all files it encounters while it operates
169 and it is possible that you may run the process out of memory.
170 .Pp
171 The file found via the hardlink path will be byte-by-byte compared with the
172 source if the
173 .Fl V
174 or
175 .Fl f
176 option is also used, otherwise only the stat info is checked to determine
177 whether it matches the source.
178 .It Fl V
179 This forces the contents of regular files to be verified, even if the
180 files appear to the be the same.  Whereas the
181 .Fl f
182 (force) option forces a copy regardless, this option will avoid rewriting
183 the target if everything matches and the contents are verified to be the
184 same.
185 .It Fl S
186 This places
187 .Nm
188 into slave mode and is used to initiate the slave protocol on a remote
189 machine.
190 .It Fl k
191 Generate and maintain a FSMID checkfile called
192 .Pa \& .FSMID.CHECK
193 in each directory on the target.
194 .Nm
195 will check the FSMID for each source file or directory against the checkfile
196 on the target and will not copy the file or recurse through the directory
197 when a match occurs.  Any source file or directory with the same name as the
198 checkfile will be ignored.  The FSMID will be re-checked after the copy
199 has been completed and
200 .Nm
201 will loop on that directory or file until it is sure it has an exact copy.
202 .Pp
203 Warning: FSMID is not always supported by a filesystem and may not be
204 synchronized if a crash occurs.
205 .Dx
206 will simulate an FSMID when
207 it is otherwise not supported by the filesystem, and users should be aware
208 that simulated FSMIDs may change state in such cases even if the underlying
209 hierarchy does not due to cache flushes.
210 Additionally, the FSMID may not reflect changes made to remote filesystems
211 by other hosts.  For example, using these options with NFS mounted sources
212 will not work well.
213 .It Fl K Ar file
214 Works the same as
215 .Fl k
216 but allows you to specify the name of the FSMID checkfile.
217 .It Fl x
218 Causes
219 .Nm
220 to use the exclusion file
221 .Pa \&.cpignore
222 in each directory on the source to
223 determine which files to ignore.  When this option is used, the exclusion
224 filename itself is automatically excluded from the copy.  If this option is
225 not used then the filename
226 .Pa \&.cpignore
227 is not considered special and will
228 be copied along with everything else.
229 .It Fl X Ar file
230 Works the same as
231 .Fl x
232 but allows you to specify the name of the exclusion file.  This file is
233 automatically excluded from the copy.  Only one exclusion file may be
234 specified.
235 .El
236 .Sh REMOTE COPYING
237 .Nm
238 can mirror directory structures across machines and can also do third-party
239 copies.
240 .Xr ssh 1
241 sessions are used and
242 .Nm
243 is run on the remote machine(s) in slave mode.
244 You can use the
245 .Fl F
246 option to pass additional flags to the ssh command if necessary.
247 .Pp
248 The syntax of remote path specifications is similar to
249 .Xr scp 1 .
250 In particular, that means that a local path containing a colon must
251 be preceded by a slash to prevent it being considered a remote host:
252 .Ql foo:bar
253 causes
254 .Nm
255 to look for a directory called
256 .Ql bar
257 on host
258 .Ql foo ,
259 while
260 .Ql \&./foo:bar
261 denotes the directory
262 .Ql foo:bar
263 on the local machine.
264 .Sh DIAGNOSTICS
265 The
266 .Nm
267 utility exits 0 if no error occurred and >0 if an error occurred.
268 .Sh SEE ALSO
269 .Xr cp 1 ,
270 .Xr cpio 1 ,
271 .Xr ssh 1 ,
272 .Xr scp 1 ,
273 .Xr tar 1
274 .Sh HISTORY
275 The
276 .Nm
277 command was originally created to update servers at BEST Internet circa 1997
278 and was placed under the
279 .Fx
280 copyright for inclusion in the ports area in 1999.
281 The program was written by Matthew Dillon and Dima Ruban.
282 .Sh BUGS
283 .Xr UFS 5
284 has a hardlink limit of 32767.  Many programs, in particular CVS
285 with regards to its CVS/Root file, will generate a lot of hard links.
286 When using the
287 .Fl H
288 option it may not be possible for
289 .Nm
290 to maintain these hard links.  If this occurs,
291 .Nm
292 will be forced to copy the file instead of link it, and thus not be able
293 to make a perfect copy of the filesystem.
294 .Pp
295 Currently the remote protocol uses host byte order.  Therefore,
296 .Nm
297 cannot talk to machines that use a byte order
298 different from the local machine.
299 .Pp
300 When so-called sparse files (i.e. files with "holes") are copied,
301 the holes will be filled in the target files, so they occupy
302 more physical disk space than the source files.