Skip to content

Commit

Permalink
add utils files
Browse files Browse the repository at this point in the history
  • Loading branch information
geektortoise committed Aug 30, 2018
1 parent c4c9054 commit 03e7ed4
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
40 changes: 40 additions & 0 deletions utils/backup_mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#
# Copyright (c) 2009-2018. Authors: see NOTICE file.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#made scripts in a util folder


if [ -z "$1" ]
then
echo "No argument supplied. Data is saved in manBU folder"
NAME="manBU"
else
NAME=$1
fi

return=0
docker exec mongodb mongodump -h localhost -o /BU && message="Backup OK. " || (message="Backup failed. " && return=1)
docker cp mongodb:/BU $NAME && message=$message"Copy OK. " || (message=$message"Copy failed. " && return=1)
docker exec mongodb rm -rf /BU && message=$message"Deletion OK. " || (message=$message"Deletion failed. " && return=1)

if [ $return -gt 0 ]
then
echo "ERROR"
else
echo "Terminated"
fi


39 changes: 39 additions & 0 deletions utils/backup_postgis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

#
# Copyright (c) 2009-2018. Authors: see NOTICE file.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#made scripts in a util folder


if [ -z "$1" ]
then
echo "No argument supplied. Data is saved in manBU.sql file"
NAME="manBU.sql"
else
NAME=$1
fi

return=0
docker exec -e PGPASSWORD="docker" postgresql pg_dump -h localhost -U docker -f BU.sql docker && message="Backup OK. " || (message="Backup failed. " && return=1)
docker cp postgresql:/BU.sql $NAME && message=$message"Copy OK. " || (message=$message"Copy failed. " && return=1)
docker exec postgresql rm /BU.sql && message=$message"Deletion OK. " || (message=$message"Deletion failed. " && return=1)

if [ $return -gt 0 ]
then
echo "ERROR"
else
echo "Terminated"
fi

47 changes: 47 additions & 0 deletions utils/restore_postgis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

#
# Copyright (c) 2009-2018. Authors: see NOTICE file.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#made scripts in a util folder


if [ -z "$1" ]
then
echo "No argument supplied. Data is restored from manBU.sql file"
NAME="manBU.sql"
else
NAME=$1
fi

docker cp $NAME postgresql:/BU.sql

docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -c "UPDATE pg_database SET datistemplate = 'false' WHERE datname ='docker'"
docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -c "select pg_terminate_backend(pid) from pg_stat_activity where datname='docker' AND pid <> pg_backend_pid()"
docker exec -e PGPASSWORD="docker" postgresql dropdb -h localhost -U docker docker

#Then recreate the db (the commands are on your deployment files).
docker exec -e PGPASSWORD="docker" postgresql createdb -h localhost -U docker --encoding='utf-8' --template=template0 -O docker docker
docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='docker'"
docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -d docker -c "CREATE EXTENSION postgis;"
docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -d docker -c "GRANT ALL ON geometry_columns TO PUBLIC;"
docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -d docker -c "GRANT ALL ON geography_columns TO PUBLIC;"
docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -d docker -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"


docker exec -e PGPASSWORD="docker" postgresql psql -h localhost -U docker -w -d docker -f /BU.sql

echo "Terminated"


0 comments on commit 03e7ed4

Please sign in to comment.