I'm creating MySQL dump of 5 databases every hour. 3 of those databases very rarely change, so creating a MySQL dump for those 3 dbs is pretty much a waste of time and resources.
Is there a way I can retrieve a unix epoch seconds of when a specific db was last changed/updated? I would compare it with latest dump file and only dump another one if there are changes.
So question again: How can I get the unix epoch datetime of last update/change of a specific database?
Only works for MyISAM tables
You can run a MySQL query against the information_schema table:
Example (replace dbname with your database name):
I use:
Regards!
it's not exactly answer to what you are looking for, but i think that's what you need: enable binary logging, backup binlogs and create full dumps once a week or so.
There is a tool from Maatkit that can do quick checksums on tables. It is mk-table-checksum
You could probably lock the tables, run mk-table-checksum and store the checksums, then unlock the tables and then look at the values to see if you need to run mysqldump or not.
The way I do this is not automated: you have to still read the modified times, but FWIW...
This will list the the modified times for the four tables shown in parentheses.
I found this metod, from http://mysqladministrators.blogspot.it/2012/02/get-database-size.html
I'm not sure if it could help you, since i'm not so prepared in MySql
Get the database size, free space and last update
To get the current database size just by querying into your query browser or CLI from the INFORMATION_SCHEMA database in table TABLES.
Get the database free space
Get the database last update ordered by update time then by create time.
Due to not being able to get update_time for innodb tables I check the db files directly:
This gives me days which I use to verify tables are inactive and can be archived.
You are looking for unix timestamp which just needs a change to ls's time-style:
This assumes your database files are in /var/lib/mysql but you can get that location by running the following query:
This question comes up from time to time and the short answer is that this information cannot be reliably obtained by any one method for the simple reason that it is not necessarily recorded.
For MyISAM tables you can use the query Phil posted. I don't know about any of the others but for InnoDB at least there is no query that will return the information you want. In this case you might consider using triggers to record the timestamp in a table whenever the data is changed but realistically the performance loss will most likely be greater that just going ahead with the dump.