Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Copies certain kinds of known files and directories from a given Jenkins master directory
  4. # into a git repo, removing any old ones, adds 'em, commits 'em, pushes 'em.
  5. set -ex
  6.  
  7. if [ $# -ne 3 ]; then
  8. echo usage: $0 jenkins_home hg_repos_url hg_repos_name
  9. exit 1
  10. fi
  11.  
  12. JENKINS_HOME=$1
  13. HG_REMOTE_URL=$2
  14. HG_REPOS_NAME=$3
  15.  
  16. rm -rf ${HG_REPOS_NAME}
  17. hg clone ${HG_REMOTE_URL}
  18.  
  19. rsync -ahv --delete \
  20. --exclude="jobConfigHistory" \
  21. --exclude="config-history" \
  22. --exclude="war" \
  23. --exclude=".hudson" \
  24. --exclude=".ivy2" \
  25. --exclude=".m2" \
  26. --exclude="lost+found" \
  27. --include="*config.xml" \
  28. --include="jobs/*/builds/*/log" \
  29. --include="users/*" \
  30. --include="*.hpi" \
  31. --include="*.jpi" \
  32. --include="*pinned" \
  33. --include="*disabled" \
  34. --include="scriptler/*" \
  35. --include="secrets/*" \
  36. --include="*.xml" \
  37. --include="*.key" \
  38. --exclude="*" \
  39. --prune-empty-dirs ${JENKINS_HOME}/ ${HG_REPOS_NAME}
  40.  
  41. hg --cwd "${HG_REPOS_NAME}" add --all . ; \
  42. hg --cwd "${HG_REPOS_NAME}" ci -m "Jenkins ${JENKINS_MASTER} config backup @ $(date)" && \
  43. hg --cwd "${HG_REPOS_NAME}" push
  44.  
  45. ## example
  46. # ./jenkins-git-backup.sh jenkins@10.0.2.196:/var/lib/jenkins git@git.oschina.net:choldrim/deepin-jenkins-git.git deepin-jenkins-git
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement