我可以在 deja-dup(备份)中按模式忽略文件吗?

我可以在 deja-dup(备份)中按模式忽略文件吗?

我的重复备份变得非常大,我注意到它们包含大量不必要的文件(例如*.pyc文件、**__pycache__文件夹和其他与构建相关的临时文件)。

我知道我可以忽略特定文件夹,但是有没有办法通过模式排除文件和文件夹?

我以为可以通过配置文件提供更多选项,但是重复不使用。所以我查看了表里不一(它基于 CLI),但手册页也没有提到配置文件。我知道表里不一可以根据模式忽略文件和文件夹(--exclude--exclude-filelist),但我不知道如何将它与重复

我是否必须放弃重复并使用表里不一手动?或者有没有办法设置所需的选项,以便它们在表里不一由使用重复

答案1

您可以编辑排除列表,如下所示:

gsettings get org.gnome.DejaDup exclude-list
# remove comment to execute
# gsettings set org.gnome.DejaDup exclude-list ['path1', 'path2']

来源:https://answers.launchpad.net/deja-dup/+question/280954

我尝试将“**/.git”和“**/build”之类的模式添加到该列表中,如下所示:

gsettings get org.gnome.DejaDup exclude-list > exclude-list
gedit exclude-list
gsettings set org.gnome.DejaDup exclude-list "`cat exclude-list`"

但在我看来,** 似乎没有传递给 duplicity。所以我最终进行了如下搜索

locate "/home/*/.svn"
locate "/home/*/build"

并手动将它们添加到排除列表中

答案2

目前 Deja Dup 无法进行这样的高级过滤。请参阅上游错误https://bugs.launchpad.net/deja-dup/+bug/374274

答案3

使用 ** 模式不再有效,因为 deja-dub 在 duplicity 命令中转义了 [?* 字符。请参阅https://git.launchpad.net/deja-dup/tree/libdeja/tools/duplicity/DuplicityJob.vala#n303

  string escape_duplicity_path(string path)
  {
    // Duplicity paths are actually shell globs.  So we want to escape anything
    // that might fool duplicity into thinking this isn't the real path.
    // Specifically, anything in '[?*'.  Duplicity does not have escape
    // characters, so we surround each with brackets.
    string rv;
    rv = path.replace("[", "[[]");
    rv = rv.replace("?", "[?]");
    rv = rv.replace("*", "[*]");
    return rv;
  }

  void process_include_excludes()
  {
    expand_links_in_list(ref includes, true);
    expand_links_in_list(ref excludes, false);

    // We need to make sure that the most specific includes/excludes will
    // be first in the list (duplicity uses only first matched dir).  Includes
    // will be preferred if the same dir is present in both lists.
    includes.sort((CompareFunc)cmp_prefix);
    excludes.sort((CompareFunc)cmp_prefix);

    foreach (File i in includes) {
      var excludes2 = excludes.copy();
      foreach (File e in excludes2) {
        if (e.has_prefix(i)) {
          saved_argv.append("--exclude=" + escape_duplicity_path(e.get_path()));
          excludes.remove(e);
        }
      }
      saved_argv.append("--include=" + escape_duplicity_path(i.get_path()));
      //if (!i.has_prefix(slash_home_me))
      //  needs_root = true;
    }
    foreach (File e in excludes) {
      saved_argv.append("--exclude=" + escape_duplicity_path(e.get_path()));
    }

    // TODO: Figure out a more reasonable way to order regexps and files.
    // For now, just stick regexps in the end, as they are more general.
    foreach (string r in exclude_regexps) {
      saved_argv.append("--exclude=" + r);
    }

    saved_argv.append("--exclude=**");
  }

答案4

我正在使用伊恩·普勒斯顿答案,非常简单,因为建议的脚本对我来说不起作用。参考他的回答,但使用这个内容代替 duplicity shim 脚本:

#!/bin/bash

# Shim script run from deja-dup in place of duplicity 
# which forces the exclusions read from ~/.config/deja-dup-excludes 
# using the standard filelist exclusion mechanism

/usr/bin/duplicity --include=$HOME/.cache/deja-dup/metadata --exclude-filelist=$HOME/.config/deja-dup-excludes "$@"

这是在 Ubuntu 18.04 和 20.04 上测试的,它使用了duplicity的标准--exclude-filelist命令, 哪个支持一些扩展的 shell 通配符模式(对于较旧的 duplicity 版本,您可以将其替换为--exclude-globbing-filelist)。为了使一切正常,排除首先出现非常重要。请谨慎选择排除的内容,不承担任何责任,使用时风险自负。

关于--include=$HOME/.cache/deja-dup/metadata

--include=$HOME/.cache/deja-dup/metadatadeja-dup在s 调用中被硬编码duplicity。该文件是在备份期间创建并用于基本健全性检查,因此需要包含在备份中。如果没有,则deja-dup在备份创建结束时会失败并出现以下错误:

'metadata' file not found when creating backup ("Could not restore ‘/home/user/.cache/deja-dup/metadata’: File not found in backup"

因此--include=$HOME/.cache/deja-dup/metadata需要论证(必须~/.config/deja-dup-excludes如果您的排除规则恰好排除$HOME/.cache(例如通过/**/.cache),则在上述垫片脚本中将其放在第一位。请参阅文件选择部分有关详细信息,请参阅 duplicity 的联机帮助页。

相关内容