Created
June 21, 2022 03:14
-
-
Save akhdaniel/2bc59542c80d821e9f16d5fcf6e0cfbc to your computer and use it in GitHub Desktop.
Revisions
-
akhdaniel created this gist
Jun 21, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ creat backup script ~/scripts/db_backup.sh ----- ```sh #!/bin/bash DIR=`date +%d-%m-%y` DEST=/db_backups/$DIR mkdir $DEST PGPASSWORD='postgres_password' pg_dump --inserts --column-inserts --username=postgres_user --host=postgres_host --port=postgres_port postgres_database_name > dbbackup.sql ``` Now chmod the script to allow it to for execution --- ```sh chmod +x ~/scripts/db_backup.sh ``` How to set up Cron (to automate the process) --- ```sh crontab -e ``` Paste the below commands at the bottom to automate the process ```sh 0 0 * * * ~/scripts/db_backup.sh # take a backup every midnight ``` Db Restore script ~/scripts/db_restore.sh ---- ```sh pg_restore -d db_name /path/to/your/file/dump_name.sql -c -U db_user ```