(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Cloning a directory structure without copying files

(Traditional format)

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.




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



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.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - SME
       - Backup
       - Mail
       - Shell
       - Blog


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress