diff --git a/jenkins/backupWinschoten.yml b/jenkins/backupWinschoten.yml index 012d429..b6801ed 100644 --- a/jenkins/backupWinschoten.yml +++ b/jenkins/backupWinschoten.yml @@ -4,8 +4,10 @@ pipeline { stage ('Run Backup to David') { steps { script { - sh "cp ${keyfile} ${WORKSPACE}/keyfile" - sh "rsync -v -a -e 'ssh -i /home/backupwinschoten/.ssh/id_rsa -p 9897' --delete --info=progress2 ${env.borglocation} backupwinschoten@localhost:/storage/" + withCredentials([sshUserPrivateKey(credentialsId: 'backupwinschoten', keyFileVariable: 'keyfile', passphraseVariable: 'passphrase', usernameVariable: 'user')]) { + sh "cp ${keyfile} ${WORKSPACE}/keyfile" + sh "rsync -v -a -e 'ssh -i /home/backupwinschoten/.ssh/id_rsa -p 9897' --delete --info=progress2 ${env.borglocation} backupwinschoten@localhost:/storage/" + } } } } diff --git a/jenkins/other_location_backup.yml b/jenkins/other_location_backup.yml new file mode 100644 index 0000000..5496167 --- /dev/null +++ b/jenkins/other_location_backup.yml @@ -0,0 +1,38 @@ +pipeline { + parameters { + booleanParam(name: 'UseLocationPrefix', defaultValue: params.backuplocally ?: true, description: 'Use the environmental backup location') + string(name: 'directory', defaultValue: params.directory ?: ' ', description: 'The directory that should be handled') + string(name: 'agentname', defaultValue: params.agentname ?: 'julien', description: 'The agent to run this backup on') + text(name: 'excludelist', defaultValue: params.excludelist ?: '**/cache/** ', description: 'Multiline string to exclude patterns from backup') + } + agent { label params['agentname'] } + environment { + BORG_RELOCATED_REPO_ACCESS_IS_OK = 'yes' + backdirectory = "${directory}" + } + + stages { + stage('Run Preparation') { + steps { + script { + if (params.UseLocationPrefix) { + backdirectory = env.borglocation + "/" + "${directory}" + } + echo "Backing up directory ${backdirectory}" + sh "echo '${params.excludelist}' >> excludelist" + } + } + } + + stage('Create local BorgBackup') { + steps { + script { + withCredentials([string(credentialsId: 'cbce976a-0d98-4f35-8ea2-1f7818931bc3', variable: 'BORG_PASSPHRASE')]) { + sh "borg create --progress --stats --exclude-from excludelist ${backdirectory}::${java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('dd-MM-yyyy_HH:mm'))} ${backdirectory}" + sh "borg prune --list --keep-daily 31 --keep-weekly 48 ${backdirectory}" + } + } + } + } + } +}