【rsync】使用rsync备份文件/目录并排除特定文件/目录

Linux 下复制(cp)目录时排除一个或者多个目录的方法

cp 貌似没有排除目录的功能,可以使用 rsync 命令来实现。

# rsync --help

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)

       --no-OPTION            turn off an implied OPTION (e.g. --no-D)

-r, --recursive            recurse into directories

-p, --perms preserve permissions

注意:--exclude后面的路径不能为绝对路径,必须为相对路径才可以,否则出错。

# ll /root/install_fio/

源目录结尾带 /,会将此目录下文件&目录拷贝到目标目录下,如果没有目标目录,会自动创建

# rsync -rap --exclude="repodata"    /root/install_fio/    /tmp/install_fio_exclude_repodata

# rsync -rap --exclude="repodata"    ./install_fio/    /tmp/install_fio_exclude_repodata

# ll  /tmp/install_fio_exclude_repodata

源目录结尾不带 /,会将此目录整个目录拷贝到目标目录下,如果没有目标目录,会自动创建

# rsync -rap --exclude="repodata"     /root/install_fio     /tmp/install_fio_exclude_repodata

# rsync -rap --exclude="repodata"   ./install_fio    /tmp/install_fio_exclude_repodata

# ll  /tmp/install_fio_exclude_repodata

参考 

How to exclude directories with certain names from rsync on Linux?

https://www.systutorials.com/how-to-exclude-directories-with-certain-names-from-rsync-on-linux

rsync 排除指定目录或文件进行同步

https://www.cnblogs.com/xiao-xue-di/p/13901756.html

rsync 排除指定目录

https://www.cnblogs.com/bigtreei/p/11763865.html

Linux下cp目录时排除一个或者多个目录的方法

https://www.osyunwei.com/archives/2626.html

https://blog.51cto.com/lxsym/831393

おすすめ

転載: blog.csdn.net/michaelwoshi/article/details/120983724
おすすめ