Skip to main content

Backup MySQL using Git-Hooks

Category: Git
git-logo

By using Git-Hooks you can easily add dumps to a commit.

First we need to add our pre-commit hook:

nano /repo/.git/hooks/pre-commit

Within the created file we simply add the following shell-code:

#!/bin/bash
mysqldump -u user -ppassword --skip-extended-insert database > /repo/database.sql
cd /repo
git add database.sql

At least we need to make the script executeable:

chmod +x /repo/.git/hooks/pre-commit