76 lines
1.9 KiB
Bash
Executable File
76 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
|
|
|
|
|
|
BACKUP_BASE_DIR=$1
|
|
BACKUP_BASE_DIR=${BACKUP_BASE_DIR:="/data/backup"}
|
|
|
|
backup_dir=$BACKUP_BASE_DIR/pgsql
|
|
|
|
if [ ! -d $backup_dir ] ; then
|
|
echo
|
|
echo " Backup directory not found"
|
|
echo
|
|
exit 1
|
|
fi
|
|
|
|
if cat /etc/passwd 2> /dev/null | grep postgres > /dev/null ; then
|
|
PSQL_USER=postgres
|
|
else
|
|
PSQL_USER=pgsql
|
|
fi
|
|
|
|
PSQL_BIN_DIR=/usr/local/pgsql/bin
|
|
if [ ! -x \$PSQL_BIN_DIR/psql ]; then
|
|
if [ -x /usr/bin/psql ]; then
|
|
PSQL_BIN_DIR=/usr/bin
|
|
elif [ -x /usr/local/bin/psql ];then
|
|
PSQL_BIN_DIR=/usr/local/bin
|
|
elif [ -x /usr/local/pgsql/bin/psql ];then
|
|
PSQL_BIN_DIR=/usr/local/pgsql/bin
|
|
else
|
|
echo
|
|
echo " pgsql bindir not found"
|
|
echo
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
logfile=restore_db.log
|
|
|
|
|
|
|
|
# -- Wiedrherstellung der datanbakuser und datenbankdefinitionen
|
|
# --
|
|
## restore_file=`find $backup_dir -maxdepth 1 -mindepth 1 -type f -printf "%f\n" | grep db_users_databases`
|
|
_list=`ls -t ${backup_dir}/db_users_databases*`
|
|
restore_file=`echo $_list | awk '{print$1}'`
|
|
|
|
echo -e "\n\tWiedrherstellung der Datanbakuser und Datenbankdefinitionen"
|
|
#echo -e "\tsu $PSQL_USER -c\"${PSQL_BIN_DIR}/psql -f $restore_file template1\"\n"
|
|
echo ""
|
|
|
|
su $PSQL_USER -c "${PSQL_BIN_DIR}/psql -f $restore_file template1" > $logfile 2>&1
|
|
|
|
|
|
# -- Wiedrherstellung der datanbakdaten
|
|
# --
|
|
#databases=`find $backup_dir -maxdepth 1 -mindepth 1 -type d -printf "%f "`
|
|
databases=`find $backup_dir -maxdepth 1 -mindepth 1 -type d -exec basename {} \;`
|
|
echo -e "\n\tWiedrherstellung der Datanbakdaten"
|
|
for db in $databases ; do
|
|
|
|
[ "$db" = "template0" ] && continue
|
|
|
|
_list=`ls -d -t ${backup_dir}/$db/dump*`
|
|
file=`echo $_list | awk '{print$1}'`
|
|
#echo " ${db}: su $PSQL_USER -c\"${PSQL_BIN_DIR}/psql -f $file $db\""
|
|
echo ""
|
|
echo -e "\t\t${db}.."
|
|
su $PSQL_USER -c "${PSQL_BIN_DIR}/psql -f $file $db" >> $logfile 2>&1
|
|
done
|
|
echo
|
|
|
|
exit 0
|