forked from AnalogJ/you-dont-know-jenkins-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1002.periodic-backups.groovy
27 lines (25 loc) · 1.1 KB
/
1002.periodic-backups.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import jenkins.model.*;
import org.jenkinsci.plugins.periodicbackup.*;
println "///////////////////////////////////////////////////////////////////////////"
println "Init Hook: Periodic backups"
println "///////////////////////////////////////////////////////////////////////////"
def jenkins_config_backup_path = '/var/jenkins_config_backup'
def periodicBackup = PeriodicBackupLink.get()
periodicBackup.setTempDirectory('/tmp/jenkins_backup_temp')
periodicBackup.setCron('0 10 * * *')
periodicBackup.setCycleQuantity(30)
periodicBackup.setCycleDays(30)
periodicBackup.setFileManagerPlugin(new ConfigOnly())
def periodicBackupStorages = periodicBackup.getStorages()
if(periodicBackupStorages.size() == 0){
periodicBackupStorages.add(new TarGzStorage())
}
def periodicBackupLocations = periodicBackup.getLocations()
if(periodicBackupLocations.size() == 0){
periodicBackupLocations.add(new LocalDirectory(new File(jenkins_config_backup_path),true))
}
else{
periodicBackupLocations[0].setPath(new File(jenkins_config_backup_path))
}
println(periodicBackupLocations[0].getPath())
periodicBackup.save()