How Do I Backup My PostgreSQL Database with Cron?

后端 未结 8 1165
孤街浪徒
孤街浪徒 2021-01-30 09:31

I can run commands like vacuumdb, pg_dump, and psql just fine in a script if I preface them like so:

/usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase &g         


        
8条回答
  •  抹茶落季
    2021-01-30 10:16

    I have set my cron like this. Every 59 minutes since monday to friday

    */59 * * * 1-5 sh /home/my_user/scripts/back_my_bd.sh 
    

    The script to run the backup is inside back_my_bd.sh file and the content is:

    pg_dump -U USERDATABASE DATABASENAME > /home/my_user/sql/mybackup.sql
    

    And i created the .pgpass file inside home directory to allow the backup whithout specify the user and password

    localhost:5432:DATABASENAME:USER:PASSWORD
    

    Sorry my english is not good!

提交回复
热议问题