当所有 sigtar 和大多数清单文件丢失时,提取未加密的 duplicity 备份

当所有 sigtar 和大多数清单文件丢失时,提取未加密的 duplicity 备份

我正在尝试从旧的 duplicity 备份中提取备份(由 ubuntu gui 完成,我相信它是 deja-dup)。

我把所有我能复制的东西都从快要报废的硬盘上复制了下来。我已经

  • 很多difftar.gz文件 — — 一些是 2014 年的,一些是 2016 年的。
  • 2014 年的单个.manifest文件。
  • 没有sigtar.gz文件

备份未加密 - 我解压了一个difftar.gz文件并在十六进制编辑器中检查了它,我可以看到很多纯文本。

运行一些命令:

% duplicity --no-encryption --ignore-errors collection-status file:///home/hamish/poonbackup2014
Running in 'ignore errors' mode due to --ignore-errors; please re-consider if this was not intended
Last full backup date: Mon Sep 15 19:37:44 2014
Collection Status
-----------------
Connecting with backend: BackendWrapper
Archive directory: /home/hamish/.cache/duplicity/c34b5c3ae7d763a715fd062ec5f49baa

Found 1 secondary backup chain.
Secondary chain 1 of 1:
-------------------------
Chain start time: Mon Sep 15 19:37:44 2014
Chain end time: Mon Sep 15 19:37:44 2014
Number of contained backup sets: 1
Total number of contained volumes: 2063
 Type of backup set:                            Time:   Number of volumes:
                Full         Mon Sep 15 19:37:44 2014              2063
-------------------------

No backup chains with active signatures found
No orphaned or incomplete backup sets found.



% duplicity --no-encryption --ignore-errors collection-status file:///home/hamish/poonbackup2016
Running in 'ignore errors' mode due to --ignore-errors; please re-consider if this was not intended
Warning, found incomplete backup sets, probably left from aborted session
Last full backup date: none
Collection Status
-----------------
Connecting with backend: BackendWrapper
Archive directory: /home/hamish/.cache/duplicity/37e66337a462669832db8b2b852f9c6f

Found 0 secondary backup chains.
No backup chains with active signatures found
Also found 0 backup sets not part of any chain,
and 2 incomplete backup sets.
These may be deleted by running duplicity with the "cleanup" command.


% duplicity --no-encryption --ignore-errors list-current-files file:///home/hamish/poonbackup2014
Running in 'ignore errors' mode due to --ignore-errors; please re-consider if this was not intended
Synchronising remote metadata to local cache...
Deleting local /home/hamish/.cache/duplicity/f152114ed2326b0ba48e42e6ec0a23d6/duplicity-full.20140915T183744Z.manifest (not authoritative at backend).
Last full backup date: none
Traceback (innermost last):
  File "/usr/bin/duplicity", line 1555, in <module>
    with_tempdir(main)
  File "/usr/bin/duplicity", line 1541, in with_tempdir
    fn()
  File "/usr/bin/duplicity", line 1393, in main
    do_backup(action)
  File "/usr/bin/duplicity", line 1476, in do_backup
    list_current(col_stats)
  File "/usr/bin/duplicity", line 702, in list_current
    sig_chain = col_stats.get_signature_chain_at_time(time)
  File "/usr/lib/python2.7/dist-packages/duplicity/collections.py", line 998, in get_signature_chain_at_time
    raise CollectionsError("No signature chains found")
 CollectionsError: No signature chains found

假设我无法从原始硬盘中提取更多文件,我有什么方法可以提取文件吗?

我最感兴趣的是提取照片 - 如果我能提取没有名称或文件元数据的照片文件,那将是一次胜利。

答案1

collection status 在 file:///home/hamish/poonbackup2014 中找到一个链。因此理论上你应该能够恢复所有的备份。签名只需要恢复单个文件/文件夹或列出内容。

..ede/duply.net

答案2

我总体上遵循这个答案中的指南但我想进一步阐述以下几点:

全面的

这些difftar.gz文件都是普通tar.gz文件,没有加密。如果你将它们全部解压,它们会将其内容放入文件结构中。顶层有两个目录:

  • snapshot/- 它包含普通文件,但就我而言,它包含我关心的文件的(非常)小子集 - 我想要恢复的 100 GB 中的约 100 MB。
  • multivol_snapshot/- 其中包含每个普通文件的目录。每个目录中都有一组文件,这些文件的文件名只有数字 - 1,,2... 文件大小似乎始终为 64 kB(当然,最后一个除外)。您可以手动将文件放在一起,这对于少量文件来说相当有效。但我有很多。

解包

首先我需要解压所有的 tar gz 文件:

for f in duplicity-full.*.difftar.gz; do echo "$f"; tar xf "$f"; done

重建

上面的答案有一个 shell 单行代码,但它会创建许多content与原始内容混合的文件。我想重新创建文件系统。所以我写了下面的 python 脚本,它接受 2 个参数:

  • multivol_snapshot/包含要恢复的位的目录
  • 放置恢复文件的目录。

它将以递归方式检查所有内容并重新创建文件。只要您拥有所需的所有块,它就会正常工作...

#!/usr/bin/env python3
import argparse
from pathlib import Path
import shutil
import sys


class FileReconstructor():

    def __init__(self, unpacked_dir, restore_dir):
        self.unpacked_path = Path(unpacked_dir).resolve()
        self.restore_path = Path(restore_dir).resolve()

    def reconstruct_files(self):
        for leaf_dir in self.walk_unpacked_leaf_dirs():
            target_path = self.target_path(leaf_dir)
            target_path.parent.mkdir(parents=True, exist_ok=True)
            with target_path.open('wb') as target_file:
                self.copy_file_parts_to(target_file, leaf_dir)

    def copy_file_parts_to(self, target_file, leaf_dir):
        file_parts = sorted(leaf_dir.iterdir(), key=lambda x: int(x.name))
        for file_part in file_parts:
            with file_part.open('rb') as source_file:
                shutil.copyfileobj(source_file, target_file)

    def walk_unpacked_leaf_dirs(self):
        """
        based on the assumption that all leaf files are named as numbers
        """
        seen_dirs = set()
        for path in self.unpacked_path.rglob('*'):
            if path.is_file():
                if path.parent not in seen_dirs:
                    seen_dirs.add(path.parent)
                    yield path.parent

    def target_path(self, leaf_dir_path):
        return self.restore_path / leaf_dir_path.relative_to(self.unpacked_path)


def parse_args(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'unpacked_dir',
        help='The directory with the unpacked tar files',
    )
    parser.add_argument(
        'restore_dir',
        help='The directory to restore files into',
    )
    return parser.parse_args(argv)


def main(argv):
    args = parse_args(argv)
    reconstuctor = FileReconstructor(args.unpacked_dir, args.restore_dir)
    return reconstuctor.reconstruct_files()


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))

相关内容