91 lines
4.6 KiB
YAML
91 lines
4.6 KiB
YAML
pipeline {
|
|
agent any
|
|
parameters {
|
|
booleanParam(name: 'backuplocally', defaultValue: params.backuplocally ?: false, description: 'If true local BORG backup will be created')
|
|
booleanParam(name: 'backuptostackstorage', defaultValue: params.backuptostackstorage ?:false, description: 'If true backup data to TransIP Stack')
|
|
booleanParam(name: 'backuptodavid', defaultValue: params.backuptodavid ?:false, description: 'If true rsync the BORG repository to David')
|
|
booleanParam(name: 'backuptopi', defaultValue: params.backuptopi ?:alse, description: 'If true rsync the BORG repository to our ExternalPI')
|
|
string(name: 'directory', defaultValue: params.directory ?: ' ', description: 'The directory that should be handled')
|
|
text(name: 'excludelist', defaultValue: params.excludelist ?: '**/cache/** ', description: 'Multiline string to exclude patterns from backup')
|
|
}
|
|
stages {
|
|
stage('Run Information') {
|
|
steps {
|
|
echo "Backing up directory ${env.storagelocation}/${directory}"
|
|
echo "Local BORG backup creation is ${params.backuplocally}"
|
|
echo "Backup to TransIP Stack is ${params.backuptostackstorage}"
|
|
echo "Backup to David is ${params.backuptodavid}"
|
|
echo "Backup to External PI is ${params.backuptopi}"
|
|
sh "echo '${params.excludelist}' >> excludelist"
|
|
}
|
|
}
|
|
stage('Getting RClone Configuration') {
|
|
steps {
|
|
configFileProvider([configFile(fileId: 'e0237193-1245-452e-b035-9d3d501f4c1b', variable: 'rclone_config')]) {
|
|
sh "mkdir -p ${WORKSPACE}/config"
|
|
sh "cp ${rclone_config} ${WORKSPACE}/config/rclone.conf"
|
|
}
|
|
}
|
|
}
|
|
stage('Create local BorgBackup'){
|
|
steps {
|
|
script {
|
|
if (params.backuplocally) {
|
|
withCredentials([string(credentialsId: 'cbce976a-0d98-4f35-8ea2-1f7818931bc3', variable: 'BORG_PASSPHRASE')]) {
|
|
sh "borg create --progress --stats --exclude-from excludelist ${env.borglocation}/${directory}::${java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('dd-MM-yyyy_HH:mm'))} ${env.storagelocation}/${directory}"
|
|
sh "borg prune --list --keep-daily 31 --keep-weekly 48 ${env.borglocation}/${directory}"
|
|
}
|
|
} else {
|
|
echo "Local BORG backup creation is skipped"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Run rclone') {
|
|
agent {
|
|
docker {
|
|
image 'rclone/rclone'
|
|
args "--volumes-from=jenkins -v ${env.storagelocation}/${directory}/:/data/ --entrypoint=''"
|
|
reuseNode true
|
|
}
|
|
}
|
|
steps {
|
|
script {
|
|
if (params.backuptostackstorage) {
|
|
sh "mkdir -p /config/rclone"
|
|
sh "cp ${WORKSPACE}/config/rclone.conf /config/rclone/"
|
|
sh "rclone copy -v /data/ stackstorage:/julien/storage/${directory} --exclude-from excludelist"
|
|
} else {
|
|
echo "Backup to TransIP Stack is skipped"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Run Rsync to David') {
|
|
steps {
|
|
script {
|
|
if (params.backuptodavid) {
|
|
sh "rsync -v -a -e 'ssh -p 664' --delete --bwlimit=3000 --info=progress2 ${env.borglocation}/${directory} matthias@home.daf2000.nl:/media/disk/borgbackup/${directory}"
|
|
} else {
|
|
echo "Backup to David is skipped"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Run Rsync to External PI') {
|
|
steps {
|
|
script {
|
|
if (params.backuptopi) {
|
|
withCredentials([sshUserPrivateKey(credentialsId: '095cc365-ac40-4ddb-a078-2fa403092de0', keyFileVariable: 'keyfile', passphraseVariable: 'passphrase', usernameVariable: 'user')]) {
|
|
sh "cp ${keyfile} ${WORKSPACE}/keyfile"
|
|
sh "rsync -v -a -e 'ssh -i /home/borgbackup/.ssh/id_rsa -p 9898' --delete --info=progress2 ${env.borglocation}/${directory} borgbackup@localhost:/borgbackup/${directory}"
|
|
}
|
|
} else {
|
|
echo "Backup to External PI is skipped"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|