Commit 339de564 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[ADMIN] bash scripts to enter or backup a postgres database

parent f940f13a
Pipeline #3045 failed with stage
in 25 minutes and 47 seconds
#!/bin/bash
# 0 3 * * * pg_dump --dbname=$MYDB | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz
if [[ $1 == "" || $2 == "" ]]
then echo "USAGE : ./psql gargantext.ini backup_directory"
else
INIFILE=$1
getter () {
grep $1 $INIFILE | sed "s/^.*= //"
}
USER=$(getter "DB_USER")
NAME=$(getter "DB_NAME")
PASS=$(getter "DB_PASS")
HOST=$(getter "DB_HOST")
PORT=$(getter "DB_PORT")
GARGDB="postgresql://${USER}:${PASS}@${HOST}:${PORT}/${NAME}"
#echo "backuping $GARGDB"
pg_dump --dbname=$GARGDB | gzip > $2/$(date +%Y-%m-%d).garg_dump.gz
fi
#!/bin/bash
if [[ $1 == "" ]]
then echo "USAGE : ./psql gargantext.ini"
else
INIFILE=$1
getter () {
grep $1 $INIFILE | sed "s/^.*= //"
}
connect () {
USER=$(getter "DB_USER")
NAME=$(getter "DB_NAME")
PASS=$(getter "DB_PASS")
HOST=$(getter "DB_HOST")
PORT=$(getter "DB_PORT")
# "postgresql://${USER}:${PASS}@${HOST}:${PORT}/${NAME}"
GARGDB="postgresql://${USER}:${PASS}@${HOST}:${PORT}/${NAME}"
#echo "connecting to $GARGDB"
psql "postgresql://${USER}:${PASS}@${HOST}:${PORT}/${NAME}"
}
if [[ $1 == "" ]]
then echo "USAGE : ./psql gargantext.ini"
else connect $INIFILE
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment