cur_time=$(date "+%Y%m%dT%H%M%S")
cur_database="pysecmaster"

#database_dump_location="O:/Programming/Databases/pySecMaster/postgres_dumps"
database_dump_location="/mnt/backups/Programming/Databases/pySecMaster/postgres_dumps"

echo "Starting the Postgres database dump for ${cur_database}"


# Local database dumps:
#    Dump the database that is on the local machine, saving it to a local folder

# Windows Backup
#"C:\Program Files\PostgreSQL\9.5\bin\pg_dump" -Fc -Z9 -U postgres $cur_database > ${database_dump_location}/${cur_database}_${cur_time}.dump
#"C:\Program Files\PostgreSQL\9.5\bin\pg_dumpall" -g -U postgres > ${database_dump_location}/postgres_misc_${cur_time}.dump

# Linux Backup
pg_dump -Fc -Z9 -U postgres $cur_database > ${database_dump_location}/${cur_database}_${cur_time}.dump
pg_dumpall -g -U postgres > ${database_dump_location}/postgres_misc_${cur_time}.dump


# Remote database dumps:
#    SSH into the database server to run pg_dump, saving it to the local machine

#remote_user="xxxxx"
#remote_ip="xxx.xxx.xxx.xxx"

#ssh -o "Compression=no" ${remote_user}@${remote_ip} "pg_dump -Z9 -Fc -U postgres ${cur_database}" > ${database_dump_location}/${cur_database}_${cur_time}.dump
#ssh -o "Compression=no" ${remote_user}@${remote_ip} "pg_dumpall -g -U postgres" > ${database_dump_location}/postgres_misc_${cur_time}.dump


# Find and delete ALL files that are older than days_to_retain period

days_to_retain=60

find ${database_dump_location} -type f -mtime +${days_to_retain} -delete

Add database backup shell script.
Add database backup shell script.

The flexible script backs up the pySecMaster from either a local or remote machine to the local machine. Also, this script deletes all prior database backups that are older than 60 days.
