Jenkins 주기적으로 remote repository에 백업하기
목적
Jenkins를 주기적으로 백업하여 문제가 생겼을 시 복원이 가능하도록 함
ThinBackup plugin 사용
간단히 Repository에 업로드 할 수 있도록 함
개요
ThinBackup이 새벽 4시에 자동으로 수행되도록 설정
새벽 5-6시에 자동으로 git push하는 job 생성
방법
ThinBackup 설치 및 자동 수행 설정 (cron job 형식으로 지정)
백업 될 장소에 jenkins user가 RW권한 가지도록 chmod
해당 폴더에서 git init 및 기타 git 설정 수행 (username, email 지정, init commit 등)
Push할 remote repository (github나 gitlab)의 access token 발급
내 계정의 access 권한을 가진 PAT가 가장 편할 것 같으니 추천. 이후 방법도 이 기준으로 설명.
발급 받은 PAT를 Jenkins credentials에 추가.
username - password로 저장
username: gitlab 기준으로는 아무거나 상관 없으나, 비어있으면 안됨.
password: 발급 받은 PAT 붙여넣기
Freestyle job 생성
Build Triggers
Build periodically 체크
cron job 형식으로 실행 될 시간 지정
Build Environment
use secret text(s) or file(s) 체크
Add - Username and password (conjoined)
Variable: 실행 될 script에서 해당 값에 접근할 이름 지정
Specific credentials에서 위에서 추가한 credential 지정
Build Steps
Add build step - Execute shell
다음의 script 복붙
#!/bin/bash cd /path/to/your/backup/location git remote set-url origin https://${GIT_PAT}@github.com/address-to-your-git git add . git commit -m "Jenkins ThinBackup - $(date +'%Y-%m-%d %H:%M:%S')" git push
Save
테스트를 위해 ThinBackup 수동 trigger - 생성한 Jenkins job 수동 build 시도