-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostgres-backup.sh
More file actions
executable file
·40 lines (27 loc) · 1.08 KB
/
postgres-backup.sh
File metadata and controls
executable file
·40 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
#
# Author: Outhan Chazima
# Date : 26-May-2022
# Description : The backup script will complete the backup and send the backup to a remote server.-
#
## In below given variables - require information to be feed by system admin##.
_BACKUP_DIR=/home/DBbackup/postgres
_DATABASE_NAME=postgres
# This requires you to have configyres the remote server ssh keys to be able to connect to remote server
_REMOTE_BACKUP_SERVER_ADDRESS=user@remote_server_ip
## Do not edit below given variable ##
_DATE_SCHEMA=$(date +%F-%H%M-%S)
_BACKUP_FILE=postgres-backup-$_DATE_SCHEMA.tar.gz
_BACKUP_PATH=$_BACKUP_DIR
###### Create / check backup Directory ####
if [ -d "$_BACKUP_PATH" ]
then
echo "$_BACKUP_PATH already exist"
else
mkdir -p "$_BACKUP_PATH"
fi
##################### SECTION 1 : SCHEMA BACKUP ############################################
pg_dump $_DATABASE_NAME | gzip > $_BACKUP_PATH/$_BACKUP_FILE
##################### END OF LINE ---- SECTION 1 : SCHEMA BACKUP #####################
scp $_BACKUP_PATH/$_BACKUP_FILE $_REMOTE_BACKUP_SERVER_ADDRESS:$_BACKUP_DIR;
done%