Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created January 14, 2015 07:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save toddlers/a6e9a38f0867e1e70518 to your computer and use it in GitHub Desktop.
Save toddlers/a6e9a38f0867e1e70518 to your computer and use it in GitHub Desktop.
Jenkins_Bacup via jenkins
# Delete all files in the workspace
rm -rf *
# Create a directory for the job definitions
mkdir -p $BUILD_ID/jobs
# Copy global configuration files into the workspace
cp $JENKINS_HOME/*.xml $BUILD_ID/
# Copy keys and secrets into the workspace
cp $JENKINS_HOME/identity.key.enc $BUILD_ID/
cp $JENKINS_HOME/secret.key $BUILD_ID/
cp $JENKINS_HOME/secret.key.not-so-secret $BUILD_ID/
cp -r $JENKINS_HOME/secrets $BUILD_ID/
# Copy user configuration files into the workspace
cp -r $JENKINS_HOME/users $BUILD_ID/
# Copy job definitions into the workspace
rsync -am --include='config.xml' --include='*/' --prune-empty-dirs --exclude='*' $JENKINS_HOME/jobs/ $BUILD_ID/jobs/
# Create an archive from all copied files (since the S3 plugin cannot copy folders recursively)
tar czf $BUILD_ID.tar.gz $BUILD_ID/
# Remove the directory so only the archive gets copied to S3
rm -rf $BUILD_ID
# uploading the build to s3 bucket, post build action is a bitch !!
#/usr/bin/s3cmd put /var/lib/jenkins/workspace/jenkins_backup/$BUILD_ID.tar.gz s3://<bucket_name>/jenkins/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment