Git as a backup system?

6 messages, 6 authors, 2016-06-15 · open the first message on its own page

Git as a backup system?

From: Eric Frederich <hidden>
Date: 2016-06-15 22:49:59

I maintain a corporate MediaWiki installation.
Currently I have a cron job that runs daily and tar's up the contents
of the installation directory and runs a mysqldump.
I keep backups of the past 45 days.
Each backup is about 200M, so all in all I always have about 9.0G of backups.
Most of the changes are in the database, so the mysqldump file is
changed every day.
Other than that, there can be new files uploaded but they never
change, just get added.
All configuration files stay the same.

I wrote a script that untar'd the contents each backup, gunziped the
mysql dump, and made a git commit.
The resulting .git directory wound up being 837M, but after running a
long (8 minute) "git gc" command, it went down to 204M.

== Questions ==
What mysqldump options would be good to use for storage in git?
Right now I'm not passing any parameters to mysqldump and its doing
all inserts for each table on a single huge line.
Would git handle it better if each insert was on its own line?

Lets say that the repo gets too big and I want to throw away history.
I'd have a linear history with a single commit every day.
Is there a way to take just the last 30 commits and throw away everything else?

Am I insane?  Are there other tools more suited toward this?
I just thought of using Git since I looked at my 9G worth of data out
there in my backup directory that is almost exactly the same and said
"git could handle this well".

Are any of you using git for a backup system?  Have any tips, words of wisdom?

Thanks,
~Eric

Re: Git as a backup system?

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:59

Eric Frederich wrote:
Am I insane?  Are there other tools more suited toward this?
I just thought of using Git since I looked at my 9G worth of data out
there in my backup directory that is almost exactly the same and said
"git could handle this well".
You might like bup: https://github.com/apenwarr/bup#readme

Re: Git as a backup system?

From: Konstantin Khomoutov <hidden>
Date: 2016-06-15 22:49:59

On Mon, 8 Nov 2010 13:01:29 -0500
Eric Frederich [off-list ref] wrote:
I maintain a corporate MediaWiki installation.
Currently I have a cron job that runs daily and tar's up the contents
of the installation directory and runs a mysqldump.
I keep backups of the past 45 days.
Each backup is about 200M, so all in all I always have about 9.0G of
backups. Most of the changes are in the database, so the mysqldump
file is changed every day.
Other than that, there can be new files uploaded but they never
change, just get added.
All configuration files stay the same.
[...]
Am I insane?  Are there other tools more suited toward this?
I just thought of using Git since I looked at my 9G worth of data out
there in my backup directory that is almost exactly the same and said
"git could handle this well".

Are any of you using git for a backup system?  Have any tips, words
of wisdom?
I suspect the rdiff-backup tool [1] was invented precisely for the setup
like yours: it is able to sync one directory to another + create diffs
between them thus providing for incremental backups.

1. http://www.nongnu.org/rdiff-backup/

Re: Git as a backup system?

From: Dirk Süsserott <hidden>
Date: 2016-06-15 22:49:59

Am 08.11.2010 19:01 schrieb Eric Frederich:
I maintain a corporate MediaWiki installation.
Currently I have a cron job that runs daily and tar's up the contents
of the installation directory and runs a mysqldump.

I wrote a script that untar'd the contents each backup, gunziped the
mysql dump, and made a git commit.
The resulting .git directory wound up being 837M, but after running a
long (8 minute) "git gc" command, it went down to 204M.

== Questions ==
What mysqldump options would be good to use for storage in git?
Right now I'm not passing any parameters to mysqldump and its doing
all inserts for each table on a single huge line.
Would git handle it better if each insert was on its own line?

Are any of you using git for a backup system?  Have any tips, words of wisdom?

Thanks,
~Eric
Hi Eric,

I also use mysqldump and Git to make backups of my databases. Indeed, it 
performs much better when each change (insert statement) is on a 
separate line. mysqldump has an option for that which I don't recommend, 
because it dramatically slows down the dump and the restore. It would 
then create separate "insert into ..." statement for each changed line.

For me the attached script worked very well: I pipe the output of 
mysqldump through the script and it simply inserts a linefeed after each 
record.

----------------------------------
#!/usr/bin/perl -p

use strict;
use warnings;

# Before:
# INSERT INTO `schliess_grund` VALUES 
(1,'Explizit'),(2,'Neuanmeldung'),(4,'Sperrung'),(3,'Timeout');
#
# After:
# INSERT INTO `schliess_grund` VALUES
#    (1,'Explizit'),
#    (2,'Neuanmeldung'),
#    (4,'Sperrung'),
#    (3,'Timeout');
if (/^(INSERT INTO .*? VALUES) (.*);$/)
{
     $_ = "$1\n     $2\n    ;\n";
     s/\),\(/\)\n    ,\(/g;
}
----------------------------------

The changeset will be much smaller. Let's call the script "wrap.pl". 
Then run the following:

----------------------------------
mysqldump --opt --routines [...] -r <outfile.tmp> <dbname>
./wrap.pl <outfile.tmp> > <outfile>; rm <outfile.tmp>
git add <outfile>
if ! git diff-index --quiet HEAD --; then
     git commit -m "Backup of ..."
fi
----------------------------------

Try it out!

Cheers,
     Dirk

Re: Git as a backup system?

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:49:59

On Mon, Nov 8, 2010 at 19:01, Eric Frederich [off-list ref] wrote:
I maintain a corporate MediaWiki installation.
Currently I have a cron job that runs daily and tar's up the contents
of the installation directory and runs a mysqldump.
I keep backups of the past 45 days.
Each backup is about 200M, so all in all I always have about 9.0G of backups.
Most of the changes are in the database, so the mysqldump file is
changed every day.
Other than that, there can be new files uploaded but they never
change, just get added.
All configuration files stay the same.

I wrote a script that untar'd the contents each backup, gunziped the
mysql dump, and made a git commit.
The resulting .git directory wound up being 837M, but after running a
long (8 minute) "git gc" command, it went down to 204M.

== Questions ==
What mysqldump options would be good to use for storage in git?
Right now I'm not passing any parameters to mysqldump and its doing
all inserts for each table on a single huge line.
Would git handle it better if each insert was on its own line?
I use git to back up all my data. It works great. But how big the
dumps get depends very much on the database.

Here's a graph of the size of my mysql backup directories:
http://munin.nix.is/nix.is/v.nix.is/dirs_var_backup_mysql.html

I use this little wrapper script:
https://github.com/avar/linode-etc/blob/master/bin/cron/mysqldump-to-git-all

Which calls this:
https://github.com/avar/linode-etc/blob/master/bin/cron/sqldump-to-git

I find with MySQL --skip-extended-insert and --compact work really well.

Then I use this to repack + gc the repos:
https://github.com/avar/linode-etc/blob/master/bin/cron/git-repack-and-gc-dir

Re: Git as a backup system?

From: Patrick Rouleau <hidden>
Date: 2016-06-15 22:49:59

Eric Frederich <eric.frederich <at> gmail.com> writes:
Are any of you using git for a backup system?  Have any tips, words of wisdom?
I had the same idea to backup a MySQL database with git.

To be able to easily drop old "backups", I have choose to go with monthly 
branches: each month, the previous month's branch is checked out and a new 
branch is created; each year, the previous year is checked out...

This is running only for 5 weeks, but so far it works pretty well.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help