Backups are important and should obvioulsy not be stored on the same server. Sending a dump of my PostgreSQL database per email once a day seemed like an easy and viable solution – as long as it does not get too big. Gmail accounts provide more than enough space for storing small backups which is why I set up an additional account in order to not pollute my main inbox.

This is the small script I wrote to do so:

DATE=$(date +"%Y-%m-%d")

pg_dump --inserts $DATABASE | gzip > $FILE
mutt -s "PG Dump $DATABASE $DATE" -a $FILE -- $EMAIL < /dev/null

You might have to install and configure mutt to be able to send e-mails with attachments. This tutorial shows how to do that.

Store the file somewhere, execute chmod +x and schedule the script as a cronjob via crontab -e.

# m h  dom mon dow   command
0 4 * * * /path/to/script/

Now a backup of your database should be sent to the provided e-mail-address every day.