Home > System Tutorial > LINUX > body text

Guide to rsync usage for excluding files and directories

WBOY
Release: 2024-01-02 19:05:25
forward
902 people have browsed it
Introduction rsync is a very useful and popular Linux tool. It is used to back up and restore files, as well as compare and synchronize files. We have already described how to use rsync under Linux in previous articles, and today we will add some more useful rsync tips.

Guide to rsync usage for excluding files and directories

Exclude files and directories list

Sometimes, when we do a lot of synchronization, we may want to exclude a list of files and directories from being synchronized. Generally speaking, files that occupy unnecessary disk space, such as device files and certain system files, or files that occupy unnecessary disk space, such as temporary files or cache files, are not suitable for synchronization. We need to exclude such files.

First, let's create a file called "excluded" (of course, you can name it whatever you want), and then write the folders or files we want to exclude into the file, one per line. In our example, if you want to make a complete backup of the root partition, you should exclude some device directories created at boot and directories where temporary files are placed. The list will look like this:
Guide to rsync usage for excluding files and directories
Then, you can run the following command to back up your system:

$ sudo rsync -aAXhv --exclude-from=excluded / /mnt/backup
Copy after login

Guide to rsync usage for excluding files and directories

Exclude files from command line

You can also exclude files directly from the command line. This method is used when the number of files you want to exclude is small, and when you want to write it into a script or add it to crontab and do not want the script or cron to depend on another file to run. Very useful at times.

For example, if you want to synchronize /var to a backup directory, but you don't want to include cache and tmp folders that usually don't have important content, you can use the following command:

$ sudo rsync -aAXhv --exclude={"/var/cache","/var/tmp"} /var /home/adrian/var
Copy after login

Guide to rsync usage for excluding files and directories
This command is easy to use in scripts or cron and does not depend on other files.

The above is the detailed content of Guide to rsync usage for excluding files and directories. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template