Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering a Jenkins backup from the command line with the Backup plugin

The problem

backup policies on my network imply giving a path to backup and an optional command to run just before, so that I can prepare the backup

I need to backup my Jenkins configuration. Simply giving a path to the Jenkins data directory is not an option as:

  1. I just need to backup the configuration
  2. the total disk usage for that directory, ~ 80GB, is far beyond reasonable backup size (99% consist of non-critical workspace data)

So far

I installed the Backup Plugin and found reasonably good settings for it. Now I wonder if I can trigger it remotely using a bash script. I understand that using curl on the /jenkins/backup/launchBackup url should do the trick, but I'm getting a 403 Forbidden error as I'm hitting the URI as an anonymous user, and couldn't find a solution to login or get around this.

So does anyone knows of a simple way to trigger a configuration only backup from the command line ?

like image 544
Erwan Queffélec Avatar asked Nov 16 '12 14:11

Erwan Queffélec


2 Answers

The Jenkins wiki describes how to perform an authenticated login in scripts. Short answer: Go to the Configure screen from your user page and get the API token, then use it as your password when running your script.

I haven't tried it with the Backup plugin, but it works for running regular builds so it should work for any scriptable invocation.

Without authentication:

$ curl http://jenkins:8080/job/my%20job/build
[ HTML page saying "Authentication required" ]

With authentication:

$ curl --user dbacher:$MY_API_TOKEN http://jenkins:8080/job/my%20job/build
[ returns nothing and the build starts ]

Update: fixed the jobs typo, thanks for the comments.

like image 129
Dave Bacher Avatar answered Sep 28 '22 17:09

Dave Bacher


Dave Bacher's answer didn't work for me. I needed to do:

$ curl http://jenkins:8080/job/MY_JOB_NAME/build?build

It's job, not jobs, and I needed the ?build on the end.

like image 36
Steve Mariotti Avatar answered Sep 28 '22 18:09

Steve Mariotti