From ed5f6b571ef6ac8b3f303dcc41c0cac1ed0be58b Mon Sep 17 00:00:00 2001 From: matthias Date: Sun, 18 Jan 2026 16:50:11 +0100 Subject: [PATCH] Added more backup steps --- jenkins/nextcloud_database.yml | 76 ++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/jenkins/nextcloud_database.yml b/jenkins/nextcloud_database.yml index 3aa9fca..1570d65 100644 --- a/jenkins/nextcloud_database.yml +++ b/jenkins/nextcloud_database.yml @@ -1,7 +1,25 @@ 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 { @@ -11,9 +29,61 @@ pipeline { } } steps { - 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" + 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" + } + } } } }