Backing up manually

2 minute read

This chapter provides guidance for backing up your $JENKINS_HOME directory.

If you are using CloudBees CI, you also have the option to use the CloudBees Backup Plugin for backup and recovery.

If you are performing a manual backup of CloudBees CI or Jenkins, the recommended manual backup process is to schedule a cron job on a regular cadence to create a tarball of your $JENKINS_HOME directory.

The basic steps for backup:

  1. Determine what you want to backup using the Explaining $JENKINS_HOME lesson.

  2. Determine how often you want to backup your $JENKINS_HOME.

  3. Determine how you want to schedule the backup (cron is recommended if available).

  4. Consider our Best practices for backup and restore.

There is no need to stop Jenkins when performing a backup.

Things to consider:

  • Refer to Explaining $JENKINS_HOME to determine what you want to include in your backup.

  • Store backup files on a different server for better security and in case of data corruption.

  • Store backup files on a different network for better security and in case of data corruption.

CloudBees CI on traditional platforms

In CloudBees CI on traditional platforms, you can backup $JENKINS_HOME manually using the following command. In the following example, you are directly logged in (remotely via SSH or physically on the machine at a command-line terminal):

  1. Navigate to your $JENKINS_HOME configuration from the command line:

    cd $JENKINS_HOME
  2. Create a compressed file:

tar -czvf /backups/jenkins_home/production-backup-2021-10-26.tar.gz .
The CloudBees Backup Plugin steps you through creating an operations center job for both backup and recovery. Even if you prefer to create your backups manually, consider setting it up as an operations center job that backs up everything across all controllers.

Kubernetes

If running in Kubernetes, and your pod is still up and running, you can back it up manually using the following commands. In the following example, the controller is called production:

kubectl get pods -n cloudbees-ci kubectl exec -n cloudbees-ci -it production-0 -- sh cd /var tar -cf - jenkins_home/ | gzip > /tmp/production-backup-2020-10-06.tar.gz exit kubectl cp -n cloudbees-ci production-0:/tmp/production-backup-2020-10-06.tar.gz ./production-backup-2020-10-06.tar.gz du -m ./production-backup-2020-10-06.tar.gz