Taking tar of a directory structure

Problem:

I have a directory structure from one server that I need to mirror onto another server.  The directory structure/tree is deep and contains hundreds of subdirectories.  I do not want to spend hours manually creating the directory structure on the other server.  I also do not want to have to back up and restore the content in the subdirectories.

Solution:

The idea is to generate a list of directories and subdirectories that can be fed into ‘tar’ as –files-from input.  Here’s an example:

tar cf etc_dirstructure.tar --no-recursion --files-from <( find /etc -type d)

Note: on Mac OS X, replace –no-recursion with -n flag.

Here’s an exerpt of the tar file content:

# tar tvf etc_dirstructure.tar
drwxr-xr-x root/root         0 2010-08-25 14:31:06 etc/
drwxr-xr-x root/root         0 2010-08-07 23:05:01 etc/cron.daily/
drwxr-xr-x root/root         0 2010-08-07 23:05:01 etc/cron.weekly/
drwxr-xr-x root/root         0 2010-08-07 23:05:01 etc/yum/
drwxr-xr-x root/root         0 2008-11-10 14:21:13 etc/bluetooth/
drwxr-xr-x root/root         0 2007-10-25 16:57:04 etc/makedev.d/
drwxr-xr-x root/root         0 2009-11-12 16:26:34 etc/sysconfig/
drwxr-xr-x root/root         0 2008-06-25 08:55:14 etc/sysconfig/console/
drwxr-xr-x root/root         0 2008-06-25 08:55:14 etc/sysconfig/networking/
drwxr-xr-x root/root         0 2008-06-25 08:55:14 etc/sysconfig/networking/prof
iles/
drwxr-xr-x root/root         0 2008-06-25 08:55:14 etc/sysconfig/networking/prof
iles/default/
drwxr-xr-x root/root         0 2008-06-25 08:55:13 etc/sysconfig/networking/devi
ces/
drwxr-xr-x root/root         0 2006-07-29 20:18:11 etc/sysconfig/apm-scripts/
drwxr-xr-x root/root         0 2010-03-10 17:48:28 etc/sysconfig/network-scripts
/
drwxr-xr-x root/root         0 2010-08-07 23:08:18 etc/sysconfig/rhn/
drwxr-xr-x root/root         0 2008-06-24 08:07:26 etc/sysconfig/rhn/clientCaps.
d/
drwxr-xr-x root/root         0 2007-10-25 16:53:03 etc/maven/
drwxr-xr-x root/root         0 2010-08-07 23:47:04 etc/mindi/
drwxr-xr-x root/root         0 2010-08-07 23:47:04 etc/mindi/deplist.d/

Now you can copy over the tar file and untar it on the other server to have the directory structure generated.

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment