Connect Postgres Database on different server

My postgres database is on different server.
I want to automate a process that can take a backup a from my postgres database which is on another server, and store it in a particular location.

I’m facing a challenge in connecting the database and how to take backup.