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.

LoneTar Backup Logo

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.



Comments /Blog/B1124.html


Add your comments

ad

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner





Views for this page
Today This Week This Month This Year  Overall
21296887 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.

Publishing your articles here

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




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://www.loch-raven.com/ Over 18 years of experience Unix and Linux servers. Linux and Unix consulting, system administration, remote administration, custom scripting, web desing and hosting.


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


http://www.cleverminds.net Need expert advice? Want a second opinion? CleverMinds is a one-stop-shop for a wide range of technology solutions. We support Unix, Linux, SCO as well as CMS, ecom, blogs, podcasts, search engines consulting and more. Contact us at web2.0@cleverminds.net 0r (617) 894-1282









Change Congress


Related Posts

Publish your articles, comments, book reviews or opinions here!