使用Dropbox API还原已删除的文件 [英] Restore deleted files using Dropbox API

查看:117
本文介绍了使用Dropbox API还原已删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用Dropbox API还原文件的方法,而Google将我带到了这里。

I was searching for a way to use Dropbox API to restore my files and Google brought me here.

首先,我的处境:

我的计算机感染了病毒,该病毒重命名了我的所有文件(如果IDK在Dropbox上被识别为重命名或删除,则该文件为IDK),并且它们都已同步到Dropbox 。我想使用Dropbox API下载我所有的原始文件。

My computer got a virus that rename all of my files (idk if its recognized as rename or delete on Dropbox) and they are all synced to Dropbox. I want to download all my original files using Dropbox API.

正如我在网络界面上看到的那样,我可以单独下载它们,但是却得到了数千个文件,因此我无法

As i can see on web interface, I can download them individually but I got like thousand files so I couldn't do it.

我的问题:

我使用Python API包装器与Dropbox API一起使用。我首先获取了所有文件,并尝试获取其所有修订,但原始文件未包含在修订列表中。

I used Python API wrapper to work with Dropbox API. I first fetched all of my files and tried to get all of their revisions but the original files are not included in revision list.

然后,我尝试列出所有文件包括已删除的文件,我可以看到列出的原始文件。我尝试使用下载终结点下载它们,但返回找不到文件错误。有没有人碰到类似的东西?我该如何解决此问题?

Then I tried to list all of my files including deleted files and I can see my original files listed. I tried to download them using download endpoint but it returned File not found error. Has anyone bumped into something similar? How can I solve this issue?

我的代码段:

dbx = dropbox.Dropbox('token is intentionally hidden')
print dbx.users_get_current_account()
for entry in dbx.files_list_folder('', recursive = False, include_deleted = True).entries:
  if (isinstance(entry, dropbox.files.FileMetadata) or isinstance(entry, dropbox.files.DeletedMetadata)):
    if not entry.name.endswith('cerber2'):
      print "name: ", entry.name, "| path: ", entry.path_lower 
      print repr(entry)
      try:
        meta, resp = dbx.files_download(entry.path_lower)
      except dropbox.exceptions.ApiError as e:
        print e.user_message_text
      print "-" * 80


推荐答案

今天下午,我一直在努力解决这个确切的问题,试图恢复朋友的Dropbox的状态,被相同的勒索软件击中。我不知道您是否仍然需要解决方案,但是总的来说,这是一种状态。

I've been scratching my head over this exact problem this afternoon, to try and restore the state of a friend's Dropbox which got hit by the same ransomware. I don't know whether you're still in need of a solution, but in a nutshell, here's the state of play.

在Dropbox API V2中,每个文件都有唯一的ID。这在删除,重命名,移动等操作中保持不变。这是解决此问题的关键,因为Dropbox会按文件路径跟踪文件历史记录,因此,勒索软件重命名文件后,可以选择以编程方式简单地回滚文件丢失。要使事情变得更加困难,请获取目录列表,其中 include_deleted 设置为True,您会注意到Dropbox在元数据删除中不包含文件ID。如果他们这样做了,那将是一件轻而易举的事。

In Dropbox API V2, every file has a unique ID. This is persisted across deletes, renames, moves, etc. This will be key to fixing this problem, as Dropbox tracks file history by file path, so as soon as the ransomware renamed your files, the option of simply rolling back your files programmatically was lost. To make things even more difficult, fetch a directory listing with include_deleted set to True and you'll notice that Dropbox don't include file IDs in the metadata for deletions. If they did, this would be a breeze.

因此,这是替代方法:


  1. 照常获取文件列表。

  2. 将该文件列表分为两个列表:现有文件和已删除文件:

  1. Fetch a list of files, as normal.
  2. Split that list of files into two lists, existing files and those that have been deleted:

已删除=列表(过滤器(lambda文件:isinstance(file,dropbox.files.DeletedMetadata),files.entries))

deleted = list(filter(lambda file: isinstance(file, dropbox.files.DeletedMetadata), files.entries))

(其中 files dropbox.files.ListFolderResult )


  1. 在这里,有关API调用的工作有些繁琐。对于每个已删除的文件,您需要使用 dropbox.Dropbox.files_list_revisions 来获取修订列表。进行第一个修订,它将是最新的,并将其ID存储在文件路径旁边。这就是我们获取已删除文件的ID的方式。

  2. 现在(希望如此)您的文件夹/ Dropbox中每个已删除文件都有一个ID,剩下要做的就是匹配将这些ID与现有加密的.cerber2文件的ID结合起来。完成此操作后,您将在加密的.cerber2文件与存储在Dropbox历史记录中的原始解密文件之间建立映射。只需还原旧文件并删除由病毒创建的文件即可。

  1. Here's where things get a bit hairy when it comes to API calls. For each of the deleted files, you need to fetch a list of revisions, using dropbox.Dropbox.files_list_revisions. Take the first revision, which will be the newest, and store its ID alongside the file path. This is how we get an ID for a deleted file.
  2. Now that we (hopefully) have an ID for each deleted file in your folder/Dropbox, all that's left to do is to match up those IDs with the IDs of the existing encrypted .cerber2 files. Once you've done that, you'll have a mapping between the encrypted .cerber2 file and the original, decrypted file stored in your Dropbox history. Simply restore the old file and delete the files created by the virus.

我故意将实际的实现方式交给您,但希望对您有所帮助。

I've purposefully left the actual implementation in code up to you, but I hope this helps.

这篇关于使用Dropbox API还原已删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