blob: 6d0a54bf49b2e025e4c31d1a45ab7a2b54c72625 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# Backing Up a Git Repository
> Sun 13th June 2021 By David T. Sadler.
Below is a quick and dirty way in which I backup all my repositories that are hosted at git.davidtsadler.com.
```shell
#!/bin/sh
DATE_PREFIX=$(date +%Y%m%d)
BACKUP_DIRECTORY=/tmp
BACKUP_FILE="${BACKUP_DIRECTORY}/${DATE_PREFIX}-repositories.tar.gz"
BACKUP_FILES="${BACKUP_DIRECTORY}/*-repositories.tar.gz"
REPOSITORIES=/home/git/*.git
tar -czf $BACKUP_FILE $REPOSITORIES
find $BACKUP_FILES -mtime +3 -delete
exit 0
```
All it does it tar and gzip any .git directories found under /home/git. It also removes any backups that are more than three days old.
This script has been saved as /usr/bin/backup_repositories and is ran daily via cron.
```cron
0 3 * * * /usr/bin/backup_repositories > /dev/null 2>&1
```
It is important to know that this backup strategy is far from ideal for repositories that are heavily used as you run the high risk of trying to backup a repository as users are pushing to it. As git updates a repository in two phases this will lead to a backup that may not contain all the data and so won't be suitable for restoring. However its fine for my purposes since I'm the only user and it's unlikely that I will be making changes during the time the backup is running.
### Links
=> /posts/git/2021-05-29/setting-up-a-self-host-git-server/ 2021-05-29 - Setting up a Self Hosted Git Server
=> /posts/git/ Git - Read More Posts.
I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.
=> mailto:david@davidtsadler.com Email david@davidtsadler.com
### License
=> https://creativecommons.org/licenses/by-sa/4.0/ The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Copyright © 2021 David T. Sadler.
=> / Return to Homepage.
|