Commit c7014821 authored by Ignacio's avatar Ignacio
Browse files

Añade check para comprobar tamaño del backup

parent 2843767c
Loading
Loading
Loading
Loading
+28 −15
Original line number Diff line number Diff line
@@ -43,7 +43,18 @@ function create_pgpass() {
function dump_all() {

	echo "Creating database backup"
	pg_dumpall -h ${POSTGRES_HOSTNAME} -U ${POSTGRES_USER} --clean > ${POSTGRES_DUMP_PATH}/${DUMP_FILENAME}
	if pg_dumpall -h ${POSTGRES_HOSTNAME} -U ${POSTGRES_USER} --clean > ${POSTGRES_DUMP_PATH}/${DUMP_FILENAME}
	then
		file_size=$(wc -c <"${POSTGRES_DUMP_PATH}/${ZIP_FILENAME}")
		if [ ${file_size} -eq 0 ]; then
			echo "ERROR created empty backup"
			exit 1
		fi
		echo "Backup created"
	else
		echo "ERROR creating backup"
		exit 1
	fi
}

function compress() {
@@ -53,6 +64,7 @@ function compress() {
	cd ${POSTGRES_DUMP_PATH}
	tar czf ${ZIP_FILENAME} ${DUMP_FILENAME}
	cd ${WORKDIR}
	echo "Backup compressed"
}

function upload_s3() {
@@ -67,10 +79,13 @@ function clean_dump() {
	rm -f ${POSTGRES_DUMP_PATH}/*
}

mkdir -p ${POSTGRES_DUMP_PATH}

function main() {

	check_constraint_variable

	mkdir -p ${POSTGRES_DUMP_PATH}

	# Create pgpass file if not exists it
	if [ ! -f ${PGPASSFILE} ]
	then
@@ -82,11 +97,9 @@ dump_all
	if [ -f ${POSTGRES_DUMP_PATH}/${DUMP_FILENAME} ]
	then
		compress

	if [ -f ${POSTGRES_DUMP_PATH}/${ZIP_FILENAME} ]
	then
		upload_s3
	fi

		clean_dump
	fi
}

main
 No newline at end of file