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.
Code:
find . -type d | xargs tar -cvf a.tar
So i tried rsync.
On my own test box, the following works.
Code:
$ 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:
Code:
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
Code:
rsync -avuzb --exclude '*.*' source/ destination/
It won't copy hidden directories. And it won't exlcude files without suffix.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
I found it easier to think of replicating the directory tree, omitting the non-directory items, and then tarring up that tree:
Code:
#!/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":
Code:
% ./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
Hello.
I use this command :
rsync -av --include=".*" --dry-run "$A_FULL_PATH_S" "$A_FULL_PATH_D"The data comes from the output of a find command.
And no full source directories are in use, only some files.
Source example... (2 Replies)
Hi
Can somebody please show me how to check from within a KSH script if a directory exists on that same host when parts of the directory tree are unknown?
If these wildcard dirs were the only dirs at that level then ...
RETCODE=$(ls -l /u01/app/oracle/local/*/* | grep target_dir) ... will... (4 Replies)
Find all files in the current directory only excluding hidden directories and files.
For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided.
`find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
I have constant trouble with XCOPY/s for multi-gigabyte transfers.
I need a utility like XCOPY/S that remembers where it left off if I reboot. Is there such a utility? How about a free utility (free as in free beer)?
How about an md5sum sanity check too?
I posted the above query in another... (3 Replies)
can someone give me a script to tar files that is older than 5 days in a directory that is not something like this:
fileArray=($(find -mtime +5 asdfasdf))
tar -cvf asfadfasdfa ${fileArray}
as the Unix I'm using has some problem with ($( )), I need another way to tar files in the folder.... (1 Reply)
Hi
I have a job that will be running nightly incremental backsup of a large directory tree.
I did the initial backup, now I want to write a script to verify that all the files were transferred correctly. I did something like this which works in principle on small trees:
diff -r -q... (6 Replies)
Dear Folks,
I have to backup pgsql database dump everynight on a routine. The database dump actually contains sql(text) statements. The actual size of the database dump is aroung 800 MB. Between two days backup, only few lines of statements are modified/added/deleted.
I dont want to do... (1 Reply)