205 lines
6.6 KiB
Groovy
205 lines
6.6 KiB
Groovy
import java.text.SimpleDateFormat
|
|
import groovy.transform.Field
|
|
@Field List props = []
|
|
|
|
pipeline {
|
|
agent none
|
|
|
|
parameters {
|
|
choice(
|
|
name: 'ACTION',
|
|
choices: ['ALL','WEB','LINUX'],
|
|
description: 'Выбор бэкапа'
|
|
)
|
|
}
|
|
|
|
options {
|
|
disableConcurrentBuilds()
|
|
timestamps()
|
|
buildDiscarder(logRotator(numToKeepStr: '10'))
|
|
skipDefaultCheckout()
|
|
timeout(time: 2400, unit: 'MINUTES')
|
|
}
|
|
environment {
|
|
BUILD_USER = getBuildUser()
|
|
CURRENT_DATE = new Date().format( 'dd.MM.yy_HH:mm' )
|
|
}
|
|
|
|
|
|
triggers{
|
|
parameterizedCron('''
|
|
00 21 * * 5 %ACTION=WEB
|
|
''')
|
|
}
|
|
|
|
|
|
stages {
|
|
|
|
stage('Prepare_ASTAROT') {
|
|
agent {label "site"}
|
|
steps {
|
|
deleteDir()
|
|
gitClone("master")
|
|
}
|
|
}
|
|
|
|
|
|
stage('WEB_BACKUP') {
|
|
agent {label "site"}
|
|
when { beforeAgent true
|
|
anyOf {environment name: 'ACTION', value: 'WEB'; environment name: 'ACTION', value: 'ALL'}
|
|
}
|
|
steps {
|
|
sh '''
|
|
rsync -avHAXxz --progress --delete --numeric-ids --exclude devpribor.ru/core/cache/* -e ssh intertest@188.120.241.91://var/www/intpribor/www /srv/archive/site/dev/
|
|
rsync -avHAXxz --progress --delete --numeric-ids --exclude interpribor.ru/core/cache/* -e ssh intertest@188.120.241.91://var/www/devtest/www /srv/archive/site/test/
|
|
rsync -avHAXxz --progress --delete --numeric-ids --exclude interpribor.ru/core/cache/* -e ssh interbase@82.146.55.174://var/www/intpribor/www /srv/archive/site/prod/
|
|
ssh interbase@82.146.55.174 "mysqldump --host 127.0.0.1 --port 3307 --column-statistics=0 --no-tablespaces -ucarpribor -p1L5n0E7Ah8A9 carpribor | gzip -9" > /srv/archive/site/prod/carpribor_$(date +%d%m%Y).sql.gz
|
|
tar -zcvf /mnt/backup/site/site_prod_$(date +%d%m%Y).tar.gz /srv/archive/site/prod/
|
|
tar -zcvf /mnt/backup/site/site_dev_$(date +%d%m%Y).tar.gz /srv/archive/site/dev/www/devpribor.ru/
|
|
find /mnt/backup/site/ -name "*.gz" -mtime +27 -exec rm -f {} \\;
|
|
'''
|
|
updateDesc("${env.STAGE_NAME}")
|
|
sendME("${env.STAGE_NAME}","WEB Backup success!!!")
|
|
telegramSend(message: 'WEB BACKUP success!!!', chatId: 648920818)
|
|
}
|
|
}
|
|
|
|
////
|
|
|
|
|
|
}
|
|
|
|
post {
|
|
success {
|
|
node ("site") {
|
|
jabberNotify notificationStrategy: 'success', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'WEB BACKUP SUCCESS!!!', targets: 'user@domen'
|
|
}
|
|
}
|
|
|
|
aborted {
|
|
node ("site") {
|
|
jabberNotify notificationStrategy: 'aborted', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'WEB BACKUP ABORT!!!', targets: 'user@domen'
|
|
}
|
|
}
|
|
failure {
|
|
node ("site") {
|
|
jabberNotify notificationStrategy: 'failure', notifyCulprits: true, notifyFixers: true, notifySuspects: true, notifyUpstreamCommitters: true, extraMessage: 'WEB BACKUP ERROR!!!', targets: 'user@domen'
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
def getBuildUser() {
|
|
return currentBuild.rawBuild.getCause(Cause.UserIdCause)?.getUserId()
|
|
}
|
|
|
|
def updateDesc(ACTION)
|
|
{
|
|
def d = [ACTION: '', BACKUP_DATE: '', END_TIME: '']
|
|
END_TIME = new Date().format( 'dd.MM.yy_HH:mm' )
|
|
d.ACTION = "${ACTION}"
|
|
d.BACKUP_DATE = "${CURRENT_DATE}"
|
|
d.END_TIME = "${END_TIME}"
|
|
d1 = d.clone()
|
|
props << d1
|
|
println d1
|
|
d.clear()
|
|
println props
|
|
println d
|
|
println "${END_TIME}"
|
|
def item = Jenkins.instance.getItemByFullName("${JOB_NAME}")
|
|
item.setDescription("${getDescTemplate(props)}")
|
|
|
|
|
|
}
|
|
|
|
def sendME(ACTION,STATUS)
|
|
{
|
|
emailext body: "${STATUS}",
|
|
subject: "${ACTION}",
|
|
to: 'therion@nasda.ru'
|
|
}
|
|
|
|
|
|
def gitClone(String stand) {
|
|
checkout poll: false, scm: [
|
|
$class: 'GitSCM',
|
|
branches: [[name: '*/master']],
|
|
doGenerateSubmoduleConfigurations: false,
|
|
userRemoteConfigs: [[url: 'git@gitlab.domen:user/sys.git']]
|
|
]
|
|
}
|
|
|
|
def scriptDir = getClass().protectionDomain.codeSource.location.path
|
|
println "${scriptDir}"
|
|
|
|
String currentDir = new File(".").getAbsolutePath()
|
|
|
|
|
|
def getDescTemplate(List props) {
|
|
return """
|
|
<?xml version="1.0" encoding="UTF-8"?><html>
|
|
<body>
|
|
<b>Задача бэкапирует сетевые диски</b>
|
|
<div style="font-wight:bold;">
|
|
Если сборка не прошла, звонить :)
|
|
</div>
|
|
<style>
|
|
.backup_table { margin:15px 0; border:none; border-collapse:collapse; border-spacing:0; font-size:100%; width: 100%;}
|
|
.backup_table th, .stand_table td { padding:3px 4px; border: 1px solid #cdcdcd; }
|
|
.backup_table th { text-align:center; font-weight:bold; border: 1px solid #cdcdcd; background:#f9efcf; }
|
|
.backup_table .last_update { text-align:right; font-size:75%; border:none; }
|
|
.backup_table .stand:hover { background:#f6faf2; }
|
|
.backup_table .col_title { width:120px; }
|
|
</style>
|
|
<table class="backup_table">
|
|
<tr>
|
|
<th colspan="8" style="text-align:left;">Задания бэкапа:</th>
|
|
</tr>
|
|
<tr>
|
|
<th abbr="ACTION">Бэкапирование</th>
|
|
<th abbr="BACKUP_DATE">Дата выполнения</th>
|
|
<th abbr="END_TIME">Время завершения</th>
|
|
</tr>
|
|
${props.collect { prop ->
|
|
def idx = props.findIndexOf { it.equals(prop) }
|
|
return """ <tr class="mail">
|
|
<td abbr="ACTION">${prop.ACTION}</td>
|
|
<td abbr="BACKUP_DATE">${prop.BACKUP_DATE}</td>
|
|
<td abbr="END_TIME">${prop.END_TIME}</td>
|
|
</tr>"""
|
|
}.join('')}
|
|
|
|
|
|
</table>
|
|
<br/>
|
|
<br/>
|
|
<br/>При запуске необходимо указать параметры:
|
|
<br/>
|
|
<ul>
|
|
<li>
|
|
<b>ACTION</b> - выполняемое действие (ALL, 1CDB, WORK)
|
|
<ul>
|
|
<li>
|
|
<b>ALL</b> - Выполнение всех задач, планировщик делает по умолчанию в выходной
|
|
</li>
|
|
<li>
|
|
<b>WEB</b> - Бэкап Продуктивного и тестового сайтов
|
|
</li>
|
|
<li>
|
|
<b>LINUX</b> - Бэкап Linux server with rsync
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<b>Бэкапы тут</b> - <a href="\\\\ASTAROT.domen\\Backup">\\\\ASTAROT.domen\\Backup</a>
|
|
</li>
|
|
</ul>
|
|
</body>
|
|
</html>
|
|
"""
|
|
}
|
|
|