Search code examples
mysqlbackupmariadbrestorerecycle

MYSQL/MardiaDB 'recycle bin'


I'm using MardiaDB and i'm wondering if there is a way how to install a 'recycle bin' on my server where if someone deleted a table or anything it gets shifted to the recycle bin and restoring it is easy.

Not talking about mounting things to restore it and all that stuff but litterly a 'save place' where it gets stored (i have more then enough space) until i decide to delete it or just keep it there for 24 hours.

Any thoughts?


Solution

  • No such feature exists. http://bugs.mysql.com takes "feature requests".

    Such a feature would necessarily involve MySQL; it cannot be done entirely in the OS's filesystem. This is because a running mysql caches information in RAM that the FS does not know about. And because the information about a table/db/proc/trigger/etc is not located entirely in a single file. Instead extra info exists in other, more general, files.

    With MyISAM, your goal was partially possible in the fs. A MyISAM table was composed of 3 files: .frm, .MYD',.MYI`. Still MySQL would need to flush something to forget that it know about the table before the fs could move the 3 files somewhere else. MyISAM is going away; so don't even think about using that 'Engine'.

    In InnoDB, a table is composed of a .ibd file (if using file_per_table) plus a .frm file, plus some info in the communal ibdata1 file. If the table is PARTITIONed, the layout is more complex.

    In version 8.0, most of the previous paragraph will become incorrect -- a major change is occurring.

    "Transactions" are a way of undoing writes to a table...

    BEGIN;
    INSERT/UPDATE/DELETE/etc...
    if ( change-mind )
        then ROLLBACK;
        else COMMIT;
    

    Effectively, the undo log acts as a recycle bin -- but only at the record level, and only until you execute COMMIT.

    MySQL 8.0 will add the ability to have DDL statements (eg, DROP TABLE) in a transaction. But, again, it is only until COMMIT.

    Think of COMMIT as flushing the recycle bin.