Rsync is very popular and powerful tool used for backup and clone operations. Rsync can work in localhost or remote hosts. This makes rsync very flexible. We have all ready provided some introduction in the following tutorial.
In this tutorial we will look exclude operations in detail. Exclude feature provides a lot of different use cases. We will look most useful of them.
Exclude Specific Directory
One of the most useful use case for exclude feature is excluding given directories. In this example we will exclude directories those names starts with
$ rsync --exclude 'vms' /home/ismail/Downloads/ /home/ismail/Public/
Exclude Multiple Directories with Specific Pattern
In previous example we have provided only one directory for exclude. We can also provide multiple directories for exclude. We will use wildcard. We will also use wildcard
* to complete
vms directory name.
$ rsync --exclude 'vms*' /home/ismail/Downloads/ /home/ismail/Public/
Exclude Specific File
We can exclude specific file by providing its relative path. In this example we will exclude file named
$ rsync --exclude '/home/ismail/Downloads/file1' Downloads/ Public/
Exclude Relative Path
Like previous example we will exlude given relative path completely. In this example we will exclude path
/home/ismail/Downloads/vms from sync operation.
$ rsync --exclude '/home/ismail/Downloads/vms' Downloads/ Public/
Exclude Specific File Type
We can also specify the file type or extension we want to exclude from sync operation. We will provide the exclude file name like
*.txt which means exclude
txt extension files.
$ rsync --exclude '*.txt' Downloads/ Public/
Exclude Multiple Files and Directories At The Same Time
Up to now we have used only single
exclude option. What will be if we want to exclude multiple files or directories. Actually we can use multiple
exclude options to exclude multiple files and directories. In this example we will exclude
vms directories and
*.tmp temp files.
$ rsync --exclude '*.tmp' --exclude 'vms' Downloads/ Public/