Skip to content

Commit 8ac455e

Browse files
authored
NERT-132: Database backup (#158)
- Initial backup container created - ENVs set for dev environment - know issues with verification / restore process, being investigated
1 parent 560f115 commit 8ac455e

File tree

7 files changed

+1389
-0
lines changed

7 files changed

+1389
-0
lines changed

containers/backup/.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Declare files that will always have LF line endings on checkout.
5+
backup.* text eol=lf
6+
*.sh text eol=lf
7+
*.md text eol=lf
8+
*.json text eol=lf
9+
*.conf text eol=lf
10+
**/s2i/bin/* text eol=lf
11+
**/root/**/* text eol=lf
12+
**/.scripts/* text eol=lf

containers/backup/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
.DS_Store
3+
4+
# Files created by the scripts from; https://github.com/BCDevOps/openshift-project-tools
5+
*_DeploymentConfig.json
6+
*_BuildConfig.json
7+
*.local.*
8+
*.overrides.*
9+
*.param
10+
settings*.sh
11+
12+
# Visual Studio Code
13+
.vscode
14+
15+
# Local config
16+
.env
17+
docker/backup.conf
18+
backups
19+
minio-data
20+
pg-data

containers/backup/DEVELOPER.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Openshift Commands to setup Backup Container
2+
3+
## <summary>Example of a Postgres deployment</summary>
4+
5+
The following outlines the deployment of a simple backup of three PostgreSQL databases in the same project namespace, on OCP v4.x.
6+
7+
1. As per OCP4 [docs](https://developer.gov.bc.ca/OCP4-Backup-and-Restore), 25G of the storage class `netapp-file-backup` is the default quota. If this is insufficient, you may [request](https://github.com/BCDevOps/devops-requests/issues/new/choose) more.
8+
9+
2. `git clone https://github.com/BCDevOps/backup-container.git && cd backup-container`.
10+
11+
Create the image.
12+
13+
```bash
14+
oc -n d83219-tools process -f ./templates/backup/backup-build.yaml | oc -n d83219-tools create -f -
15+
```
16+
17+
3. Configure (./config/backup.conf) (listing your database(s), and setting your cron schedule).
18+
19+
```bash
20+
postgres=restoration-tracker-db-postgresql:5432/restoration-tracker
21+
# postgres=pawslimesurvey-postgresql:5432/pawslimesurvey
22+
23+
0 1 * * * default ./backup.sh -s
24+
0 4 * * * default ./backup.sh -s -v all
25+
```
26+
27+
4. Configure references to your DB credentials in [backup-deploy.yaml](./openshift/templates/backup/backup-deploy.yaml), replacing the boilerplate `DATABASE_USER` and `DATABASE_PASSWORD` environment variables.
28+
29+
```yaml
30+
- name: RESTORATION_TRACKER_DB_POSTGRESQL_DEV_DEPLOY_USER
31+
valueFrom:
32+
secretKeyRef:
33+
key: database-admin
34+
name: '${DATABASE_SECRET_REF}'
35+
- name: RESTORATION_TRACKER_DB_POSTGRESQL_DEV_DEPLOY_PASSWORD
36+
valueFrom:
37+
secretKeyRef:
38+
key: database-admin-password
39+
name: '${DATABASE_SECRET_REF}'
40+
41+
...
42+
- name: DATABASE_SECRET_REF
43+
displayName: Database Secret Reference
44+
description: The name of the secret containing the database credentials.
45+
required: true
46+
value: restoration-tracker-creds
47+
```
48+
49+
Note that underscores should be used in the environment variable names.
50+
51+
5. Create your customized `./openshift/backup-deploy.overrides.param` parameter file, if required.
52+
53+
6. Deploy the app; here the example namespace is `d83219-dev` and the app name is `backup-postgres`:
54+
55+
```bash
56+
oc -n d83219-dev create configmap backup-conf --from-file=./config/backup.conf
57+
oc -n d83219-dev label configmap backup-conf app=backup-postgres
58+
59+
oc -n d83219-dev process -f ./templates/backup/backup-deploy.yaml | oc -n d83219-dev create -f -
60+
```
61+
62+
To clean up the deployment
63+
64+
```bash
65+
oc -n d83219-dev delete pvc/backup-postgres-pvc pvc/backup-verification secret/backup-postgres secret/ftp-secret dc/backup-postgres networkpolicy/backup-postgres configmap/backup-conf
66+
```
67+
68+
To clean up the image stream and build configuration
69+
70+
```bash
71+
oc -n d83219-tools delete buildconfig/backup-postgres imagestream/backup-postgres
72+
```
73+
74+
### NOTE: User Management Role Binding Required in tools env
75+
```
76+
kind: RoleBinding
77+
apiVersion: rbac.authorization.k8s.io/v1
78+
metadata:
79+
name: 'system:image-pullers'
80+
namespace: d83219-tools
81+
annotations:
82+
openshift.io/description: >-
83+
Allows all pods in this namespace to pull images from this namespace. It
84+
is auto-managed by a controller; remove subjects to disable.
85+
subjects:
86+
- kind: Group
87+
apiGroup: rbac.authorization.k8s.io
88+
name: 'system:serviceaccounts:d83219-tools'
89+
- kind: Group
90+
apiGroup: rbac.authorization.k8s.io
91+
name: 'system:serviceaccounts:d83219-dev'
92+
- kind: Group
93+
apiGroup: rbac.authorization.k8s.io
94+
name: 'system:serviceaccounts:d83219-test'
95+
- kind: Group
96+
apiGroup: rbac.authorization.k8s.io
97+
name: 'system:serviceaccounts:d83219-prod'
98+
roleRef:
99+
apiGroup: rbac.authorization.k8s.io
100+
kind: ClusterRole
101+
name: 'system:image-puller'
102+
```

0 commit comments

Comments
 (0)