![]() $ rsync -avz -exclude-from 'exclude-list.txt' source/ destination/ Next, execute the rsync using –exclude-from option with the exclude-list.txt as shown below. This is the list of files and directories you want to exclude from the rsync. So, the better way is to use rsync –exclude-from option as shown below, where you can list all the files (and directories) you want to exclude in a file.įirst, create a text file with a list of all the files and directories you don’t want to backup. I can’t keep adding them in the command line using multiple –exclude, which is hard to read, and hard to re-use the rsync command for later. What if I had tons of files that I want to exclude from rsync? $ rsync -avz -exclude file1.txt -exclude dir3/file4.txt source/ destination/ When you want to exclude multiple files and directories, you can always specify multiple rsync exclude options in the command line as shown below. Exclude multiple files and directories at the same time Note: The above is very helpful, when you want to backup your home directory, but exclude all those huge image and video files that has a specific file extension. Verify the destination directory to make sure it didn’t copy the *.txt files. $ rsync -avz -exclude '*.txt' source/ destination/ ![]() For example, to exclude all the files that contains. ![]() To exclude a specific file type that has a specific extension, use the appropriate pattern. $ rsync -avz -exclude 'dir1/dir2/file3.txt' source/ destination/ 5. Just to avoid confusion (and to make it easy to read), don’t give / in front of the exclude path. So, the above command is exactly same as the following. $ rsync -avz -exclude '/dir1/dir2/file3.txt' source/ destination/ In the example below, rsync will look for dir1 under source directory (and not under / root directory). But, from rsync point of view, exclude path is always relative, and it will be treated as dir1/dir2/file3.txt. In the following example, the exclude option seems to have a full path (i.e /dir1/dir2/file3.txt). If you are not careful, you might make this mistake. $ find destinationĭestination/dir3/file4.txt 4. Verify the destination directory to make sure it didn’t copy the specific file ( dir1/dir2/file3.txt in this example). $ rsync -avz -exclude 'dir1/dir2/file3.txt' source/ destination/ To exclude a specific file, use the relative path of the file in the exclude option as shown below. $ find destinationĭestination/file1.txt 3. Verify the destination directory to make sure it didn’t copy any directories that has the keyword “dir” in it. $ rsync -avz -exclude 'dir*' source/ destination/ The following example will exclude any directory (or subdirectories) under source/ that matches the pattern “dir*” $ rm -rf destination Exclude multiple directories that matches a pattern ![]() ![]() $ find destinationĭestination/dir3/file4.txt 2. Verify to make sure dir1 is not copied from source directory to destination directory. $ rsync -avz -exclude 'dir1' source/ destination/ If you don’t want to sync the dir1 (including all it’s subdirectories) from the source to the destination folder, use the rsync –exclude option as shown below. The above command will create a source directory (under your home directory) with the following structure. This article explains how to ignore multiple files and/or directories during rsync with examples.įirst, create a sample directory structure as shown below (with some empty files) that can be used for testing purpose. You might also want to exclude a specific file type from rsync. In a typical backup situation, you might want to exclude one or more files (or directories) from the backup. You know this already, as we presented you with practical examples on rsync earlier. Rsync is very powerful tool to take backups, or sync files and directories between two different locations (or servers). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |