18f0e7bc1SMatthew Dillon.\" (c) Copyright 1997-2009 by Matthew Dillon and Dima Ruban. Permission to 23a42736dSMatthew Dillon.\" use and distribute based on the DragonFly copyright. Supplied as-is, 33a42736dSMatthew Dillon.\" USE WITH EXTREME CAUTION. 43a42736dSMatthew Dillon.\" 58f0e7bc1SMatthew Dillon.Dd November 24, 2009 63a42736dSMatthew Dillon.Dt CPDUP 1 7b28a9db4SSascha Wildner.Os 83a42736dSMatthew Dillon.Sh NAME 93a42736dSMatthew Dillon.Nm cpdup 103a42736dSMatthew Dillon.Nd mirror filesystems 113a42736dSMatthew Dillon.Sh SYNOPSIS 1297983c9eSSascha Wildner.Nm 1344dd1628SMatthew Dillon.Op Fl C 14293141b7SMatthew Dillon.Op Fl v Ns Op Cm v Ns Op Cm v 15293141b7SMatthew Dillon.Op Fl d 164d2076d3SChris Pressey.Op Fl u 173a42736dSMatthew Dillon.Op Fl I 183a42736dSMatthew Dillon.Op Fl f 19293141b7SMatthew Dillon.Op Fl F Ar ssh-arg 203a42736dSMatthew Dillon.Op Fl s0 213a42736dSMatthew Dillon.Op Fl i0 22ac482a7eSMatthew Dillon.Op Fl j0 23b130721cSSascha Wildner.Op Fl l 243a42736dSMatthew Dillon.Op Fl q 253a42736dSMatthew Dillon.Op Fl o 263a42736dSMatthew Dillon.Op Fl m 27293141b7SMatthew Dillon.Op Fl H Ar path 28293141b7SMatthew Dillon.Op Fl M Ar file 29d5fdcd00SMatthew Dillon.Op Fl V 30*1bcaecdaSMatthew Dillon.Op Fl VV 314d858d58SMatthew Dillon.Op Fl S 32577109eaSMatthew Dillon.Op Fl k 33293141b7SMatthew Dillon.Op Fl K Ar file 34293141b7SMatthew Dillon.Op Fl X Ar file 35c0d18d1dSMatthew Dillon.Op Fl x 36293141b7SMatthew Dillon.Oo Oo Ar user Ns Li @ Oc Ns Ar host : Oc Ns Ar source_dir 37293141b7SMatthew Dillon.Oo Oo Ar user Ns Li @ Oc Ns Ar host : Oc Ns Ar target_dir 383a42736dSMatthew Dillon.Sh DESCRIPTION 393a42736dSMatthew DillonThe 403a42736dSMatthew Dillon.Nm 413a42736dSMatthew Dillonutility makes an exact mirror copy of the source in the destination, creating 423a42736dSMatthew Dillonand deleting files and directories as necessary. UTimes, hardlinks, 433a42736dSMatthew Dillonsoftlinks, devices, permissions, and flags are mirrored. By default, 443a42736dSMatthew Dillon.Nm 453a42736dSMatthew Dillonasks for confirmation if any file or directory needs to be removed from 463a42736dSMatthew Dillonthe destination and does not copy files which it believes to have already 47293141b7SMatthew Dillonbeen synchronized (by observing that the source and destination files' sizes 483a42736dSMatthew Dillonand mtimes match). 493a42736dSMatthew Dillon.Nm 5073afa964SChris Presseydoes not cross mount points in either the source or the destination. 5173afa964SChris PresseyAs a safety measure, 523a42736dSMatthew Dillon.Nm 533a42736dSMatthew Dillonrefuses to replace a destination directory with a file. 543a42736dSMatthew Dillon.Pp 553a42736dSMatthew DillonThe following options are available: 563a42736dSMatthew Dillon.Bl -tag -width flag 5744dd1628SMatthew Dillon.It Fl C 58293141b7SMatthew DillonIf the source or target is a remote host, request that the 5944dd1628SMatthew Dillon.Xr ssh 1 6044dd1628SMatthew Dillonsession be compressed. 61293141b7SMatthew DillonThis is the same as 62293141b7SMatthew Dillon.Fl F 63293141b7SMatthew Dillon.Fl C . 64293141b7SMatthew Dillon.It Fl v Ns Op Cm v Ns Op Cm v 653a42736dSMatthew DillonSet verboseness. By default 663a42736dSMatthew Dillon.Nm 673a42736dSMatthew Dillondoes not report its progress except when asking for confirmation. A single 683a42736dSMatthew Dillon.Fl v 693a42736dSMatthew Dillonwill only report modifications made to the destination. 703a42736dSMatthew Dillon.Fl vv 713a42736dSMatthew Dillonwill report directories as they are being traversed as well as 723a42736dSMatthew Dillonmodifications made to the destination. 733a42736dSMatthew Dillon.Fl vvv 743a42736dSMatthew Dillonwill cause all files and directories to be reported whether or not 753a42736dSMatthew Dillonmodifications are made. 76293141b7SMatthew Dillon.It Fl d 77293141b7SMatthew DillonPrint directories as they are being traversed. 78293141b7SMatthew DillonUseful to watch the progress; 79293141b7SMatthew Dillonthis typically produces much less output than 80293141b7SMatthew Dillon.Fl vv . 814d2076d3SChris Pressey.It Fl u 82293141b7SMatthew DillonCauses the output generated by 83293141b7SMatthew Dillon.Fl v 84293141b7SMatthew Dillonand 85293141b7SMatthew Dillon.Fl d 864d2076d3SChris Presseyto be unbuffered. 874d2076d3SChris PresseyThis can be useful for obtaining prompt progress updates through a pipe. 883a42736dSMatthew Dillon.It Fl I 89b5203c54SSascha Wildnerwill cause 90b5203c54SSascha Wildner.Nm 91293141b7SMatthew Dillonto print a summary at the end with performance counters. 923a42736dSMatthew Dillon.It Fl f 934e316ad5SMatthew DillonForces file updates to occur even if the files appear to be the same. If 944e316ad5SMatthew Dillonthe 954e316ad5SMatthew Dillon.Fl H 966db8f15dSMatthew Dillonoption is used, this option will force a byte for byte comparison 974e316ad5SMatthew Dillonbetween the original file and the file in the hardlink path, even if 984e316ad5SMatthew Dillonall the stat info matches, but will still use a hardlink if they match. 99293141b7SMatthew Dillon.It Fl F Ar ssh-arg 100293141b7SMatthew DillonPass 101293141b7SMatthew Dillon.Ar ssh-arg 102293141b7SMatthew Dillonto ssh. For example 103293141b7SMatthew Dillon.Dq Fl F Fl p222 . 104293141b7SMatthew DillonNote the lack of a space. 1053a42736dSMatthew Dillon.It Fl s0 1063a42736dSMatthew DillonDisable the disallow-file-replaces-directory safety feature. This 1073a42736dSMatthew Dillonsafety feature is enabled by default to prevent user mistakes from blowing 108163ffa07SSascha Wildneraway everything accidentally. 1093a42736dSMatthew Dillon.It Fl i0 1103a42736dSMatthew DillonDo not request confirmation when removing something. 111ac482a7eSMatthew Dillon.It Fl j0 112ac482a7eSMatthew DillonDo not try to recreate CHR or BLK devices. 113a2dc574cSMatthew Dillon.It Fl l 114a2dc574cSMatthew DillonLine buffer verbose output. 1153a42736dSMatthew Dillon.It Fl q 116293141b7SMatthew DillonQuiet operation. 1173a42736dSMatthew Dillon.It Fl o 1183a42736dSMatthew DillonDo not remove any files, just overwrite/add. 1193a42736dSMatthew Dillon.It Fl m 120293141b7SMatthew DillonGenerate and maintain a MD5 checkfile called 121293141b7SMatthew Dillon.Pa \&.MD5.CHECKSUMS 122293141b7SMatthew Dillonin each directory on the source 1233a42736dSMatthew Dillonand do an MD5 check on each file of the destination when the destination 1243a42736dSMatthew Dillonappears to be the same as the source. If the check fails, 1253a42736dSMatthew Dillonthe source is recopied to the destination. When you specify a destination 126293141b7SMatthew Dillondirectory, the MD5 checkfile is only updated as needed and may not be updated 1273a42736dSMatthew Dilloneven if modifications are made to a source file. If you do not specify a 1283a42736dSMatthew Dillondestination directory the 1293a42736dSMatthew Dillon.Nm 1303a42736dSMatthew Dilloncommand forcefully regenerates the MD5 checkfile for every file in the source. 131293141b7SMatthew Dillon.It Fl M Ar file 132293141b7SMatthew DillonWorks the same as 133293141b7SMatthew Dillon.Fl m 134293141b7SMatthew Dillonbut allows you to specify the name of the MD5 checkfile. 1354e316ad5SMatthew Dillon.It Fl H Ar path 136b5203c54SSascha Wildner.Nm 137b5203c54SSascha Wildnerwill create a hardlink from a file found under 1384e316ad5SMatthew Dillon.Ar path 1394e316ad5SMatthew Dillonto the target instead of copying the source to the target if the file found 1404e316ad5SMatthew Dillonvia 1414e316ad5SMatthew Dillon.Ar path 1424d858d58SMatthew Dillonis identical to the source. 143d5fdcd00SMatthew DillonNote that a remote host specification should not be used for this option's 144293141b7SMatthew Dillon.Ar path , 145293141b7SMatthew Dillonbut the 146293141b7SMatthew Dillon.Ar path 147293141b7SMatthew Dillonwill be relative to the target machine. 1484d858d58SMatthew Dillon.Pp 1494d858d58SMatthew DillonThis allows one to use 1504e316ad5SMatthew Dillon.Nm 151293141b7SMatthew Dillonto create incremental backups of a filesystem. Create a direct 152293141b7SMatthew Dillon.Sq level 0 1534e316ad5SMatthew Dillonbackup, and then specify the level 0 backup path with this option when 1549b2d9484SMatthew Dilloncreating an incremental backup to a different target directory. 1559b2d9484SMatthew DillonThis method works so long as the filesystem does not hit a hardlink limit. 156293141b7SMatthew DillonIf the system does hit a hardlink limit, 1579b2d9484SMatthew Dillon.Nm 1589b2d9484SMatthew Dillonwill generate a warning and copy the file instead. 1599b2d9484SMatthew DillonNote that 1604e316ad5SMatthew Dillon.Nm 1614e316ad5SMatthew Dillonmust record file paths for any hardlinked file while operating and therefore 1624e316ad5SMatthew Dillonuses a great deal more memory when dealing with hardlinks or hardlink-based 1634e316ad5SMatthew Dillonbackups. Example use: 1644e316ad5SMatthew Dillon.Pp 165293141b7SMatthew Dillon.Dl cpdup \-i0 \-s0 \-I \-H /backup/home.l0 /home /backup/home.l1 1664e316ad5SMatthew Dillon.Pp 1674e316ad5SMatthew DillonWARNING: If this option is used 1684e316ad5SMatthew Dillon.Nm 1694e316ad5SMatthew Dillonmust record the paths for all files it encounters while it operates 1704e316ad5SMatthew Dillonand it is possible that you may run the process out of memory. 171d5fdcd00SMatthew Dillon.Pp 1728084e06aSPeter AvalosThe file found via the hardlink path will be byte-by-byte compared with the 173d5fdcd00SMatthew Dillonsource if the 174d5fdcd00SMatthew Dillon.Fl V 175d5fdcd00SMatthew Dillonor 176d5fdcd00SMatthew Dillon.Fl f 177d5fdcd00SMatthew Dillonoption is also used, otherwise only the stat info is checked to determine 178d5fdcd00SMatthew Dillonwhether it matches the source. 179d5fdcd00SMatthew Dillon.It Fl V 180d5fdcd00SMatthew DillonThis forces the contents of regular files to be verified, even if the 181d5fdcd00SMatthew Dillonfiles appear to the be the same. Whereas the 182d5fdcd00SMatthew Dillon.Fl f 183d5fdcd00SMatthew Dillon(force) option forces a copy regardless, this option will avoid rewriting 184d5fdcd00SMatthew Dillonthe target if everything matches and the contents are verified to be the 185d5fdcd00SMatthew Dillonsame. 186*1bcaecdaSMatthew Dillon.It Fl VV 187*1bcaecdaSMatthew DillonThis works the same as 188*1bcaecdaSMatthew Dillon.Fl V 189*1bcaecdaSMatthew Dillonbut ignores mtime entirely, making it suitable for comparing HAMMER 190*1bcaecdaSMatthew Dillonmaster and slave filesystems or copies made without mtime retention. 1914d858d58SMatthew Dillon.It Fl S 1924d858d58SMatthew DillonThis places 1934d858d58SMatthew Dillon.Nm 1944d858d58SMatthew Dilloninto slave mode and is used to initiate the slave protocol on a remote 1954d858d58SMatthew Dillonmachine. 196577109eaSMatthew Dillon.It Fl k 197293141b7SMatthew DillonGenerate and maintain a FSMID checkfile called 198293141b7SMatthew Dillon.Pa \& .FSMID.CHECK 199293141b7SMatthew Dillonin each directory on the target. 200577109eaSMatthew Dillon.Nm 201577109eaSMatthew Dillonwill check the FSMID for each source file or directory against the checkfile 202577109eaSMatthew Dillonon the target and will not copy the file or recurse through the directory 203577109eaSMatthew Dillonwhen a match occurs. Any source file or directory with the same name as the 204577109eaSMatthew Dilloncheckfile will be ignored. The FSMID will be re-checked after the copy 205577109eaSMatthew Dillonhas been completed and 206577109eaSMatthew Dillon.Nm 207577109eaSMatthew Dillonwill loop on that directory or file until it is sure it has an exact copy. 208577109eaSMatthew Dillon.Pp 209577109eaSMatthew DillonWarning: FSMID is not always supported by a filesystem and may not be 2101df089c8SSascha Wildnersynchronized if a crash occurs. 2111df089c8SSascha Wildner.Dx 2121df089c8SSascha Wildnerwill simulate an FSMID when 213577109eaSMatthew Dillonit is otherwise not supported by the filesystem, and users should be aware 214577109eaSMatthew Dillonthat simulated FSMIDs may change state in such cases even if the underlying 215577109eaSMatthew Dillonhierarchy does not due to cache flushes. 216577109eaSMatthew DillonAdditionally, the FSMID may not reflect changes made to remote filesystems 217577109eaSMatthew Dillonby other hosts. For example, using these options with NFS mounted sources 218577109eaSMatthew Dillonwill not work well. 219577109eaSMatthew Dillon.It Fl K Ar file 220577109eaSMatthew DillonWorks the same as 221577109eaSMatthew Dillon.Fl k 222577109eaSMatthew Dillonbut allows you to specify the name of the FSMID checkfile. 2233a42736dSMatthew Dillon.It Fl x 2243a42736dSMatthew DillonCauses 2253a42736dSMatthew Dillon.Nm 226293141b7SMatthew Dillonto use the exclusion file 227293141b7SMatthew Dillon.Pa \&.cpignore 228293141b7SMatthew Dillonin each directory on the source to 2293a42736dSMatthew Dillondetermine which files to ignore. When this option is used, the exclusion 2303a42736dSMatthew Dillonfilename itself is automatically excluded from the copy. If this option is 231293141b7SMatthew Dillonnot used then the filename 232293141b7SMatthew Dillon.Pa \&.cpignore 233293141b7SMatthew Dillonis not considered special and will 2343a42736dSMatthew Dillonbe copied along with everything else. 235577109eaSMatthew Dillon.It Fl X Ar file 2363a42736dSMatthew DillonWorks the same as 2373a42736dSMatthew Dillon.Fl x 2383a42736dSMatthew Dillonbut allows you to specify the name of the exclusion file. This file is 2393a42736dSMatthew Dillonautomatically excluded from the copy. Only one exclusion file may be 2403a42736dSMatthew Dillonspecified. 24152ac7bd7SHiten Pandya.El 2424d858d58SMatthew Dillon.Sh REMOTE COPYING 2434d858d58SMatthew Dillon.Nm 2444d858d58SMatthew Dilloncan mirror directory structures across machines and can also do third-party 2454d858d58SMatthew Dilloncopies. 2464d858d58SMatthew Dillon.Xr ssh 1 2474d858d58SMatthew Dillonsessions are used and 2484d858d58SMatthew Dillon.Nm 2494d858d58SMatthew Dillonis run on the remote machine(s) in slave mode. 250293141b7SMatthew DillonYou can use the 251293141b7SMatthew Dillon.Fl F 252293141b7SMatthew Dillonoption to pass additional flags to the ssh command if necessary. 253293141b7SMatthew Dillon.Pp 254293141b7SMatthew DillonThe syntax of remote path specifications is similar to 255293141b7SMatthew Dillon.Xr scp 1 . 256293141b7SMatthew DillonIn particular, that means that a local path containing a colon must 257293141b7SMatthew Dillonbe preceded by a slash to prevent it being considered a remote host: 258293141b7SMatthew Dillon.Ql foo:bar 259293141b7SMatthew Dilloncauses 260293141b7SMatthew Dillon.Nm 261293141b7SMatthew Dillonto look for a directory called 262293141b7SMatthew Dillon.Ql bar 263293141b7SMatthew Dillonon host 264293141b7SMatthew Dillon.Ql foo , 265293141b7SMatthew Dillonwhile 266293141b7SMatthew Dillon.Ql \&./foo:bar 267293141b7SMatthew Dillondenotes the directory 268293141b7SMatthew Dillon.Ql foo:bar 269293141b7SMatthew Dillonon the local machine. 2703a42736dSMatthew Dillon.Sh DIAGNOSTICS 2713a42736dSMatthew DillonThe 2723a42736dSMatthew Dillon.Nm 2733f625015SSascha Wildnerutility exits 0 if no error occurred and >0 if an error occurred. 2743a42736dSMatthew Dillon.Sh SEE ALSO 2753a42736dSMatthew Dillon.Xr cp 1 , 2763a42736dSMatthew Dillon.Xr cpio 1 , 277293141b7SMatthew Dillon.Xr ssh 1 , 278293141b7SMatthew Dillon.Xr scp 1 , 2792653401fSChris Pressey.Xr tar 1 280de023c90SSascha Wildner.Sh HISTORY 281de023c90SSascha WildnerThe 282de023c90SSascha Wildner.Nm 283aa4f0cadSSascha Wildnercommand was originally created to update servers at BEST Internet circa 1997 284b5ac91c1SSascha Wildnerand was placed under the 285b5ac91c1SSascha Wildner.Fx 286b5ac91c1SSascha Wildnercopyright for inclusion in the ports area in 1999. 287b5ac91c1SSascha WildnerThe program was written by Matthew Dillon and Dima Ruban. 2889b2d9484SMatthew Dillon.Sh BUGS 289167c1ad2SSascha Wildner.Xr UFS 5 290167c1ad2SSascha Wildnerhas a hardlink limit of 32767. Many programs, in particular CVS 2919b2d9484SMatthew Dillonwith regards to its CVS/Root file, will generate a lot of hard links. 2929b2d9484SMatthew DillonWhen using the 2939b2d9484SMatthew Dillon.Fl H 2949b2d9484SMatthew Dillonoption it may not be possible for 2959b2d9484SMatthew Dillon.Nm 296293141b7SMatthew Dillonto maintain these hard links. If this occurs, 2979b2d9484SMatthew Dillon.Nm 2989b2d9484SMatthew Dillonwill be forced to copy the file instead of link it, and thus not be able 2999b2d9484SMatthew Dillonto make a perfect copy of the filesystem. 300293141b7SMatthew Dillon.Pp 301293141b7SMatthew DillonCurrently the remote protocol uses host byte order. Therefore, 302293141b7SMatthew Dillon.Nm 303293141b7SMatthew Dilloncannot talk to machines that use a byte order 304293141b7SMatthew Dillondifferent from the local machine. 305293141b7SMatthew Dillon.Pp 306293141b7SMatthew DillonWhen so-called sparse files (i.e. files with "holes") are copied, 307293141b7SMatthew Dillonthe holes will be filled in the target files, so they occupy 308293141b7SMatthew Dillonmore physical disk space than the source files. 309