How to restore deleted dataset?

Hello -

new truenas scale (V 23.10.2) user here. I have accidentally deleted my dataset. Is there any way to recover the data (apart from restoring the existing backup)? I have already read some older posts in various forums, but these usually refer to older/other truenas or freenas versions.

Many thanks for your help

In general no.

ZFS snapshots can help with deleted files in a dataset. But, you can’t delete a dataset unless it has no snapshots. So, in your case, no.

There is a complex method of exporting your pool and potentially re-importing the pool, preferably R/O, (Read Only), rolling back ZFS write transactions that may make your deleted dataset visible. However, it depends on the amount of changes made in the pool. Too many changes, and the pointers to a ZFS write transaction are no longer available.

In the future, you might investigate ZFS Pool Checkpoints. That WOULD allow rolling back, though all new changes to the pool would be lost. So a backup before any Checkpoint roll back should be considered.

1 Like

Yeah, little hope of recovering a destroyed dataset other than from backups. That’s why the GUI makes you type in the dataset’s name before allowing you to destroy it.

3 Likes

Thank you very much for your help so far.

I should probably add that I made no further changes to Truenas after I realized my mishap. I immediately shut down the NAS.

I found an article online that explains how to recover a dataset, but before I do something stupid, I’d like someone to evaluate this article in terms of its usefulness with Truena’s Scale.
https://endlesspuzzle.com/how-to-recover-a-destroyed-dataset-on-a-zfs-pool/

Otherwise, there’s Klennet ZFS Recovery, a software I stumbled across in several threads dealing with the same topic. Useful?

I assume the ability to recover via zpool checkpoints is not yet available, is it?

It is available (at the CLI), but you’d need to have made a checkpoint before destroying the dataset.

Vote for this ticket.

Forum thread for reference.

More so than anything else, but everything else has zero usefulness, so it’s not a high bar. Experiences are very mixed.

If you shut the system down right away, I’d say the odds are good that some zdb incantation would be able to roll it back–but I don’t have a clue what that incantation would be.

Yes, if you shutdown immediately after, you have a reasonable chance of full recovery.

That article seems reasonable, except that you have to import the pool to get the pool history. Based on that, I would use the following, all from the command line unless specified otherwise;

  1. Arrange to boot without the pool auto-importing, (which would be R/W, potentially bad at this stage).
  2. Manually import the pool R/O.
  3. Get the pool history, and the ZFS write transaction ID for the dataset destroy
  4. Export the pool
  5. Import the pool R/W using the specific ZFS write transaction ID you got from step 3.
  6. Verify that the pool is good to go in regards to the formerly destroyed dataset.
  7. Export the pool
  8. Import the pool from the GUI, check if looks good. Potentially rebooting to restore any shares or apps using the pool or it’s datasets.

Now I’ve left off specific commands and options as I have not done this before, BUT, the concept is very sound.

Caveats:

  • The pool import with the specific ZFS write transaction ID has to be R/W. Otherwise when you export the pool, the destroyed dataset is still destroyed on any simple import of the pool.
  • You loose any writes that occurred after the dataset destroy, however, you said you made none, so that should not be a problem. (I mention it for future readers with a similar problem, but DO want to preserve later written data.)
  • The GUI / TrueNAS middleware won’t know anything about what you are doing from the command line. Thus, ignore the GUI / TrueNAS for the moment. This is all underlying ZFS work on the command line.
  • All TrueNAS users should have a basic understanding of ZFS, and what it can and can’t do. ZFS is not the end all to solve all problems… but it does have greater data integrity that anything else out their at present. And, it is the only file system and RAID manager that TrueNAS supports.
2 Likes