Cloning a directory structure without copying files
I'm always somewhat amused when I go searching for help and Google sends me to my own site for the answer. That's what happened here when I needed to duplicate a directory structure without copying certain files. The solution given at the link referenced above wasn't quite what I wanted, though it did put me on the right track.
I needed to clone user directories on an SME server without copying their mail message files. The reason for this was that we wanted to do a Desktop Backup for a complicated upgrade, which in the SME world means creating a backup and saving it on a Windows box. As these people used IMAP, the user directories were chock full of mail messages and the total size of the backup would be far too large for Windows to accept over an SMB connection.
SME's desktop backup is script driven, so we could have hacked the script to do what we wanted, but that probably would have been fairly difficult.
The script from the referenced link wasn't quite what was needed, because other than the actual mail messages, we wanted to backup any other ordinary files found. Since the mail files are easily matched by a wildcard pattern, this wasn't hard:
# stop mail services svc -d /service/smtpfront-qmail svd -d /service/qmail mkdir /dirclone cd /home/e-smith/files/users # now copy the directory, leaving out the *e-smith* files for i in * do rsync -v -rolgpt --exclude="*e-smith*" $i /dirclone done cd .. mv users usersall mv /dirclone users # do backup, then reverse the directory renaming and restart services
That duplicates the directory hierarchy but leaves out "*e-smith*" files, which is what we want. Rsync does all the work of copying and creating directories with the proper ownership and permissions while conveniently allowing us to say what we DON'T want copied. Note that the exclusion is a wild-card format, not a regex. The rest of the rsync flags make sure that links, permissions, ownerships and time stamps are preserved and that rsync gives us feedback as it descends into the directories.
Got something to add? Send me email.
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
Increase ad revenue 50-250% with Ezoic
Inexpensive and informative Apple related e-books:
Take control of Apple TV, Second Edition
Take Control of iCloud, Fifth Edition
Take Control of the Mac Command Line with Terminal, Second Edition
Take Control of Upgrading to Sierra
Take Control of Pages