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

rub*_*o77 32 backup rsync

您可以轻松地在外部硬盘驱动器上备份您的主文件夹

rsync -a --exclude=.cache --progress /home/$USER /media/linuxbackup/home/$USER
Run Code Online (Sandbox Code Playgroud)

我排除了 .cache 文件夹,因为我认为当我必须从这个备份重新安装时我永远不需要它。

我在这里找到了可以在普通备份中排除的所有文件夹的列表:
可以从主目录的备份中排除哪些文件和目录?

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

#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
Run Code Online (Sandbox Code Playgroud)

这是要点的完整列表

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

rub*_*o77 55

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

将此忽略列表下载到 /var/tmp/ignorelist

wget https://raw.githubusercontent.com/rubo77/rsync-homedir-excludes/master/rsync-homedir-excludes.txt -O /var/tmp/ignorelist
Run Code Online (Sandbox Code Playgroud)

然后启动rsync

rsync -aP --exclude-from=/var/tmp/ignorelist /home/$USER/ /media/$USER/linuxbackup/home/
Run Code Online (Sandbox Code Playgroud)

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

  • 好点,但我认为在启动 rsync 之前首先查看忽略列表是值得推荐的 (10认同)
  • 你可以组合这两个命令,因为 `rsync` 可以从 `stdin` 读取:`wget https://... -O - | rsync -a --progress --exclude-from=- ...` (2认同)

mur*_*uru 5

man rsync

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