Bru*_*tus 24 backup deja-dup duplicity
我的Déjà Dup备份变得非常大,我注意到它们包含大量不必要的文件(例如*.pyc文件、**__pycache__文件夹和其他与构建相关的临时文件)。
我知道我可以忽略特定文件夹,但是有没有办法按模式排除文件和/或文件夹?
我认为通过配置文件可能有更多可用的选项,但Déjà Dup不使用一个。所以我查看了重复性(它基于的 CLI),但手册页也没有提到配置文件。我知道Duplicity可以忽略基于模式 ( --exclude, --exclude-filelist) 的文件和文件夹,但我不知道如何将其与Déjà Dup结合起来。
我是否必须放弃 Déjà Dup并手动使用双重性?还是有一种方法来设置所需要的选项,因此它们可以自动使用,当两面三刀所使用的DéjàDup的?
您可以编辑排除列表,如:
gsettings get org.gnome.DejaDup exclude-list
# remove comment to execute
# gsettings set org.gnome.DejaDup exclude-list ['path1', 'path2']
Run Code Online (Sandbox Code Playgroud)
来源: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`"
Run Code Online (Sandbox Code Playgroud)
但对我来说,**似乎没有被传递给口是心非。所以相反,我最终做了类似的搜索
locate "/home/*/.svn"
locate "/home/*/build"
Run Code Online (Sandbox Code Playgroud)
并手动将它们添加到排除列表中
小智 6
使用 ** 模式(不再)起作用,因为 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=**");
}
Run Code Online (Sandbox Code Playgroud)
小智 5
dconf-editorsudo apt install dconf-editor
Run Code Online (Sandbox Code Playgroud)
dconf-editor以普通用户身份运行。(不要使用sudo)dconf-editor
Run Code Online (Sandbox Code Playgroud)
['$TRASH', '$DOWNLOAD', '/home/leo/.anaconda', '/home/leo/**/node_modules', '/home/leo/**/__pycache__', '/home/leo/**/*.pyc']
Run Code Online (Sandbox Code Playgroud)
截图:
将leo替换为您的用户名
我为此想出了一个可行的解决方法。问题似乎是口是心非本身并不扩展通配符(显然除了 ** )而是依赖 shell 来做到这一点,并且当它从 deja-dup 运行时没有 shell 参与,这就是为什么现在阻止配置通配符排除。当然,您可以使用 dconf-editor 强制它们进入保存的排除列表,但它们不起作用(从下面脚本中的监控我实际上发现 deja-dup 会删除包含 '*' 的排除并且不会传递它们完全口是心非)。
为了使其工作,我们需要对通配符进行 shell 扩展。您可以手动执行此操作并通过 dconf-editor 插入结果,如此处建议的那样,但此解决方案会在备份运行时自动执行此操作。
首先找到路径上的口是心非的位置(“哪个口是心非”),然后在路径中找到其前面的路径位置(“echo $PATH”)。就我而言,它是 /usr/bin/duplicity ,而 /usr/local/bin 位于其前面,这是完美的。在后一个路径位置(例如 /usr/local/bin/duplicity)创建一个名为 duplicity 的文本文件,使其可执行(chmod +x ...)并将以下内容放入其中:
#! /bin/bash
# Shim script run from deja-dup in place of duplicity, to add in file/pattern
# exclude arguments for duplicity.
#
# The excludes are read from ~/.config/deja-dup-excludes (one-per-line).
ARGS="$*"
EXCLUDES=$(cat $HOME/.config/deja-dup-excludes | sed -e 's/#.*$//' -e 's/^[ \t]*//' -e '/^$/d')
if ( echo "$ARGS" | grep -q '\--exclude'); then
for EXCL in $EXCLUDES
do
EXCL_ARG=$(find $EXCL -printf '--exclude %p ')
ARGS="$EXCL_ARG$ARGS"
done
fi
#echo "$ARGS" >>/tmp/dup.out
/usr/bin/duplicity $ARGS
Run Code Online (Sandbox Code Playgroud)
确保最后一行具有您计算机上真正口是心非的正确路径,如果您想检查您的工作,可以取消注释 echo 语句。
然后在主目录下创建一个文件 .config/deja-dup-excludes,其中每行列出一个排除项,例如:
# Exclude files/patterns for deja-dup
# (used by the /usr/local/bin/duplicity script).
/home/Ian/core.*
/etc/postfix/sasl_passwd*
Run Code Online (Sandbox Code Playgroud)
任何以“#”开头的行都将被视为注释行并被忽略。
deja-dup 现在将执行该脚本而不是真正的口是心非,并且它将在调用后者之前添加必要的 --exclude 参数。
诚然,这是一种黑客行为,但它确实有魅力。
我正在使用Ian Puleston答案的变体,该答案非常简化,因为提议的脚本不适合我。请参阅他的答案,但使用此内容代替口是心非垫片脚本:
\n#!/bin/bash\n\n# Shim script run from deja-dup in place of duplicity \n# which forces the exclusions read from ~/.config/deja-dup-excludes \n# using the standard filelist exclusion mechanism\n\n/usr/bin/duplicity --include=$HOME/.cache/deja-dup/metadata --exclude-filelist=$HOME/.config/deja-dup-excludes "$@"\nRun Code Online (Sandbox Code Playgroud)\n这是在 Ubuntu 18.04 和 20.04 上进行测试的,它使用duplicity\ 的标准--exclude-filelist命令,它支持一些扩展的 shell 通配模式(对于较旧的口是心非版本,您可以将其替换为--exclude-globbing-filelist)。为了让一切正常工作,首先出现排除项很重要。请小心您排除的内容,不承担任何责任,使用风险自负。
--include=$HOME/.cache/deja-dup/metadata--include=$HOME/.cache/deja-dup/metadatadeja-dup在的调用中被硬编码duplicity。该文件是在备份期间创建的,用于基本的健全性检查,因此需要包含在备份中。如果不是,deja-dup则会在备份创建结束时失败并出现以下错误:
\'metadata\' file not found when creating backup ("Could not restore \xe2\x80\x98/home/user/.cache/deja-dup/metadata\xe2\x80\x99: File not found in backup"\nRun Code Online (Sandbox Code Playgroud)\n因此,在上面的 shim 脚本中,该--include=$HOME/.cache/deja-dup/metadata参数是必需的(必须先出现),以防您的排除规则碰巧~/.config/deja-dup-excludes排除$HOME/.cache(例如 via /**/.cache)。有关详细信息,请参阅duplicity 联机帮助页中的文件选择部分。