1ca097fa5SMatthew Dillon.\" (c) Copyright 1997-2010 by Matthew Dillon, Dima Ruban, and Oliver Fromme. 2ca097fa5SMatthew Dillon.\" Permission to use and distribute based on the DragonFly copyright. 3ca097fa5SMatthew Dillon.\" Supplied as-is, USE WITH CAUTION. 43a42736dSMatthew Dillon.\" 5*5ca0a96dSSascha Wildner.Dd December 28, 2020 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 16698d0b11SMatthew Dillon.Op Fl n 174d2076d3SChris Pressey.Op Fl u 183a42736dSMatthew Dillon.Op Fl I 193a42736dSMatthew Dillon.Op Fl f 20293141b7SMatthew Dillon.Op Fl F Ar ssh-arg 213a42736dSMatthew Dillon.Op Fl s0 223a42736dSMatthew Dillon.Op Fl i0 23ac482a7eSMatthew Dillon.Op Fl j0 24b130721cSSascha Wildner.Op Fl l 253a42736dSMatthew Dillon.Op Fl q 263a42736dSMatthew Dillon.Op Fl o 273a42736dSMatthew Dillon.Op Fl m 28293141b7SMatthew Dillon.Op Fl H Ar path 29293141b7SMatthew Dillon.Op Fl M Ar file 30d5fdcd00SMatthew Dillon.Op Fl V 311bcaecdaSMatthew Dillon.Op Fl VV 324d858d58SMatthew Dillon.Op Fl S 33c0538630SMatthew Dillon.Op Fl R 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 . 81698d0b11SMatthew Dillon.It Fl n 82698d0b11SMatthew DillonGo through the motions but don't actually make any changes to 83698d0b11SMatthew Dillonthe target. 844d2076d3SChris Pressey.It Fl u 85293141b7SMatthew DillonCauses the output generated by 86293141b7SMatthew Dillon.Fl v 87293141b7SMatthew Dillonand 88293141b7SMatthew Dillon.Fl d 894d2076d3SChris Presseyto be unbuffered. 904d2076d3SChris PresseyThis can be useful for obtaining prompt progress updates through a pipe. 913a42736dSMatthew Dillon.It Fl I 92b5203c54SSascha Wildnerwill cause 93b5203c54SSascha Wildner.Nm 94293141b7SMatthew Dillonto print a summary at the end with performance counters. 953a42736dSMatthew Dillon.It Fl f 964e316ad5SMatthew DillonForces file updates to occur even if the files appear to be the same. If 974e316ad5SMatthew Dillonthe 984e316ad5SMatthew Dillon.Fl H 996db8f15dSMatthew Dillonoption is used, this option will force a byte for byte comparison 1004e316ad5SMatthew Dillonbetween the original file and the file in the hardlink path, even if 1014e316ad5SMatthew Dillonall the stat info matches, but will still use a hardlink if they match. 102293141b7SMatthew Dillon.It Fl F Ar ssh-arg 103293141b7SMatthew DillonPass 104293141b7SMatthew Dillon.Ar ssh-arg 105293141b7SMatthew Dillonto ssh. For example 106293141b7SMatthew Dillon.Dq Fl F Fl p222 . 107293141b7SMatthew DillonNote the lack of a space. 1083a42736dSMatthew Dillon.It Fl s0 1093a42736dSMatthew DillonDisable the disallow-file-replaces-directory safety feature. This 1103a42736dSMatthew Dillonsafety feature is enabled by default to prevent user mistakes from blowing 111163ffa07SSascha Wildneraway everything accidentally. 1123a42736dSMatthew Dillon.It Fl i0 1133a42736dSMatthew DillonDo not request confirmation when removing something. 114ac482a7eSMatthew Dillon.It Fl j0 115ac482a7eSMatthew DillonDo not try to recreate CHR or BLK devices. 116a2dc574cSMatthew Dillon.It Fl l 117a2dc574cSMatthew DillonLine buffer verbose output. 1183a42736dSMatthew Dillon.It Fl q 119293141b7SMatthew DillonQuiet operation. 1203a42736dSMatthew Dillon.It Fl o 1213a42736dSMatthew DillonDo not remove any files, just overwrite/add. 1223a42736dSMatthew Dillon.It Fl m 123293141b7SMatthew DillonGenerate and maintain a MD5 checkfile called 124293141b7SMatthew Dillon.Pa \&.MD5.CHECKSUMS 125293141b7SMatthew Dillonin each directory on the source 1263a42736dSMatthew Dillonand do an MD5 check on each file of the destination when the destination 1273a42736dSMatthew Dillonappears to be the same as the source. If the check fails, 1283a42736dSMatthew Dillonthe source is recopied to the destination. When you specify a destination 129293141b7SMatthew Dillondirectory, the MD5 checkfile is only updated as needed and may not be updated 1303a42736dSMatthew Dilloneven if modifications are made to a source file. If you do not specify a 1313a42736dSMatthew Dillondestination directory the 1323a42736dSMatthew Dillon.Nm 1333a42736dSMatthew Dilloncommand forcefully regenerates the MD5 checkfile for every file in the source. 134293141b7SMatthew Dillon.It Fl M Ar file 135293141b7SMatthew DillonWorks the same as 136293141b7SMatthew Dillon.Fl m 137293141b7SMatthew Dillonbut allows you to specify the name of the MD5 checkfile. 1384e316ad5SMatthew Dillon.It Fl H Ar path 139b5203c54SSascha Wildner.Nm 140b5203c54SSascha Wildnerwill create a hardlink from a file found under 1414e316ad5SMatthew Dillon.Ar path 1424e316ad5SMatthew Dillonto the target instead of copying the source to the target if the file found 1434e316ad5SMatthew Dillonvia 1444e316ad5SMatthew Dillon.Ar path 1454d858d58SMatthew Dillonis identical to the source. 146d5fdcd00SMatthew DillonNote that a remote host specification should not be used for this option's 147293141b7SMatthew Dillon.Ar path , 148293141b7SMatthew Dillonbut the 149293141b7SMatthew Dillon.Ar path 150293141b7SMatthew Dillonwill be relative to the target machine. 1514d858d58SMatthew Dillon.Pp 1524d858d58SMatthew DillonThis allows one to use 1534e316ad5SMatthew Dillon.Nm 154293141b7SMatthew Dillonto create incremental backups of a filesystem. Create a direct 155293141b7SMatthew Dillon.Sq level 0 1564e316ad5SMatthew Dillonbackup, and then specify the level 0 backup path with this option when 1579b2d9484SMatthew Dilloncreating an incremental backup to a different target directory. 1589b2d9484SMatthew DillonThis method works so long as the filesystem does not hit a hardlink limit. 159293141b7SMatthew DillonIf the system does hit a hardlink limit, 1609b2d9484SMatthew Dillon.Nm 1619b2d9484SMatthew Dillonwill generate a warning and copy the file instead. 1629b2d9484SMatthew DillonNote that 1634e316ad5SMatthew Dillon.Nm 1644e316ad5SMatthew Dillonmust record file paths for any hardlinked file while operating and therefore 1654e316ad5SMatthew Dillonuses a great deal more memory when dealing with hardlinks or hardlink-based 1664e316ad5SMatthew Dillonbackups. Example use: 1674e316ad5SMatthew Dillon.Pp 168293141b7SMatthew Dillon.Dl cpdup \-i0 \-s0 \-I \-H /backup/home.l0 /home /backup/home.l1 1694e316ad5SMatthew Dillon.Pp 1704e316ad5SMatthew DillonWARNING: If this option is used 1714e316ad5SMatthew Dillon.Nm 1724e316ad5SMatthew Dillonmust record the paths for all files it encounters while it operates 1734e316ad5SMatthew Dillonand it is possible that you may run the process out of memory. 174d5fdcd00SMatthew Dillon.Pp 1758084e06aSPeter AvalosThe file found via the hardlink path will be byte-by-byte compared with the 176d5fdcd00SMatthew Dillonsource if the 177d5fdcd00SMatthew Dillon.Fl V 178d5fdcd00SMatthew Dillonor 179d5fdcd00SMatthew Dillon.Fl f 180d5fdcd00SMatthew Dillonoption is also used, otherwise only the stat info is checked to determine 181d5fdcd00SMatthew Dillonwhether it matches the source. 182d5fdcd00SMatthew Dillon.It Fl V 183d5fdcd00SMatthew DillonThis forces the contents of regular files to be verified, even if the 184d5fdcd00SMatthew Dillonfiles appear to the be the same. Whereas the 185d5fdcd00SMatthew Dillon.Fl f 186d5fdcd00SMatthew Dillon(force) option forces a copy regardless, this option will avoid rewriting 187d5fdcd00SMatthew Dillonthe target if everything matches and the contents are verified to be the 188d5fdcd00SMatthew Dillonsame. 1891bcaecdaSMatthew Dillon.It Fl VV 1901bcaecdaSMatthew DillonThis works the same as 1911bcaecdaSMatthew Dillon.Fl V 1921bcaecdaSMatthew Dillonbut ignores mtime entirely, making it suitable for comparing HAMMER 1931bcaecdaSMatthew Dillonmaster and slave filesystems or copies made without mtime retention. 1944d858d58SMatthew Dillon.It Fl S 1954d858d58SMatthew DillonThis places 1964d858d58SMatthew Dillon.Nm 1974d858d58SMatthew Dilloninto slave mode and is used to initiate the slave protocol on a remote 1984d858d58SMatthew Dillonmachine. 199c0538630SMatthew DillonThis option is not intended to be used by humans. 200c0538630SMatthew Dillon.It Fl R 201c0538630SMatthew DillonPlace the slave into read-only mode. 202c0538630SMatthew DillonCan only be used when the source is remote. 203c0538630SMatthew DillonUseful for unattended backups via SSH keys. 2043a42736dSMatthew Dillon.It Fl x 2053a42736dSMatthew DillonCauses 2063a42736dSMatthew Dillon.Nm 207293141b7SMatthew Dillonto use the exclusion file 208293141b7SMatthew Dillon.Pa \&.cpignore 209293141b7SMatthew Dillonin each directory on the source to 2103a42736dSMatthew Dillondetermine which files to ignore. When this option is used, the exclusion 2113a42736dSMatthew Dillonfilename itself is automatically excluded from the copy. If this option is 212293141b7SMatthew Dillonnot used then the filename 213293141b7SMatthew Dillon.Pa \&.cpignore 214293141b7SMatthew Dillonis not considered special and will 2153a42736dSMatthew Dillonbe copied along with everything else. 216577109eaSMatthew Dillon.It Fl X Ar file 21716802529SMatthew DillonWorks similarly to 2183a42736dSMatthew Dillon.Fl x 2193a42736dSMatthew Dillonbut allows you to specify the name of the exclusion file. This file is 2203a42736dSMatthew Dillonautomatically excluded from the copy. Only one exclusion file may be 2213a42736dSMatthew Dillonspecified. 222560e4370SMatthew Dillon.Pp 223560e4370SMatthew DillonWhen an absolute path is used, the same exclusive file is read for 224560e4370SMatthew Dillonevery directory and may contain full paths or wildcarded paths based 225560e4370SMatthew Dillonon the full source path as specified on the cpdup command line. 22616802529SMatthew DillonIn this situation, the exclusive file is read from the host running 22716802529SMatthew Dillonthe command, NOT from the source host (if remote). 228560e4370SMatthew Dillon.Pp 229560e4370SMatthew DillonWhen a relative path is used (or 230560e4370SMatthew Dillon.Fl x 231560e4370SMatthew Dillonis specified), the exclusion file is only applicable to the directory 23216802529SMatthew Dillonit resides in on the source host and only path elements (the directory 23316802529SMatthew Dillonelements) are matched against it. 23452ac7bd7SHiten Pandya.El 2354d858d58SMatthew Dillon.Sh REMOTE COPYING 2364d858d58SMatthew Dillon.Nm 2374d858d58SMatthew Dilloncan mirror directory structures across machines and can also do third-party 2384d858d58SMatthew Dilloncopies. 239c0538630SMatthew DillonThis also works between machines that use different byte order. 2404d858d58SMatthew Dillon.Xr ssh 1 2414d858d58SMatthew Dillonsessions are used and 2424d858d58SMatthew Dillon.Nm 2434d858d58SMatthew Dillonis run on the remote machine(s) in slave mode. 244293141b7SMatthew DillonYou can use the 245293141b7SMatthew Dillon.Fl F 246293141b7SMatthew Dillonoption to pass additional flags to the ssh command if necessary. 247293141b7SMatthew Dillon.Pp 248293141b7SMatthew DillonThe syntax of remote path specifications is similar to 249293141b7SMatthew Dillon.Xr scp 1 . 250293141b7SMatthew DillonIn particular, that means that a local path containing a colon must 251293141b7SMatthew Dillonbe preceded by a slash to prevent it being considered a remote host: 252293141b7SMatthew Dillon.Ql foo:bar 253293141b7SMatthew Dilloncauses 254293141b7SMatthew Dillon.Nm 255293141b7SMatthew Dillonto look for a directory called 256293141b7SMatthew Dillon.Ql bar 257293141b7SMatthew Dillonon host 258293141b7SMatthew Dillon.Ql foo , 259293141b7SMatthew Dillonwhile 260293141b7SMatthew Dillon.Ql \&./foo:bar 261293141b7SMatthew Dillondenotes the directory 262293141b7SMatthew Dillon.Ql foo:bar 263293141b7SMatthew Dillonon the local machine. 264d72200edSMatthew Dillon.Pp 265d72200edSMatthew Dillon.Nm 266d72200edSMatthew Dillonalso supports a 267d72200edSMatthew Dillon.Ql localhost: 268d72200edSMatthew Dillonprefix which is silently discarded but prevents any colons in the remainder 269d72200edSMatthew Dillonof the path from being interpreted as a host:path form. 270d72200edSMatthew Dillonthis form can be used with relative filenames when you do not want colons in 271d72200edSMatthew Dillonthe filename to be misinterpreted. 27278478697SSascha Wildner.Sh EXIT STATUS 27378478697SSascha Wildner.Ex -std 2743a42736dSMatthew Dillon.Sh SEE ALSO 2753a42736dSMatthew Dillon.Xr cp 1 , 2763a42736dSMatthew Dillon.Xr cpio 1 , 277293141b7SMatthew Dillon.Xr scp 1 , 27845b74f6eSSascha Wildner.Xr ssh 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. 287ca097fa5SMatthew DillonThe program was written by Matthew Dillon, Dima Ruban, and later 288ca097fa5SMatthew Dillonsignificantly improved by Oliver Fromme. 2899b2d9484SMatthew Dillon.Sh BUGS 290167c1ad2SSascha Wildner.Xr UFS 5 291167c1ad2SSascha Wildnerhas a hardlink limit of 32767. Many programs, in particular CVS 2929b2d9484SMatthew Dillonwith regards to its CVS/Root file, will generate a lot of hard links. 2939b2d9484SMatthew DillonWhen using the 2949b2d9484SMatthew Dillon.Fl H 2959b2d9484SMatthew Dillonoption it may not be possible for 2969b2d9484SMatthew Dillon.Nm 297293141b7SMatthew Dillonto maintain these hard links. If this occurs, 2989b2d9484SMatthew Dillon.Nm 2999b2d9484SMatthew Dillonwill be forced to copy the file instead of link it, and thus not be able 3009b2d9484SMatthew Dillonto make a perfect copy of the filesystem. 301293141b7SMatthew Dillon.Pp 302293141b7SMatthew DillonWhen so-called sparse files (i.e. files with "holes") are copied, 303293141b7SMatthew Dillonthe holes will be filled in the target files, so they occupy 304293141b7SMatthew Dillonmore physical disk space than the source files. 305c0538630SMatthew Dillon.Pp 306c0538630SMatthew DillonFor compatibility reasons, the slave protocol is not as efficient 307c0538630SMatthew Dillonfor writing remote files as it is for reading them. 308c0538630SMatthew DillonTherefore it is recommended to run 309c0538630SMatthew Dillon.Nm 310c0538630SMatthew Dillonon the target machine when making remote copies, 311c0538630SMatthew Dillonso the source machine is remote. 312c0538630SMatthew DillonIf you do it the other way, 313c0538630SMatthew Dillon.Nm 314c0538630SMatthew Dillonwill run somewhat slower. 315