Files
backup/jenkins/nextcloud_database.yml
2026-01-18 16:50:11 +01:00

90 lines
4.4 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 ?: false, 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('Run MariaDB') {
agent {
docker {
image 'mariadb:latest'
args "--volumes-from=jenkins -v /srv/dev-disk-by-uuid-27fc012e-a1fa-4c7c-9dad-82770888cd03/nextcloud_backup/database_dump:/data/ --entrypoint=''"
reuseNode false
}
}
steps {
script {
if (params.backuplocally) {
sh "yes | cp -rf /data/backup_yesterday.dmp /data/backup_early.dmp 2>/dev/null || :"
sh "yes | cp -rf /data/backup_latest.dmp /data/backup_yesterday.dmp 2>/dev/null || :"
sh "mariadb-dump -u nextcloud -h 10.10.1.32 --all-databases -ppassword -v > /data/backup_latest.dmp"
} else {
echo "Local BORG backup creation is skipped"
}
}
}
}
stage('Run rclone') {
agent {
docker {
image 'rclone/rclone'
args "--volumes-from=jenkins -v /srv/dev-disk-by-uuid-27fc012e-a1fa-4c7c-9dad-82770888cd03/nextcloud_backup/database_dump/:/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/nextcloud/database --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"
}
}
}
}
}
}