Skip to content

Instantly share code, notes, and snippets.

@digrabok
Forked from sirbrillig/pgsql_backup.sh
Created November 28, 2023 05:15
Show Gist options
  • Select an option

  • Save digrabok/0d9ed0c323a9819c085f94dd4066b65f to your computer and use it in GitHub Desktop.

Select an option

Save digrabok/0d9ed0c323a9819c085f94dd4066b65f to your computer and use it in GitHub Desktop.
Postgresql daily backup script.
FILE=`date +"%Y%m%d"`_backup.sql
DBSERVER=127.0.0.1
DATABASE=
USER=postgres
PASS=
# (2) in case you run this twice in one day, remove the previous version of the file
unalias rm 2> /dev/null
rm ${FILE} 2> /dev/null
rm ${FILE}.gz 2> /dev/null
# (3) do the mysql database backup (dump)
# use this command for a database server on a separate host:
#mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} ${DATABASE} > ${FILE}
# use this command for a database server on localhost. add other options if need be.
pg_dump ${DATABASE} > ${FILE}
# (4) gzip the mysql database dump file
gzip $FILE
# (5) show the user the result
echo "${FILE}.gz was created:"
ls -l ${FILE}.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment