New exep function which handels pipes and redirects properly
rework mayan backup and restore steps
This commit is contained in:
@@ -150,15 +150,25 @@ user = mayan"
|
||||
step_20_info() { echo "Backup postgres database to media folder"; }
|
||||
step_20_alias() { ALIAS=backupdb; }
|
||||
step_20() {
|
||||
echo "Backup with standard user / database: mayan / mayan"
|
||||
exe pg_dump -h 127.0.0.1 -U mayan -c mayan -W > ${toolMediaFolder}/`date +%Y-%m-%d"_"%H-%M-%S`.sql
|
||||
local LASTYEAR=$(($(date +%Y)-1))
|
||||
if [ ! -s ~/.pgpass ] ; then
|
||||
echo "[INFO] For unattended backup please define ~/.pgpass containing credentials for user mayan"
|
||||
fi
|
||||
echo "Backup custom pg format with standard user / database: mayan / mayan"
|
||||
exep "pg_dump -h 127.0.0.1 -U mayan -Fc mayan | bzip2 -c > ${toolDbBackupFolder}/`date +%Y-%m-%d\"_\"%H-%M-%S`.backup.bz2"
|
||||
exe rm -f ${toolDbBackupFolder}/${LASTYEAR}*
|
||||
}
|
||||
toolDbBackupFolder=${toolMediaFolder}/backupdb
|
||||
|
||||
|
||||
step_22_info() { echo "Postgres database restore"; }
|
||||
step_22() {
|
||||
echo "1. Create a empty postgres database first (step 4)"
|
||||
echo "2. psql -h <host> -U <database user> -d <database name> -W -f <sql dump file>"
|
||||
echo " e.g. psql -h 127.0.0.1 -U mayan -d mayan -W -f 2018-06-07_18-10-56.sql"
|
||||
echo "or"
|
||||
echo "3. Custom postgres format dump restore:"
|
||||
echo " pg_restore -h localhost -p 5432 -U mayan -d new_db -v \"10.70.0.61.backup\""
|
||||
}
|
||||
|
||||
# Read postgres database information dbname/user/pass if empty
|
||||
|
@@ -365,7 +365,7 @@ showVersion() {
|
||||
}
|
||||
|
||||
exe() {
|
||||
arr=("$@")
|
||||
local arr=("$@")
|
||||
if [ $DRY -ne 0 ] ; then
|
||||
echo -e "\n-- ${arr[@]}"
|
||||
elif [ $VERBOSE -eq 1 ] ; then
|
||||
@@ -375,6 +375,18 @@ exe() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle dry run and verbose output for commands containing pipe and/or redirects
|
||||
# exep <COMMAND TO RUN AS STRING>
|
||||
exep() {
|
||||
if [ $DRY -ne 0 ] || [ $VERBOSE -eq 1 ] ; then
|
||||
echo -e "\n-- $1"
|
||||
fi
|
||||
if [ $DRY -eq 0 ] ; then
|
||||
bash -c "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
local START=0
|
||||
|
||||
|
Reference in New Issue
Block a user