我不小心删除了我的AWS Sagemaker实例上的jupyter笔记本文件。我想知道是否还可以还原/恢复文件?
答案 0 :(得分:0)
好吧,首先检查{notebook_directory}/.ipynb_checkpoints/
的快照。该目录应包含您上次保存笔记本时的笔记本副本。
如果不存在,则IPython内核会将发出的命令保存在sqlite数据库中。在~/.ipython/profile_default
中找到。在那里,您应该找到 history.sqlite 。
history.sqlite应该包含发布给ipython内核的所有命令。感兴趣的表是会话和历史记录。
您需要按会话开始时间或结束时间查询会话表,以确定哪些会话与您要查找的会话相关:
select
sessions.session, sessions.start, sessions.end, history.source
from sessions
join history using (session)
where
start > 'your_start_date' and start < 'your_end_date';
找到会话后
select '# @@ Cell '|| line || char(10) || source || char(10) from history where session = your_session_number;
将查询输出到.py,然后使用jupytext转换为ipynb,然后将笔记本放回原处:
sqlite3 history.sqlite \
"select '# @@ Cell '|| line || char(10) || source || char(10) from history where session = your_session_number;" \
> output.py