-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_jenkins.sh
executable file
·45 lines (35 loc) · 1.24 KB
/
backup_jenkins.sh
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
#!/bin/bash
###This script is used to mirror the jenkins jobs log on RackHD Jenkins to cloud
set -e
set -x
sync_files(){
local files_number=0
rm -rf rsync_log
rsync "$@" 2>&1|tee rsync_log
files_number=$(cat rsync_log |awk '/Number of regular files transferred/{print $NF}')
echo "$files_number"
}
#start to pull jobs in jenkins server to jump server
opt="-ravzh --stats --exclude Maglev-BRI-Test --exclude sandbox"
#current jobs in jenkins server
source1=${[email protected]:/var/lib/jenkins/jobs/}
#old builds of jobs in jenkins server
source2=${[email protected]:/mnt/nfsroot/var/lib/jenkins/jobs/}
#destination directory of jumper server
dest=${JUMPER_DIR-/var/lib/jenkins/jobs}
case $dest in
*/)dest=${dest%/};;
esac
sync_files $opt $source1 $dest
sync_files $opt $source2 $dest
#cloud host username:ip
cloud_host=${[email protected]}
#directory of jobs on cloud
cloud_jobs=${[email protected]:/var/lib/jenkins/jobs}
dest="${dest}/"
sync_files $opt $dest $cloud_jobs
#if any file is transfered to cloud, the jenkins service should be force reload
#if [ "$files_transfered" -gt 0 ];
#then
# ssh $cloud_host "service jenkins force-reload"
#fi