2 add revelent tag
| link
1
source | link

backup file locally in shell script

This is my crontab:

crontab -e
30 5 * * * sh /home/donato/Documents/pg_bak.sh

Every day at 5:30am I want to execute a shell script I created called pg_bak.sh.

This is the contents of the shell script:

#!/bin/bash

PG_USER=donato
DATABASE=mydb
SERVER=216.58.219.174
DIR="$HOME/pg_bak"
DATE=$(date +"%m_%d_%y")
FILE="$DATABASE_$DATE"
# pass @ .pgpass

PG_BAK_NOW () {
  pg_dump -h $SERVER -U $PG_USER $DATABASE -f $FILE.sql  
}

echo "Ready to dump to $FILE" >> "$HOME/pg_status" 

cd $DIR
if [ -f "$FILE" ];
then
  rm $FILE
  PG_BAK_NOW 
else
  PG_BAK_NOW
fi

I want to backup the sql file on my local machine at ~/pg_bak, NOT on the remote server. In other words, I do not want to backup the file on the remote server. Will the pg_dump command be running in the context of the computer I am running it from or from the remote server?