Auto-archive MariaDB10 database table
The perhaps obvious solution would be to modify step 3: Don't just delete all rows from the active table. Instead, find a column you can use as an indicator of whether the rows are newer or older than the most recent row that will be copied to the archive table/database.

This column can be e.g. an integer used for the primary key column, or if you don't have that, perhaps a timestamp column.

So instead of deleting every row, you can do something like:

DELETE FROM active_table WHERE id &lt;= @maxIdThatWasArchived; 


Or something like:

DELETE FROM active_table WHERE ts &lt;= @maxTimeStampThatWasArchived;