summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Siraut <csiraut@entrouvert.com>2019-05-28 15:04:45 (GMT)
committerChristophe Siraut <csiraut@entrouvert.com>2019-05-29 12:08:20 (GMT)
commitae4389f2d3768d746f7f240ef9d347f131bba530 (patch)
tree0094b94dcb376db236caae1b4b1a444c36d22f9d
parent6693156ddc21ea32dfcb83d49707f3381f372f13 (diff)
downloadpublik-client-scripts-ae4389f2d3768d746f7f240ef9d347f131bba530.zip
publik-client-scripts-ae4389f2d3768d746f7f240ef9d347f131bba530.tar.gz
publik-client-scripts-ae4389f2d3768d746f7f240ef9d347f131bba530.tar.bz2
add publik-montpellier-scripts (#32727)v1.1
-rw-r--r--.gitignore1
-rwxr-xr-xclients/montpellier/pg_copy_bijoe_schema28
-rwxr-xr-xclients/montpellier/pg_copy_bijoe_schema.task4
-rw-r--r--debian/control5
-rw-r--r--debian/publik-montpellier-scripts.cron.d1
-rw-r--r--debian/publik-montpellier-scripts.dirs1
-rw-r--r--debian/publik-montpellier-scripts.install1
7 files changed, 41 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 73ade75..e063cf6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
debian/.debhelper/
debian/*.debhelper.log
debian/publik-strasbourg-scripts/
+debian/publik-montpellier-scripts/
sdist
diff --git a/clients/montpellier/pg_copy_bijoe_schema b/clients/montpellier/pg_copy_bijoe_schema
new file mode 100755
index 0000000..03b9776
--- /dev/null
+++ b/clients/montpellier/pg_copy_bijoe_schema
@@ -0,0 +1,28 @@
+#!/bin/bash
+# dump a database schema to a new database with specific privileges
+# you may want to change the role password with :
+# ALTER USER $owner WITH PASSWORD 'new_password';
+set -e
+
+function usage () {
+ echo "$0 statistiques_paris_fr"; exit 1
+}
+
+test "$#" -eq 1 || usage
+
+origin=bijoe
+schema=$1
+destination=montpellier3m_bijoe
+owner=montpellier3m
+psql='sudo -u postgres psql'
+
+$psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$owner'" | grep -q 1 || $psql -c "CREATE ROLE $owner;"
+
+$psql -c "DROP DATABASE IF EXISTS $destination;" >/dev/null
+$psql -c "CREATE DATABASE $destination WITH OWNER '$owner';" >/dev/null
+sudo -u postgres pg_dump --no-owner --schema $schema $origin | $psql $destination >/dev/null
+
+$psql -c "ALTER ROLE $owner WITH LOGIN;" >/dev/null
+$psql -c "GRANT CONNECT ON DATABASE $destination TO $owner;" >/dev/null
+$psql $destination -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO $owner;" >/dev/null
+$psql $destination -c "GRANT SELECT ON ALL TABLES IN SCHEMA $schema TO $owner;" >/dev/null
diff --git a/clients/montpellier/pg_copy_bijoe_schema.task b/clients/montpellier/pg_copy_bijoe_schema.task
new file mode 100755
index 0000000..edc256b
--- /dev/null
+++ b/clients/montpellier/pg_copy_bijoe_schema.task
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+test `hostname -f` = 'database.node1.test.saas.entrouvert.org' && /usr/lib/publik/clients/montpellier/pg_copy_bijoe_schema statistiques_test_entrouvert_montpellier3m_fr
+test `hostname -f` = 'database.node1.prod.saas.entrouvert.org' && /usr/lib/publik/clients/montpellier/pg_copy_bijoe_schema statistiques_montpellier3m_fr
diff --git a/debian/control b/debian/control
index 0dd3702..ba0826a 100644
--- a/debian/control
+++ b/debian/control
@@ -9,6 +9,7 @@ Homepage: https://git.entrouvert.org/publik-client-scripts.git
Package: publik-client-scripts
Architecture: all
Depends: ${misc:Depends},
+ publik-montpellier-scripts,
publik-strasbourg-scripts
Description: Meta package with all Publik client scripts
@@ -17,3 +18,7 @@ Architecture: all
Depends: ${misc:Depends}, python-elasticsearch
Description: Publik scripts for Strasbourg
+Package: publik-montpellier-scripts
+Architecture: all
+Depends: ${misc:Depends}
+Description: Publik scripts for Montpellier
diff --git a/debian/publik-montpellier-scripts.cron.d b/debian/publik-montpellier-scripts.cron.d
new file mode 100644
index 0000000..249f1af
--- /dev/null
+++ b/debian/publik-montpellier-scripts.cron.d
@@ -0,0 +1 @@
+1 4 * * * root /usr/lib/publik/clients/montpellier/export_bijoe_schema
diff --git a/debian/publik-montpellier-scripts.dirs b/debian/publik-montpellier-scripts.dirs
new file mode 100644
index 0000000..3c8204d
--- /dev/null
+++ b/debian/publik-montpellier-scripts.dirs
@@ -0,0 +1 @@
+/usr/lib/publik/clients/montpellier
diff --git a/debian/publik-montpellier-scripts.install b/debian/publik-montpellier-scripts.install
new file mode 100644
index 0000000..2ccfa55
--- /dev/null
+++ b/debian/publik-montpellier-scripts.install
@@ -0,0 +1 @@
+usr/lib/publik/clients/montpellier/