Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rsync how to include directories but not files?

I have a directory structure and files like this

data/ data/a.txt data/folder/ data/folder/b.txt data/folder/folder/ data/folder/folder/c.txt ... 

a.txt, b.txt, and c.txt are large files that are computer-generated and renewed frequently. They should NOT be backuped -- but I want to backup the directory structure :

data/ data/folder/ data/folder/folder/ 

How can I do this with rsync and --exclude-from, without specifying every folder, but something like rsync -a data/* --exclude-from=exclude.rsync "" --onlyfoldersandnotfiles""?

Thanks for help !

like image 368
chicama Avatar asked Aug 23 '10 08:08

chicama


People also ask

How do I only rsync a directory?

Rsync allows you to transfer only directory structure if you do not need the files at another location. To do so, add -f"+ */" -f"- *" before the source directory.

How do I ignore files in rsync?

Exclude Files and Directories from a List. When you need to exclude a large number of different files and directories, you can use the rsync --exclude-from flag. To do so, create a text file with the name of the files and directories you want to exclude. Then, pass the name of the file to the --exlude-from option.

How do I keep two directories in sync with rsync?

In order to keep two directories truly in sync, it's necessary to delete files from the destination directory if they are removed from the source. By default, rsync does not delete anything from the destination directory. You can change this behavior with the --delete option.

Can you rsync a folder?

Rsync is a tool that can improve the reliability of local directory syncing and the file transfer process over remote systems. You can use the rsync command to create complex backups and smooth control over what and how a directory will sync.


1 Answers

rsync -a --include='*/' --exclude='*' source/ destination/ 

Basically, first include all directories, then exclude all files.

like image 178
Nikana Reklawyks Avatar answered Sep 21 '22 10:09

Nikana Reklawyks