#!/bin/bash
source $HOME/.gamerc

for db in $(grep _DB_NAME= ~/.gamerc | awk -F"=" '{print $2}' | grep -v WebTool | sed 's/"//g;s/${GAME_TYPE}//' | sed "s/^/${GAME_TYPE}/"); do
	DBLISTS=$(psql -U postgres -c "COPY(SELECT datname FROM pg_database WHERE datname ~ '^${db}[0-9]*$') TO STDOUT;")
	CHECK=$(echo ${DBLISTS} | sed '/^$/d' | wc -l)
	if [ "${CHECK}" -gt 0 ]; then
		for dbname in ${DBLISTS}; do
			#echo ${dbname}
			DBbackup ${dbname}
		done
	fi
done
