Here’s a bash script which will back up all repositories on a self hosted Jira and BitBucket server
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 | #!/bin/bash
FTPSERVER=backup-server-ip-or-hostname
FTPUSER=ftpusername
FTPPASS=ftppassword
DAY=</span>date +%A<span style="color: #4070a0">
ftp -4vpn $FTPSERVER <<ENDFOO
user $FTPUSER $FTPPASS
prompt
mdelete $DAY*
quit
ENDFOO
cd /tmp
echo "Backing up yesterdays Jira backups"
# Back up yesterday's Jira backups
for i in $(ls -1 /var/atlassian/application-data/jira/export | grep </span>date -d yesterday +%Y-%b-%d<span style="color: #4070a0"> ); do
ftp -4vpn $FTPSERVER <<ENDFOO
user $FTPUSER $FTPPASS
put /var/atlassian/application-data/jira/export/$i $i
prompt
mdelete date -d "last month" +%Y-%b-%d
quit
ENDFOO
done
echo "Backing up today's backup"
for i in $(ls -1 /var/atlassian/application-data/jira/export | grep </span>date +%Y-%b-%d<span style="color: #4070a0"> ); do
ftp -4vpn $FTPSERVER <<ENDFOO
user $FTPUSER $FTPPASS
put /var/atlassian/application-data/jira/export/$i $i
quit
ENDFOO
done
echo "Backing up Jira attachments"
tar -czf /tmp/$DAY-var-atlassian-application-data-jira-data.tgz /var/atlassian/application-data/jira/data
ftp -4vpn $FTPSERVER <<ENDFOO
user $FTPUSER $FTPPASS
put /tmp/$DAY-var-atlassian-application-dara-jira-data.tgz $DAY-var-atlassian-application-dara-jira-data.tgz
quit
ENDFOO
rm -f /tmp/$DAY-var-atlassian-application-dara-jira-data.tgz
#####
#
# Back up all repos
#
#####
for i in </span>curl -q https://**BitbucketServer**/rest/api/1.0/repos<span style="color: #4070a0; font-weight: bold">\?</span>limit<span style="color: #4070a0; font-weight: bold">\=</span>2000 | grep -Eo <span style="color: #4070a0">"(http|https)://[a-zA-Z0-9./?i@=_-]*"</span> | grep git<span style="color: #4070a0"> ; do
i=</span><span style="color: #007020">echo</span> <span style="color: #bb60d5">$i</span> | sed <span style="color: #4070a0">"s/username@//g"
echo $i
PROJECT=</span><span style="color: #007020">echo</span> <span style="color: #bb60d5">$i</span> | cut -d/ -f5<span style="color: #4070a0"> REPO=</span><span style="color: #007020">echo</span> <span style="color: #bb60d5">$i</span> | cut -d/ -f6<span style="color: #4070a0">
echo "Backing up $REPO from project $PROJECT"
git clone –bare "$i" /tmp/$REPO && tar -czf "/tmp/$DAY-$PROJECT_$REPO.tar.gz" "/tmp/$REPO" >/dev/null
if [ $? -ne 0 ]; then
echo -e "Subject: FAILED BACKUP\n\n$PROJECT_$REPO failed backup" | sendmail erroremailaddress@foo.com
else
ftp -4vpn $FTPSERVER <<ENDFOO
user $FTPUSER $FTPPASS
put /tmp/$DAY-$PROJECT_$REPO.tar.gz $DAY-$PROJECT*$REPO.tar.gz
quit
ENDFOO
rm -fr /tmp/$REPO
rm -f /tmp/$DAY-$PROJECT*$REPO.tar.gz
fi
done
|