Jenkins Backup and Restore via CronJob¶
The Jenkins Backup and Restore functionality allows for the automated archiving of Jenkins data using a Kubernetes CronJob. This feature is typically configured via the official Jenkins Helm Chart to ensure that critical configuration and job data are preserved on a scheduled basis^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md].
Overview¶
When enabled, the chart creates a Kubernetes CronJob that executes a backup task at a defined interval^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. This mechanism helps prevent data loss by periodically copying data to a persistent destination.
Configuration¶
The backup behavior is controlled by values under the backup key in the Helm chart configuration^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md].
Core Settings¶
backup.enabled: Determines whether the backup CronJob is created^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. Default isfalse.backup.schedule: Defines the Cron schedule for the backup job^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. Default is0 2 * * *(daily at 2:00 AM).backup.destination: Specifies the target location for the backup artifacts^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. The default iss3://jenkins-data/backup.
Job Scope¶
The configuration allows for filtering the specific data included in the backup^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]:
backup.onlyJobs: When set totrue, the backup process only archives the job folder. If set tofalse, it backs up the entire Jenkins home directory. Default isfalse.
container and Resources¶
The CronJob utilizes a specific container image to perform the backup tasks^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]:
- Image: Defaults to
maorfr/kube-taskswith tag0.2.0^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. - Resources: Default resource requests are set to a memory limit of
1Giand a CPU limit of1^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md].
Cloud Credentials¶
To support backups to cloud storage providers like AWS, Azure, or GCP, the configuration allows mapping existing Kubernetes Secrets to environment variables^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]:
backup.existingSecret: Used to specify the name of the secret containing credentials^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md].- AWS: Mappings for
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. - Azure: Mappings for
AZURE_STORAGE_ACCOUNTandAZURE_STORAGE_ACCESS_KEY^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]. - GCP: Mounts a secret as a volume and sets
GOOGLE_APPLICATION_CREDENTIALS^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md].
Related Concepts¶
- [[流程化筆記]]: Maintaining documentation for backup and restore procedures ensures reliability and reduces repetitive work during disaster recovery.
- 20/80學習原則: Understanding the essential 20% of Helm chart values (like
backup.enabledanddestination) allows for quick configuration without mastering every parameter. - [[23种经典设计模式]]: The creation of a backup task can be viewed as an application of the Singleton or Template Method patterns within the infrastructure automation context.
Sources¶
^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__VALUES_SUMMARY.md]