17

While revisions are kept and it is easy to get back to a previous revision of a node, I was wondering if it is possible to restore a node that has really been deleted by a user?

20

If you have a database backup (which you should ;) you can restore an old copy of the site and retrieve it that way.

Drupal does give users quite a clear warning that deleting a node is final, and there is a confirmation dialog.

| improve this answer | |
  • Why does drupal handle it this way? Why not implement a "trash can" so it is a two step process to delete something permanently. This is how Wordpress handles it. Once that trash can is empty, you can't get it back. – Robbiegod Mar 30 at 14:32
  • Turns out soft-deleting things is a hard problem to solve AND is not GDPR compliant. drupal.org/i/2725447 – JamesWilson Nov 12 at 14:44
19

What Chris says. The code reads

    db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
    db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);

...so deleted really means deleted.

To prevent accidents like this, you may want to restrict user permissions so users cannot delete, but only unpublish nodes. Unpublished nodes will not show up on your site (assuming that your site is built correctly) but they remain available in the database.

| improve this answer | |
2

Yes there are several solutions for this.

  • The first one is using full backups which has already been mentioned by Chris here. this is the most difficult one specially if the node contains complex fields.
  • Using https://drupal.org/project/recover module, which monitors
  • Using https://drupal.org/project/entity_soft_delete module. It created sort of a recycle/trashbin for nodes/entities so when a particular node gets deleted, it won't be removed from the database only its status changes to deleted. So the admin can still see or even use it and if required change its status back to normal or delete it permanently
| improve this answer | |
0

Here is a suggestion building on what Chris said that reverse engineers @marcvangend's answer. I like to use phpMyAdmin, but you can do this same process with the command line if you like that better.

Like the other answers, this assumes you have a backup of your database. No excuse not to with awesome modules like Backup & Migrate out there.

  1. Create a new empty MySQL database called "restore" or "testing" or something similar
  2. Create a new manual backup so you can revert to this moment, not last night's backup if you need to
  3. Import your backup into the new "restore" database
  4. Go to the node table, search for your deleted node. Hopefully you know the nid, but if you don't figure it out now.
  5. Select the one row that was deleted and export via phpMyAdmin. There should be just one row.
  6. Now go to the node_revisions table. Search on the nid of your deleted node and export. There should be at least one row, but could be more. Export everything with your nid.
  7. Go back to your live site's database in phpMyadmin
  8. Import the two files you just exported from the backup
  9. Check your work on the live site

Using this method will allow you to restore the single node from the backup without loosing any changes to the database since the last backup. If you're not concerned about that and you don't think anything but the deletion has happened since the last backup, it would be easier to just do a full restore of the last backup that to undergo the process above.

| improve this answer | |
  • What if I go to the node table and do not see the deleted nid there? Does this mean things look grim? The site is Drupal 8, by the way. – MadPhysicist Mar 13 '17 at 14:48
0

I am.late , but answer is use entity backup module https://www.drupal.org/project/entity_backup

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.