Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it viable to handle MySQL backups with git?

Tags:

Today I had this really neat idea for backing up my database: put the dump file in a git repository, then commit on each dump so that I have both the most recent copy, but can easily roll back to any previous backup. I can also easily pull a copy of the repository on a regular basis to keep a copy on my own computer as a backup of the backups. It definitely sounds clever.

However, I'm aware that clever solutions sometimes have fundamental flaws. What sort of issues might I hit storing mysqldump diffs in git? Is it worth it? What do most people do in order to have multiple database backups on the server and keep redundant copies elsewhere?

like image 526
Matchu Avatar asked Nov 23 '10 22:11

Matchu


People also ask

Can git be used for backups?

git bundle is can be used for backup purposes. It will create a single file containing all the refs you need to export from your local repository. For one branch, it's simple. This command will create a myrepo.

What is the best way to backup MySQL database?

To back up a MySQL database, you can use either third-party tools or execute the mysqldump command from the command line. mysqldump is a command-line utility used to generate a MySQL logical database backup. It creates a single . sql file that contains a set of SQL statements.


2 Answers

Normally you don't keep every backup (or snapshot) forever. A git repository does keep every checkin you ever make. If you ever decide to prune old revisions (say month-old revisions down to once a week, year old to once a month, etc) you will have to do it with git filter-branch which will rewrite the entire history. Then git gc to remove the unwanted revisions.

Given that git's strengths are distributed version control and complex patch/branch workflows (neither of which apply to snapshots or backups) I'd consider using a different VCS with a more malleable history.

like image 113
Ben Jackson Avatar answered Oct 07 '22 16:10

Ben Jackson


This approach sounds fine to me. I use Git for backing up my own important data.

Note that you are not storing diffs -- Git effectively stores snapshots of the directory state with each commit. You can generate the diff of two commits, but the actual storage mechanism has nothing to do with diff.

like image 22
cdhowie Avatar answered Oct 07 '22 16:10

cdhowie