Skip to content

Commit 5462c5a

Browse files
committed
implement archive and rsync of configs
if configured the script will tar up the configs and, if needed, rsync them separately. Issue #28
1 parent 803832b commit 5462c5a

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ sshKeyPath=""
6868
## $remoteServer path for gitlab backups
6969
remoteDest="/var/opt/gitlab/backups"
7070

71+
## set $localConfDir
72+
# blank disables conf backups
73+
# you can create /var/opt/gitlab/backups/configBackups --
74+
# gitlab doesn't seem to complain with a subfolder
75+
# in there. Plus it will rsync up with the backup.
76+
# So you won't need to enable a separate rsync run
77+
localConfDir="/var/opt/gitlab/backups/configBackups"
78+
79+
## set $remoteServer path for gitlab configs
80+
# blank disables remote copy
81+
# unless $localConfDir is outside /var/opt/gitlab/backups/configBackups
82+
# you can leave this blank
83+
remoteConfDest=""
84+
7185
## Using the CI server?
7286
# change to true or 1 to enable CI backups
7387
enableCIBackup="0"
@@ -90,6 +104,10 @@ RVM_envPath=""
90104
remoteModule=""
91105
rsync_password_file=""
92106

107+
## only change if configs are in different locations. (unlikely)
108+
localConfig="/etc/gitlab"
109+
localsshkeys="/var/opt/gitlab/.ssh"
110+
93111
## Check remote quota
94112
# change to true or 1 to enable
95113
checkQuota="0"

auto-gitlab-backup.conf.sample

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ sshKeyPath=""
1212
## $remoteServer path for gitlab backups
1313
remoteDest="/var/opt/gitlab/backups"
1414

15+
## set $localConfDir
16+
# blank disables conf backups
17+
# you can create /var/opt/gitlab/backups/configBackups --
18+
# gitlab doesn't seem to complain with a subfolder
19+
# in there. Plus it will rsync up with the backup.
20+
# So you won't need to enable a separate rsync run
21+
localConfDir="/var/opt/gitlab/backups/configBackups"
22+
23+
## set $remoteServer path for gitlab configs
24+
# blank disables remote copy
25+
# unless $localConfDir is outside /var/opt/gitlab/backups/configBackups
26+
# you can leave this blank
27+
remoteConfDest=""
28+
1529
## Using the CI server?
1630
# change to true or 1 to enable CI backups
1731
enableCIBackup="0"
@@ -34,6 +48,16 @@ RVM_envPath=""
3448
remoteModule=""
3549
rsync_password_file=""
3650

51+
## localbackup directories
52+
# only change if gitlab_rails['backup_path'] in gitlab.rb is set
53+
# other than $gitHome/[backups|ci-backups]
54+
gitRakeBackups="/var/opt/gitlab/backups"
55+
gitRakeCIBackups="/var/opt/gitlab/ci-backups"
56+
57+
## only change if configs are in different locations. (unlikely)
58+
localConfig="/etc/gitlab"
59+
localsshkeys="/var/opt/gitlab/.ssh"
60+
3761
## Check remote quota
3862
# change to true or 1 to enable
3963
checkQuota="0"

auto-gitlab-backup.sh

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
3838
gitHome="$(awk -F: -v v="git" '{if ($1==v) print $6}' /etc/passwd)"
3939
gitlabHome="$gitHome/gitlab"
4040
gitlab_rails="/opt/gitlab/embedded/service/gitlab-rails"
41-
gitRakeBackups="/var/opt/gitlab/backups"
42-
gitRakeCIBackups="/var/opt/gitlab/ci-backups"
4341
PDIR=$(dirname $(readlink -f $0))
42+
dateStamp=`date +"%F %H:%m:%S"`
4443
confFile="$PDIR/auto-gitlab-backup.conf"
4544
rakeBackup="gitlab-rake gitlab:backup:create"
4645
rakeCIBackup="gitlab-ci-rake backup:create"
@@ -74,6 +73,20 @@ checkSize() {
7473
echo
7574
}
7675

