当前位置: 首页>>技术教程>>正文


使用 rsync 备份主目录并跳过无用的文件夹

,

问题描述

您可以轻松地将主文件夹备份到外部硬盘上

rsync -a --exclude=.cache --progress /home/$USER /media/linuxbackup/home/$USER

我排除了 .cache 文件夹,因为我认为当我必须从此备份中获取 re-install 时,我永远不会需要它。

\\n

I found this list of all folders that I could exclude in a normal backup here:
\\nWhat files and directories can be excluded from a backup of the home directory?

\\n

我创建了这个答案的列表,其中包含以下形式的一些评论:

#These directories may be excluded:

.gvfs                           # contains mounted file systems?
.local/share/gvfs-metadata
.Private                        # contains the actual encrypted home directory
.dbus                           # session-specific
.cache
.Trash                          # do I need to say more?
.local/share/Trash
.cddb                           # cached info about audio CDs
.aptitude                       # cached packages lists

#Flash-specific:

.adobe                          # Cache for flash, maybe others?
.macromedia   # except for Flash persistence, there is no reason to keep this

#Files:

.xsession-errors            # contains errors from the current graphical session
.recently-used              # recently used files
.recently-used.xbel
.thumbnails

Here is the full list at gist

如何将此列表添加到我的 rsync 命令中?

最佳思路

排除列表只能包含文件名、文件夹名和以 # 开头的行。不允许在文件夹名称后面添加注释。我创建了一个 Git 存储库,其中包含所有已知的多余文件和文件夹:

下载此 ignorelist 到 /var/tmp/ignorelist

wget https://raw.githubusercontent.com/rubo77/rsync-homedir-excludes/master/rsync-homedir-excludes.txt -O /var/tmp/ignorelist

然后启动 rsync

rsync -aP --exclude-from=/var/tmp/ignorelist /home/$USER/ /media/$USER/linuxbackup/home/

注意:\n在忽略列表中,开头有一个带有文件夹的注释部分,这些文件夹可能也不值得备份。取消注释那些,你不需要。

次佳思路

来自 man rsync

 --exclude-from=FILE     read exclude patterns from FILE
          This option is related to the --exclude option, but it specifies
          a FILE that contains exclude patterns  (one  per  line).   Blank
          lines  in  the  file  and  lines  starting  with  ’;’ or ’#’ are
          ignored.  If FILE is -, the list  will  be  read  from  standard
          input.

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13921.html,未经允许,请勿转载。