Um, let's back up a bit :) It's not like I have never thought of what you mention. I've already explained my thinking about tables. Now let me explain my thinking about the residual two points in your post: handling file / directory removal and commonality of the requested features.
Your use case is NOT the most common one, I'm afraid. Even if I include the file system structure that you mentioned in passing it is something that has come up a grand total of six times in the nearly twelve years I'm doing this. That's why dealing with it was low on my priorities. I do, however, done extensive research into it and have two pending to-do items.
Now bear with me for a second because I have to explain the thinking behind handling filesystem removal. The operating assumption in my research was that it was to be handled by the restoration script. This is an important point and a big fallacy as it turns out.
Remember that you extract the backup archive before you restore it. So what you really need to do is a TRIPLE pass just to determine which files and folders to remove. Once to go through the backup archive to get a list of the files present in the archive. Two, list the filesystem situation. Three, find the files in the second set which don't belong in the first set. This requires 10MB of memory and several dozen seconds for a small site. This is an O(N^2) problem so things get exponentially worse the more files you have.
I know this is a stupid idea because that's how JoomlaPack 1.0 worked back in 2006; it'd run a first pass to determine what to back up and then run a second pass to copy everything into an uncompressed TAR archive. It'd take 10+ minutes to back up a tiny site and would fail on anything real-world. I had to write a proper backup engine for JoomlaPack 1.1 and then refactor it to Hell and back in 1.2 to get improve the backup speed by an order of magnitude.
So I already know that just figuring out what to delete is going to fail spectacularly - and I even know why and how. But let's pretend I am naive or insane and went with it.
Now the question is, how do you delete all those files. You can't do it in a single page load because of PHP and Apache timeouts. If you follow that line of thought you end up... with Akeeba Engine (the backup engine), namely its file-only backup mode. The only difference is that instead of an archiver which creates backup archives you have one which delete files. Now we've hit another roadblock. The Engine is big and complex, hardly what you want to have in a restoration script. Not only does it add bloat and a thick layer of JavaScript to use it, it also requires configuration. Suddenly the restoration becomes this complicated hot mess which requires you to fiddle with settings for several minutes before you can restore your site. And you will fail. And you have to retry. And these settings cannot be saved since the restoration script is transient. That's how you lose 99% of your users. The 1% remaining will have by now figured out that it's really dumb to spend all that time in the restoration interface when FTP and SFTP have been around literally for decades, are easier to grasp and take more than an order of magnitude less time.
But let's pretend I am thicker than a brick wall and want to go with it anyway. Ownership and permissions of the files to be deleted. Right. How do I deal with that? Of course, the Hybrid filesystem engine in Kickstart! Only that you need to configure it and you need to get it right. Otherwise here's another point of configuration failure you have to endure. Don't assume that because you run PHP under FastCGI and / or know what you're doing everyone else does too. It's hardly the case as 12 years of experience has taught me, the very hard way.
You know what this thing is called? Overengineered. There are two universal truths about overengineering: it always fails spectacularly and it's never the sign of intelligence on the engineer's part. I have worked long enough as a business consultant, mechanical engineer and software engineer to attest to the veracity of this axiom based on mistakes I've seen and I've done. That's the good thing about mistakes though: I get to learn from them and not repeat them.
The more I was thinking about this the more evident it became that this is getting out of hand and we're essentially writing a massive and fragile application just to restore a site to what would amount restoring it on brand new hosting.
Whoa. Wait. Brand new hosting? Is it that simple?
It turns out that if you definitely want to go back to the exact state of the backup -nothing added or removed- there is a simple way:
1. Delete all files from your web root using FTP, SFTP or even cPanel. Time to complete: 1'.
2. Delete all tables from your database using phpMyAdmin (again accessible through cPanel). Time to complete: 1'.
3. Restore the backup using Kickstart. Time to complete: 5' or less (our s l o w video tutorial is a testament to that).
Step 3 is already automated in code. Doing a cost / benefit analysis it turns out that steps 1 and 2 can be somewhat automated for specific use cases which do match yours.
Step 1 is on my to-do list since December and it amounts to this: "Add an option to Kickstart to delete all files and folders EXCEPT itself, the archive and its temporary directory". Even if you live in Permissions Hell, Kickstart has the Hybrid file write option which can be used for file deletion as well. The problem amounts to creating a recursive filesystem deletion which can save its state, a problem already solved in the Akeeba Engine and which probably can be ported in a concise form. Had I not spent 2+ months writing a GDPR compliance solution from scratch I'd have already done the research and probably implemented this feature already.
Step 2 is also on my to-do list and it amounts to a "Drop all tables" option in ANGIE. The sticky point was foreign keys and non-table entities. The former is straightforward: tell MySQL to ignore foreign keys and drop one table after the other. The latter is more complicated and won't be implemented: if you have functions, stored procedures or triggers they are not going to be automatically removed (hence "drop all tables"). Dropping them requires listing them which is really complicated as we know from building the backup engine.
The whole reason for these two features is to provide a quick "start over" feature in Kickstart. This cannot be implemented in the integrated restoration from the Manage Backups page because you would be leaving stuff behind, of the variety which has security implications (the removal of all files would make it impossible for the extraction script to know how to remove the restoration.php file which unlocks restore.php for over-the-web access, something which can be used over the span of several days / months to crack its encryption scheme and upload arbitrary code to your site).
So, while it's not exactly the same as manually removing everything and restoring a backup it would be really darned close and for your use case it'd be just fine. The whole point is finding time to do that. Frankly, it's a low priority item for me since it's an unusual use case AND it has a viable if manual workaround for those few people who want it. In the end of the day feature implementation is the cross section of a popularity contest and engineering sprint. If only I could code the features I find interesting on a technical level, not just the ones that actually sell subscriptions and earn me a living :(
Sorry for another long post and for being probably less coherent than usual. I'm just back from a transatlantic trip, meaning I got 2 hours of bad sleep on an airplane seat the size of a matchbox in the last 24 hours or so.
Nicholas K. Dionysopoulos
Lead Developer and Director
🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!