Thu Oct 28 20:08:19 2004 Cloning a
directory structure without copying files
Posted by Tony Lawrence
Search Keys: mail|shell
Referencing: /Bofcusm/1926.html
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 ( http://contribs.org/modules/phpwiki/index.php/SME%20and%20backups), 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.
Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)
| Views for this page | ||||
|---|---|---|---|---|
| Today | This Week | This Month | This Year | Overall |
| 2 | 12 | 96 | 887 | 5,365 |
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Publish your articles, comments, book reviews or opinions here!
Add your comments