76+
archiveConfig() {
77+
echo ===== Archiving Configs =====
78+
if [ -w $localConfDir ]
79+
then
80+
tar -czf $localConfDir/gitlabConf-$dateStamp.tgz $localConfig $localsshkeys
81+
82+
# remove files not within 3 days
83+
find $localConfDir -type f -mtime +3 -exec rm {} \;
84+
85+
else
86+
echo "Local configs aren't enabled or $localConfDir is not writable."
87+
fi
88+
}
89+
7790
rakeBackup() {
7891
echo ===== raking a backup =====
7992
cd $gitRakeBackups
@@ -103,6 +116,15 @@ rsyncUp() {
103116
echo -e "Start rsync to \n$remoteServer:$ciRemoteDest\ndefault key\n"
104117
rsync -Cavz --delete-after -e "ssh -p$remotePort" $gitRakeCIBackups/ $remoteUser@$remoteServer:$ciRemoteDest
105118
fi
119+
120+
# config rsync
121+
if [ ! -z $remoteConfDest ]
122+
then
123+
echo ===== rsync a config backup =====
124+
echo =============================================================
125+
echo -e "Start rsync to \n$remoteServer:$remoteConfDest\ndefault key\n"
126+
rsync -Cavz --delete-after -e "ssh -p$remotePort" $localConfDir/ $remoteUser@$remoteServer:$remoteConfDest
127+
fi
106128
}
107129

108130
rsyncUp_dryrun() {
@@ -119,6 +141,15 @@ rsyncUp_dryrun() {
119141
echo -e "Start rsync to \n$remoteServer:$ciRemoteDest\ndefault key\n"
120142
rsync --dry-run -Cavz --delete-after -e "ssh -p$remotePort" $gitRakeCIBackups/ $remoteUser@$remoteServer:$ciRemoteDest
121143
fi
144+
145+
# config rsync
146+
if [ ! -z $remoteConfDest ]
147+
then
148+
echo ===== rsync a config backup =====
149+
echo =============================================================
150+
echo -e "Start dry run rsync to \n$remoteServer:$remoteConfDest\ndefault key\n"
151+
rsync --dry-run -Cavz --delete-after -e "ssh -p$remotePort" $localConfDir/ $remoteUser@$remoteServer:$remoteConfDest
152+
fi
122153
}
123154

124155
rsyncKey() {
@@ -134,6 +165,15 @@ rsyncKey() {
134165
echo -e "Start rsync to \n$remoteServer:$ciRemoteDest\nwith specific key\n"
135166
rsync -Cavz --delete-after -e "ssh -i $sshKeyPath -p$remotePort" $gitRakeCIBackups/ $remoteUser@$remoteServer:$ciRemoteDest
136167
fi
168+
169+
# config rsync
170+
if [ ! -z $remoteConfDest ]
171+
then
172+
echo ===== rsync a config backup =====
173+
echo =============================================================
174+
echo -e "Start rsync to \n$remoteServer:$remoteConfDest\ndefault key\n"
175+
rsync -Cavz --delete-after -e "ssh -p$remotePort" $localConfDir/ $remoteUser@$remoteServer:$remoteConfDest
176+
fi
137177
}
138178

139179
rsyncKey_dryrun() {
@@ -149,6 +189,15 @@ rsyncKey_dryrun() {
149189
echo -e "Start rsync to \n$remoteServer:$ciRemoteDest\nwith specific key\n"
150190
rsync --dry-run -Cavz --delete-after -e "ssh -i $sshKeyPath -p$remotePort" $gitRakeCIBackups/ $remoteUser@$remoteServer:$ciRemoteDest
151191
fi
192+
193+
# config rsync
194+
if [ ! -z $remoteConfDest ]
195+
then
196+
echo ===== rsync a config backup =====
197+
echo =============================================================
198+
echo -e "Start rsync to \n$remoteServer:$remoteConfDest\ndefault key\n"
199+
rsync --dry-run -Cavz --delete-after -e "ssh -p$remotePort" $localConfDir/ $remoteUser@$remoteServer:$remoteConfDest
200+
fi
152201
}
153202

154203

@@ -167,6 +216,14 @@ rsyncDaemon() {
167216
rsync -Cavz --port=$remotePort --password-file=$rsync_password_file --delete-after /$gitRakeCIBackups/ $remoteUser@$remoteServer::$remoteCIModule
168217
fi
169218

219+
# config rsync
220+
if [ ! -z $remoteConfDest ]
221+
then
222+
echo ===== rsync a config backup =====
223+
echo =============================================================
224+
echo -e "Start rsync to \n$remoteServer:$remoteConfDest\ndefault key\n"
225+
rsync -Cavz --delete-after -e "ssh -p$remotePort" $localConfDir/ $remoteUser@$remoteServer:$remoteConfDest
226+
fi
170227
}
171228

172229
rsyncDaemon_dryrun() {
@@ -184,6 +241,14 @@ rsyncDaemon_dryrun() {
184241
rsync --dry-run -Cavz --port=$remotePort --password-file=$rsync_password_file --delete-after /$gitRakeCIBackups/ $remoteUser@$remoteServer::$remoteCIModule
185242
fi
186243

244+
# config rsync
245+
if [ ! -z $remoteConfDest ]
246+
then
247+
echo ===== rsync a config backup =====
248+
echo =============================================================
249+
echo -e "Start rsync to \n$remoteServer:$remoteConfDest\ndefault key\n"
250+
rsync --dry-run -Cavz --delete-after -e "ssh -p$remotePort" $localConfDir/ $remoteUser@$remoteServer:$remoteConfDest
251+
fi
187252
}
188253

189254

0 commit comments

Comments
 (0)