Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rsync to copy only particular folders

Tags:

linux

rsync

I have a dir with files and dirs in it. What I want is to make rsync copy of several folders from that dir. For example, lets say I have this:

/home/user
-- drwxr-xr-x  folderA
-- drwxr-xr-x  folderB
-- drwxr-xr-x  folderC
-- -rw-r--r--  file.1
-- -rw-r--r--  file.2

I want to copy folderA and folerB using rsync. I have created file rsync_folders.txt

+ /folderA/**
+ /folderB/**

My problem is that rsync will always copy file unless it matches exclude pattern. But if I add

- /**

nothing is copied because rsync first matches against exclude patterns.

Any ideas?

Note: I cannot list all folders and files I want to exclude. It will be changing from time to time.

like image 947
Georgy Bolyuba Avatar asked Jul 15 '09 14:07

Georgy Bolyuba


People also ask

How do I rsync only certain files?

The rsync tool allows you to exclude certain file types when synchronizing data. Use an asterisk * followed by the extension of the file type you want to exclude. For example, you may want to back up a directory that contains many .

Does rsync copy folders?

Rsync (Remote Sync) is the most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems.

Is rsync faster than copying?

So if you are running this sort of command frequently, and the set of changed files is small relative to the total number of files, you should find that rsync is faster than cp.


1 Answers

Either use rsync -av src1 src2 src3 ... dst or put all the folders you want to rsync in a text file (each folder in a separate line) and use rsync -arv --files-from=sources.txt dst.
Note that by default -a implies --recursive but not when --files-from is used, so in this case -r must be specified explicitly.

like image 118
drrlvn Avatar answered Sep 28 '22 10:09

drrlvn