1 Git as a Backup Solution
2 ========================
3 :author: Aaron Ball
4 :email: nullspoon@iohq.net
5
6
7 == {doctitle}
8
9 To preface this post, I would like to point out two very key things. The backup
10 files will be stored in two branches inside of a single repository. Those
11 branches will be called "files" and "database". You may choose to use other
12 names (such as database and master) but for the purposes of this post, the
13 afforementioned names will be used.
14
15 If it suits you better, you could also use two git repositories. I used that
16 for a while and it worked great. I just found it more convenient to have the
17 database dumps and the wiki files in one repository for simplicity.
18
19 [[files-checkin]]
20 Files Checkin
21 -------------
22
23 This will catch all upgrades, uploads, settings file changes, etc.
24 Anything you change on the actual filesystem where your wiki is stored
25 will be commited to the repository.
26
27 ----
28 export repo = 127.0.0.1
29 # Check in the files
30 cd /path/to/your/wiki
31
32 # Add all new, edited, and deleted files
33 git add . -A
34 # Commit our changes
35 git commit -m "Routine Checkin"
36 # Push the commit to the files branch of our repository
37 git push origin files
38 ----
39
40
41 [[database-checkin]]
42 Database Checkin
43 ----------------
44
45 For this we are going to take a database dump and overwrite the old one
46 with it. We will then check in the same file, but with the changes.
47 Again, any changes made to pages, users, logs, etc will be in the dump
48 file and thus will be commited to the repository.
49
50 ----
51 dbFileName = "wiki.data.sql"
52 $password = "CheckMeYo"
53 $dumpPath = /path/to/dump/backups/
54 mysqldump -u wikiUser -p$pass 'databaseName' > $dumpPath$dbFileName
55 cd $dumpPath
56 git add . -A
57 git commit -m "Routine Checkin"
58 # Push the commit to the database branch of our repository
59 git push origin database
60 ----
61
62
63 [[restoring-from-backups]]
64 Restoring from Backups
65 ----------------------
66
67 Restoring from a backup is actually quite simple. All one needs to do is
68 fetch the repository (origin).
69
70 * Firstly, pull the database branch and run a mysqlimport on the dump
71 file.
72 * Secondly, to get the files (and overwrite any current files), do a
73
74 ----
75 git pull --rebase origin files
76 ----
77
78 and the most recent version of the files branch will show up in the current
79 directory.
80
81 Also, if you worry someone will download your .git directory contents, you can
82 just move the .git directory out when you aren't doing backups and back in
83 temporarily for a backup.
84
85
86 [[size-concerns]]
87 Size Concerns
88 -------------
89
90 Git has the capability to compress repositories using the *git gc* command.
91 This will have git go back through all of the commits in the working repository
92 and compress them in the context of all of the other commits. Currently my wiki
93 plaintext database dump is 50 megabytes. It has been checked in to the
94 repository 18 times and the entire repository is about 17.5 megabytes after a
95 "git gc". Neat, huh?
96
97
98 Category:Git
99 Category:Backups
100
101
102 // vim: set syntax=asciidoc:
|