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?
5 Answers
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.
-
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. Commented Mar 30, 2020 at 14:32
-
1Turns out soft-deleting things is a hard problem to solve AND is not GDPR compliant. drupal.org/i/2725447 Commented Nov 12, 2020 at 14:44
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.
-
6Extra tip: for a dedicated tab and more control over who can unpublish what, check out the Publish Content module: drupal.org/project/publishcontent Commented Mar 11, 2011 at 11:42
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
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.
- Create a new empty MySQL database called "restore" or "testing" or something similar
- Create a new manual backup so you can revert to this moment, not last night's backup if you need to
- Import your backup into the new "restore" database
- Go to the
node
table, search for your deleted node. Hopefully you know the nid, but if you don't figure it out now. - Select the one row that was deleted and export via phpMyAdmin. There should be just one row.
- 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. - Go back to your live site's database in phpMyadmin
- Import the two files you just exported from the backup
- 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.
-
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. Commented Mar 13, 2017 at 14:48
I am.late , but answer is use entity backup module https://www.drupal.org/project/entity_backup