Skip to content

Instantly share code, notes, and snippets.

@hatan4ik
Forked from toddlers/jenkins_backup.sh
Created January 24, 2019 20:31
Show Gist options
  • Save hatan4ik/be8aaabd8a5d4d49c47f6b6240f1b31d to your computer and use it in GitHub Desktop.
Save hatan4ik/be8aaabd8a5d4d49c47f6b6240f1b31d 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