I version control mysql database dumps from websites with git.
With --skip-extended-insert, so each record is on it's own line, it works quite well to track changes. It also allows me to pull old versions of the database from history and import them.
Is there a way to tell git to ignore certain lines or lines containing certain patterns?
Git is file based, it will not modify the contents of tracked files to derive diffs.
Don't include tables/data in the db dumps that you don't care for. If it's not there creating differences, you don't need to take extra steps to ignore/correct for it.
So if for example, the problem is deleted articles that you don't want to backup, remove them from the backup process:
mysqldump -c -w "articles.deleted IS NULL" articles > backup.sql
Post process the database dump to remove things you don't care for. As an example, here's an extract from a db dump helper script I use:
#!/bin/bash
mysqldump -dRC --skip-dump-date --skip-add-drop-table --default-character-set=utf8 database $@ > schema.sql
sed -i 's/ AUTO_INCREMENT=[0-9]\+//' schema.sql
This example (for illustration only) removes autoincrement values from create table statements so that they don't generate differences in the (version controlled) schema.sql file.
If git cannot do this, the two solutions I see are:
Modify the script I use to dump the database to remove things that are irrelevant to version control. (drawback: removing some of these things might cause the dump to no longer be viable for import)
Store each database dump somewhere else (maybe named by commitID somehow within a hook) and version control a modified version.
e.g.,cat dump.sql | grep -v "_session" >> dump.sql
,
but it would be ideal if I could add a grep like this to git somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With