-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdb_backup.sh
executable file
·30 lines (21 loc) · 1.18 KB
/
db_backup.sh
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
#! /bin/sh
# About
# pg_dump:
# - sed: Changes all instances of 'n3c' in the pg_dump file to $fname, but only where 'n3c' appears as a schema name. It does this by looking at any line that isn't a line of data (all lines of data start with a number).
dt=$(date +%Y%m%d)
fname=n3c_backup_$dt
cat <<-END
How to make a backup of n3c schema
----------------------------------
Step 1: Backup the DB
pg_dump -d \$psql_conn -n n3c | sed '/^[0-9][0-9]*\t/! s/[[:<:]]n3c[[:>:]]/$fname/' > $fname.dmp
Step 2: Upload
Immediately upload the backup schema to the database. You may need to delete the oldest backup schema firrst in order to make room to upload this new schema.
psql -d \$psql_conn < $fname.dmp
Step 3: Quality control checks
3.1. Run: 'make counts-update'
This helps us keep track of changes in row counts at critical moments. Example: 'make counts-update Just performed a backup of n3c and uploaded new backup schema.'
3.2. Run: 'make counts-compare-schemas'
If there is a difference in row counts between 'n3c' and the new backup, this will require further analysis to determine why.
3.3 Optional: Run: 'make counts-docs', commit the changes, and push to GitHub, and @ the dev team.
END