How to rsync or tar directory trees, with hidden directory, but without files?

I want to backup all the directory tress, including hidden directories, without copying any files.
find . -type d gives the perfect list.

When I tried tar, it won't work for me because it tars all the files.

find . -type d | xargs tar -cvf a.tar

So i tried rsync.
On my own test box, the following works.

$ rsync -a -f"+ */" -f"- *" source/ destination/

unfortunately, the server I want to do the backup has an older version of rsync (version 2.5.5 protocol version 26), so the command above somehow does not work:

bash-2.05$ rsync -a -f"+ */" -f"- *" source/ destination.
rsync: -f+ */: unknown option
rsync error: syntax or usage error (code 1) at main.c(875)

I have also tried

rsync -avuzb --exclude '*.*' source/ destination/

It won't copy hidden directories. And it won't exlcude files without suffix.

So please help!

actually with xargs is not seem mistake.. if you give still error try this :slight_smile:

cd backuppath ; tar cvf a.tar `ls -la | grep ^d | grep -Ev '\.\.$|\.$' | sed 's/.* //'`

Tried it, got an error:

If I remove E, the command runs, but it tars up everything under/home, not just dir1 :frowning:

The part in ` ` gives all the dirs under /home/dir1 that I want to backup, just tar behaves weirdly. Any ideas?

hmm try to change the part in ` ` with

ls -la |grep ^d |sed 's/.* //;s/^\.$\|\..$//;/^$/d'

Hi.

I found it easier to think of replicating the directory tree, omitting the non-directory items, and then tarring up that tree:

#!/usr/bin/env bash

# @(#) s1	Demonstrate replication of directory structure.

# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

pl " Original tree \"a\" with files:"
tree -a -F a

pl " Original tree \"a\", listing directories only:"
tree -d -a -F a

rm -rf skeleton skeleton-t1
find . -type d ! -name '*skeleton*' > skeleton-t1
# cat skeleton-t1
sed 's|^[.]|skeleton|' skeleton-t1 > skeleton-t2
# cat skeleton-t2

IFS=$'\012'
while read dir
do
  mkdir "$dir"
done < skeleton-t2

pl " New upper tree named \"skeleton\", same structure, expecting no files:"
tree -a -F skeleton

pl  " Final tar operation:"
tar cvf skeleton.tar -C skeleton .

pl " Listing of tar file:"
tar xvf skeleton.tar

exit 0

producing on an existing example tree "a":

% ./s1

-----
 Original tree "a" with files:
a
|-- .a4
|-- a-3
|-- a1
|-- a2
|-- b/
|   |-- b1
|   |-- b2
|   |-- b3 with spaces
|   `-- d/
|       |-- d1
|       `-- d2
`-- c/
    |-- c1
    |-- c2
    `-- e-dir with spaces/
        |-- .f-hidden/
        |   |-- f1
        |   `-- f2
        |-- e1
        `-- e2

5 directories, 15 files

-----
 Original tree "a", listing directories only:
a
|-- b
|   `-- d
`-- c
    `-- e-dir with spaces
        `-- .f-hidden

5 directories

-----
 New upper tree named "skeleton", same structure, expecting no files:
skeleton
`-- a/
    |-- b/
    |   `-- d/
    `-- c/
        `-- e-dir with spaces/
            `-- .f-hidden/

6 directories, 0 files

-----
 Final tar operation:
./
./a/
./a/b/
./a/b/d/
./a/c/
./a/c/e-dir with spaces/
./a/c/e-dir with spaces/.f-hidden/

-----
 Listing of tar file:
./
./a/
./a/b/
./a/b/d/
./a/c/
./a/c/e-dir with spaces/
./a/c/e-dir with spaces/.f-hidden/

I ran this on a tree that had 60 MB in 280 directories, and it went too quickly for me to see anything except the last part of the list.

There may be other shorter methods as well ... cheers, drl