summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Siraut <csiraut@entrouvert.com>2019-06-06 12:35:50 (GMT)
committerChristophe Siraut <csiraut@entrouvert.com>2019-06-06 15:29:46 (GMT)
commitf7b3c154c0bc0430928bdad6fd9c8d98e8067f0f (patch)
tree24b2489824f1f0f76e538095e9d3801c3e2ed4a9
parent0b326727daf23d363f94918105dbef16c32d01b9 (diff)
downloadpublik-client-scripts-f7b3c154c0bc0430928bdad6fd9c8d98e8067f0f.zip
publik-client-scripts-f7b3c154c0bc0430928bdad6fd9c8d98e8067f0f.tar.gz
publik-client-scripts-f7b3c154c0bc0430928bdad6fd9c8d98e8067f0f.tar.bz2
montpellier: export wcs-olap schemasv1.4
-rwxr-xr-xclients/montpellier/pg_copy_bijoe_schema.task4
-rwxr-xr-xclients/montpellier/pg_copy_bijoe_schemas (renamed from clients/montpellier/pg_copy_bijoe_schema)18
-rwxr-xr-xclients/montpellier/pg_copy_bijoe_schemas.task4
-rw-r--r--debian/publik-montpellier-scripts.cron.d2
4 files changed, 13 insertions, 15 deletions
diff --git a/clients/montpellier/pg_copy_bijoe_schema.task b/clients/montpellier/pg_copy_bijoe_schema.task
deleted file mode 100755
index edc256b..0000000
--- a/clients/montpellier/pg_copy_bijoe_schema.task
+++ /dev/null
@@ -1,4 +0,0 @@
-#! /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/clients/montpellier/pg_copy_bijoe_schema b/clients/montpellier/pg_copy_bijoe_schemas
index 142a4ed..72aaa8a 100755
--- a/clients/montpellier/pg_copy_bijoe_schema
+++ b/clients/montpellier/pg_copy_bijoe_schemas
@@ -1,28 +1,26 @@
#!/bin/bash
-# dump a database schema to a new database with specific privileges
+# dump database schemas 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
+schemas=`psql -q -t -c "select schema_name from information_schema.schemata where schema_name LIKE '%eservices%montpellier3m_fr'" bijoe`
psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$owner'" | grep -q 1 || psql -c "CREATE ROLE $owner"
psql -c "select pg_terminate_backend(pid) from pg_stat_activity where datname = '$destination'" >/dev/null
psql -c "DROP DATABASE IF EXISTS $destination" >/dev/null
psql -c "CREATE DATABASE $destination WITH OWNER '$owner'" >/dev/null
-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
+
+for schema in $schemas
+do
+ pg_dump --no-owner --schema $schema $origin | psql $destination >/dev/null
+ psql $destination -c "GRANT SELECT ON ALL TABLES IN SCHEMA $schema TO $owner" >/dev/null
+done
diff --git a/clients/montpellier/pg_copy_bijoe_schemas.task b/clients/montpellier/pg_copy_bijoe_schemas.task
new file mode 100755
index 0000000..43a032c
--- /dev/null
+++ b/clients/montpellier/pg_copy_bijoe_schemas.task
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+test `hostname -f` = 'database.node1.test.saas.entrouvert.org' && /usr/lib/publik/clients/montpellier/pg_copy_bijoe_schemas
+test `hostname -f` = 'database.node1.prod.saas.entrouvert.org' && /usr/lib/publik/clients/montpellier/pg_copy_bijoe_schemas
diff --git a/debian/publik-montpellier-scripts.cron.d b/debian/publik-montpellier-scripts.cron.d
index 5b65a6f..606ed7f 100644
--- a/debian/publik-montpellier-scripts.cron.d
+++ b/debian/publik-montpellier-scripts.cron.d
@@ -1 +1 @@
-1 4 * * * postgres /usr/lib/publik/clients/montpellier/pg_copy_bijoe_schema.task
+1 4 * * * postgres /usr/lib/publik/clients/montpellier/pg_copy_bijoe_schemas.task