How to recover deleted iPython Notebooks

2019-02-12 23:37发布

I have iPython Notebook through Anaconda. I accidentally deleted an important notebook, and I can't seem to find it in trash (I don't think iPy Notebooks go to the trash).

Does anyone know how I can recover the notebook? I am using Mac OS X.

Thanks!

8条回答
手持菜刀,她持情操
2楼-- · 2019-02-12 23:50

Sadly my file was neither in the checkpoints directory, nor chromium's cache. Fortunately, I had an ext4 formatted file system and was able to recover my file using extundelete:

  1. Figure out the drive your missing deleted file was stored on:

    df /your/deleted/file/diretory/

  2. Switch to a folder located on another you have write access to:

    cd /your/alternate/location/

  3. It is proffered to run extundlete on an unmounted partition. Thus, if your deleted file wasn't stored on the same drive as your operating system, it's recommended you unmount the partition of the deleted file (though you may want to ensure extundlete is already installed before proceeding):

    sudo umount /dev/sdax where sdax is the partition returned by your df command earlier

  4. Use extundelete to restore your file:

    sudo extundelete --restore-file /your/deleted/file/diretory/delted.file /dev/sdax

  5. If successful your recovered file will be located at:

    /your/alternate/location/your/deleted/file/diretory/delted.file

查看更多
时光不老,我们不散
3楼-- · 2019-02-12 23:52

This is bit of additional info on the answer by Thuener,

I did the following to recover my deleted .ipynb file.

  1. The cache is in ~/.cache/chromium/Default/Cache/ (I use chromium)
  2. used grep in binary search mode, grep -a 'import math' (replace search string by a keyword specific in your code)
  3. Edit the binary file in vim (it doesn't open in gedit)
    • The python ipynb should file start with '{ "cells":' and
    • ends with '"nbformat": 4, "nbformat_minor": 2}'
    • remove everything outside these start and end points
  4. Rename the file as .ipynb, open it in your jupyter-notebook, it works.
查看更多
Fickle 薄情
4楼-- · 2019-02-12 23:55

The "delete" functionality now sends the file to OS trash rather than permanently deleting it, see this PR: https://github.com/jupyter/notebook/pull/1968. So you can just open your Trash (wherever that is on your system) and restore it.

查看更多
SAY GOODBYE
5楼-- · 2019-02-12 23:58

If you're using windows, it sends it to the recycle bin, thankfully. Clearly, it's a good idea to make checkpoints.

查看更多
不美不萌又怎样
6楼-- · 2019-02-13 00:00

If you use PyCharm, you can do the following.

  1. Open the Local History view.

  2. Select the version you want to roll back to.

  3. On the context menu of the selection, choose Revert.

Worked for me!

Source: here

查看更多
ら.Afraid
7楼-- · 2019-02-13 00:06

For the unlucky ones like me, that delete some files on JuliaBox(jupyter for julia), there is a solution. I successifly recovery all my deleted files.

The browsers strore cache information about the pages you visit. You have to find your cache browser folder (in ubuntu with crhome was ~/.cache/google-chrome/Default/Cache) and grep for some text of your notebook in the binarys. Then, cut the text part of the file that is correspond to your ipynb.

https://groups.google.com/forum/#!searchin/julia-box/delete%7Csort:relevance/julia-box/Rt9LG9RldrU/3s_vVSrivJEJ

查看更多
登录 后发表回答