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