How to pass in password to pg_dump?

后端 未结 16 865
深忆病人
深忆病人 2020-11-28 00:58

I\'m trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs:

0          


        
16条回答
  •  不知归路
    2020-11-28 01:17

    A secure way of passing the password is to store it in .pgpass file

    Content of the .pgpass file will be in the format:

    db_host:db_port:db_name:db_user:db_pass
    
    #Eg
    localhost:5432:db1:admin:tiger
    localhost:5432:db2:admin:tiger
    
    

    Now, store this file in the home directory of the user with permissions u=rw (0600) or less

    To find the home directory of the user, use echo $HOME

    Restrict permissions of the file chmod 0600 /home/ubuntu/.pgpass

提交回复
热议问题