-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile.dbcopy
59 lines (48 loc) · 1.59 KB
/
Jenkinsfile.dbcopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@Library('conservify') _
properties([
buildDiscarder(logRotator(numToKeepStr: '5')),
disableConcurrentBuilds(),
])
timestamps {
node ("jenkins-aws-ubuntu") {
try {
def ws = conservifyTerraformWorkspace(env: params.WorkEnv)
def name = params.DbName ?: "db"
def isTsDB = name == "tsdb"
def url = isTsDB ? ws.timescaledb_url.value : ws.database_url.value
def exclusions = params.Exclusions ?: ""
def now = new Date()
def stamp = now.format("yyyyMMdd-HHmmss", TimeZone.getTimeZone('UTC'))
def file = "${name}-${stamp}.sql"
stage ('dbcopy') {
sh "rm -rf *.bz2 *.xz"
if (isTsDB) {
writeFile(file: "stop_workers.sql", text: "SELECT _timescaledb_internal.stop_background_workers();")
sh "docker run --rm -i postgres psql '${url}' < stop_workers.sql"
}
try {
def excluding = exclusions.split(",").collect { it.replaceAll("\\s", "") }.collect { "-T '${it}'" }
def extraArgs = excluding.join(" ")
sh "docker run --log-driver none --rm postgres pg_dump --schema-only '${url}' > ${file}"
sh "docker run --log-driver none --rm postgres pg_dump --data-only --disable-triggers ${extraArgs} '${url}' >> ${file}"
}
finally {
if (isTsDB) {
writeFile(file: "start_workers.sql", text: "SELECT _timescaledb_internal.start_background_workers();")
sh "docker run --rm -i postgres psql '${url}' < start_workers.sql"
}
}
sh "ls -alh ${file}"
sh "xz -T2 ${file}"
}
stage ('archive') {
archiveArtifacts(artifacts: "*.xz")
}
notifySuccess()
}
catch (Exception e) {
notifyFailure(e)
throw e
}
}
}