db script rebuild
This commit is contained in:
@@ -1,75 +1,48 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
parameters {
|
parameters {
|
||||||
booleanParam(name: 'backuplocally', defaultValue: params.backuplocally ?: false, description: 'If true local BORG backup will be created')
|
booleanParam(name: 'UseLocationPrefix', defaultValue: params.backuplocally ?: true, description: 'Use the environmental backup location')
|
||||||
booleanParam(name: 'backuptodavid', defaultValue: params.backuptodavid ?: false, description: 'If true rsync the BORG repository to David')
|
string(name: 'directory', defaultValue: params.directory ?: ' ', description: 'The directory that should be handled')
|
||||||
booleanParam(name: 'backuptowinschoten', defaultValue: params.backuptowinschoten ?: false, description: 'If true rsync the BORG repository to our Winschoten backup system')
|
string(name: 'agentname', defaultValue: params.agentname ?: 'julien', description: 'The agent to run this backup on')
|
||||||
|
}
|
||||||
|
environment {
|
||||||
|
BORG_RELOCATED_REPO_ACCESS_IS_OK = 'yes'
|
||||||
|
backdirectory = "${directory}"
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Run Information') {
|
stage('Run Preparation') {
|
||||||
steps {
|
steps {
|
||||||
echo "Local BORG backup creation is ${params.backuplocally}"
|
script {
|
||||||
echo "Backup to David is ${params.backuptodavid}"
|
if (params.UseLocationPrefix) {
|
||||||
echo "Backup to Winschoten PI is ${params.backuptowinschoten}"
|
backdirectory = env.borglocation + "/" + "${directory}"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
stage('Run MariaDB') {
|
stage('Run MariaDB') {
|
||||||
agent {
|
agent {
|
||||||
docker {
|
docker {
|
||||||
image 'mariadb:latest'
|
image 'mariadb:latest'
|
||||||
args "--volumes-from=jenkins -v /srv/dev-disk-by-uuid-27fc012e-a1fa-4c7c-9dad-82770888cd03/nextcloud_backup/database_dump:/data/ --entrypoint=''"
|
args "--volumes-from=jenkins -v /tmp/database_dump:/data/ --entrypoint=''"
|
||||||
reuseNode false
|
reuseNode false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
if (params.backuplocally) {
|
sh "mariadb-dump -u nextcloud -h 10.10.1.32 --all-databases -ppassword -v > /data/nextcloud_database.dmp"
|
||||||
sh "yes | cp -rf /data/backup_previous.dmp /data/backup_early.dmp 2>/dev/null || :"
|
|
||||||
sh "yes | cp -rf /data/backup_latest.dmp /data/backup_previous.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 backup creation is skipped"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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('Rsync Backup in Parallel') {
|
|
||||||
failFast false
|
|
||||||
parallel {
|
|
||||||
stage ('Run Backup to David') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
if (params.backuptodavid) {
|
|
||||||
sh "ssh -p 664 matthias@home.daf2000.nl yes | cp -rf /media/disk/nextcloudbackup/database_dump/backup_previous.dmp /media/disk/nextcloudbackup/database_dump/backup_early.dmp 2>/dev/null || :"
|
|
||||||
sh "ssh -p 664 matthias@home.daf2000.nl yes | cp -rf /media/disk/nextcloudbackup/database_dump/backup_latest.dmp /media/disk/nextcloudbackup/database_dump/backup_previous.dmp 2>/dev/null || :"
|
|
||||||
sh "rsync -v -a -e 'ssh -p 664' --delete --bwlimit=3000 --info=progress2 --exclude='.*' /srv/dev-disk-by-uuid-27fc012e-a1fa-4c7c-9dad-82770888cd03/nextcloud_backup/database_dump/ matthias@home.daf2000.nl:/media/disk/nextcloudbackup/database_dump/"
|
|
||||||
} else {
|
|
||||||
echo "Backup to David is skipped"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
stage ('Run Backup to Winschoten') {
|
}
|
||||||
steps {
|
}
|
||||||
script {
|
stage('Create local BorgBackup') {
|
||||||
if (params.backuptowinschoten) {
|
steps {
|
||||||
sh "ssh -p 9897 backupwinschoten@localhost yes | cp -rf /storage/nextcloud_backup/database_dump/backup_previous.dmp /storage/nextcloud_backup/database_dump/backup_early.dmp 2>/dev/null || :"
|
script {
|
||||||
sh "ssh -p 9897 backupwinschoten@localhost yes | cp -rf /storage/nextcloud_backup/database_dump/backup_latest.dmp /storage/nextcloud_backup/database_dump/backup_previous.dmp 2>/dev/null || :"
|
withCredentials([string(credentialsId: 'cbce976a-0d98-4f35-8ea2-1f7818931bc3', variable: 'BORG_PASSPHRASE')]) {
|
||||||
sh "rsync -v -a -e 'ssh -i /home/backupwinschoten/.ssh/id_rsa -p 9897' --delete --info=progress2 /srv/dev-disk-by-uuid-27fc012e-a1fa-4c7c-9dad-82770888cd03/nextcloud_backup/database_dump/ backupwinschoten@localhost:/storage/nextcloud_backup/database_dump/"
|
sh "borg create --progress --stats ${env.borglocation}/nextcloud_database::${java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern('dd-MM-yyyy_HH:mm'))} /tmp/database_dump"
|
||||||
} else {
|
sh "borg prune --list --keep-daily 31 --keep-weekly 48 ${env.borglocation}/nextcloud_database"
|
||||||
echo "Backup to Winschoten is skipped"
|
sh "rm -rf /tmp/database_dump"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user