https://github.com/sue445/jenkins-backup-script
archive jenkins setting and plugins
https://github.com/sue445/jenkins-backup-script
jenkins shell
Last synced: about 1 year ago
JSON representation
archive jenkins setting and plugins
- Host: GitHub
- URL: https://github.com/sue445/jenkins-backup-script
- Owner: sue445
- License: mit
- Created: 2013-12-07T15:10:25.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2025-04-27T20:45:40.000Z (about 1 year ago)
- Last Synced: 2025-04-27T21:30:44.776Z (about 1 year ago)
- Topics: jenkins, shell
- Language: Ruby
- Homepage: http://sue445.hatenablog.com/entry/2013/12/08/005317
- Size: 364 KB
- Stars: 486
- Watchers: 19
- Forks: 433
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Jenkins backup script
[](https://github.com/sue445/jenkins-backup-script/actions/workflows/test.yml)
Archive Jenkins settings and plugins
* `$JENKINS_HOME/*.xml`
* `$JENKINS_HOME/*.jks`
* `$JENKINS_HOME/jobs/*/*.xml`
* `$JENKINS_HOME/nodes/*`
* `$JENKINS_HOME/plugins/*.jpi`
* `$JENKINS_HOME/secrets/*`
* `$JENKINS_HOME/users/*`
# Usage
```sh
./jenkins-backup.sh /path/to/jenkins_home archive.tar.gz
# add timestamp suffix
./jenkins-backup.sh /path/to/jenkins_home backup_`date +"%Y%m%d%H%M%S"`.tar.gz
```
# run with Jenkins Job
## 1. install Exclusive Execution Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Exclusive+Execution+Plugin
## 2. New Job

## 3. Configure
### Source Code Management > Repository URL
```
https://github.com/sue445/jenkins-backup-script.git
```
* **Recommended** : specify Branch Specifier with latest release tag
* Check https://github.com/sue445/jenkins-backup-script/releases

### Build Triggers > Build periodically

### Build Environment > Set exclusive Execution

### Build > Execute shell

ex.
```bash
./jenkins-backup.sh $JENKINS_HOME /path/to/backup_`date +"%Y%m%d%H%M%S"`.tar.gz
```
# Operability confirmed
* Debian wheezy
* Debian jessie
* Debian stretch
* Debian buster
* CentOS 6
* CentOS 7
## Testing
requirements [Docker](https://www.docker.com/)
```sh
bundle install
bundle exec itamae docker --node-yaml=spec/node.yml spec/recipes/bootstrap.rb --image=centos:7 --tag local:latest
DOCKER_IMAGE=local:latest bundle exec rspec
```
# Tips
## rotate backup files
```bash
# keep backup with latest 30 days
find /path/to/backup_* -mtime +30 -delete
```
## Restore commands
example
```bash
sudo /etc/init.d/jenkins stop
cd /path/to/backup_dir
tar xzvf backup.tar.gz
sudo cp -R jenkins-backup/* /path/to/jenkins/
sudo chown jenkins:jenkins -R /path/to/jenkins/
sudo /etc/init.d/jenkins start
```
# Changelog
[CHANGELOG.md](CHANGELOG.md)