-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update versions test workflow, cleaning up un-used YAML/templates, an…
…d DB examples (#71)
- Loading branch information
Showing
10 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Example Files | ||
|
||
The files in this directory provide further examples for working with the Helm chart deployments. The scripts and other files here are provided as-is. | ||
|
||
## Self-host chart | ||
|
||
These following examples are for use with the `self-host` chart. | ||
|
||
### Database Pod Backup and Restore Examples | ||
|
||
We have provided two example jobs for backing up and restoring the database in the Bitwarden database pod. If you are using your own SQL Server instance that is not deployed as part of this Helm chart, please follow your corporate backup and restore policies. These are illustrative examples of what can be done. Database backups and backup policies are ultimately up to the implementor. | ||
|
||
The example jobs for the database pod can be found in the `database-backup` and `database-restore` folders under the `examples` directory. Note that the backup could be scheduled outside of the cluster to run at a regular interval, or it could be modified to create a CronJob object within Kubernetes for scheduling purposes. | ||
|
||
The backup job will create timestamped versions of the previous backups. The current backup is simply called `vault.bak`. These files are placed in the MS SQL backups persistent volume. The restore job will look for `vault.bak` in the same persistent volume. |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: "bitwarden-backup" | ||
labels: | ||
app.kubernetes.io/component: bitwarden-backup | ||
app: bitwarden-backup | ||
spec: | ||
ttlSecondsAfterFinished: 10 | ||
backoffLimit: 1 | ||
template: | ||
metadata: | ||
name: "bitwarden-backup" | ||
labels: | ||
app.kubernetes.io/component: bitwarden-backup | ||
app: bitwarden-backup | ||
spec: | ||
containers: | ||
- name: backup-db | ||
env: | ||
- name: MSSQL_CONN_STRING | ||
valueFrom: | ||
secretKeyRef: | ||
name: bitwarden-sql-connection-string | ||
key: globalSettings__sqlServer__connectionString | ||
image: "mcr.microsoft.com/mssql-tools" | ||
volumeMounts: | ||
- name: mssql-backups | ||
mountPath: /backups | ||
command: | ||
- "/bin/bash" | ||
- "-c" | ||
args: [ | ||
" | ||
[ ! -f /backups/vault.bak ] || mv /backups/vault.bak \"/backups/vault.bak.$(date -r /backups/vault.bak -u +'%Y-%m-%dT%H:%M:%SZ')\"; | ||
svr=\"$(echo \"${MSSQL_CONN_STRING}\" | grep -Po \"Data Source=tcp:\\K[^,]*(?=.*)\")\"; | ||
pass=\"$(echo \"${MSSQL_CONN_STRING}\" | grep -Po \".*Password=\\K[^;]*(?=.*)\")\"; | ||
echo \"$pass\" | /opt/mssql-tools/bin/sqlcmd -S $svr -U SA -q \"BACKUP DATABASE [vault] TO DISK = '/var/opt/mssql/backups/vault.bak' WITH FORMAT, INIT\" | ||
" | ||
] | ||
restartPolicy: Never | ||
volumes: | ||
- name: mssql-backups | ||
persistentVolumeClaim: | ||
claimName: bitwarden-self-host-mssqlbackups |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
namespace="bitwarden" | ||
|
||
kubectl delete job -n $namespace -l app=bitwarden-backup | ||
kubectl apply -n $namespace -f $(dirname "$0")/backup-job.yaml | ||
echo -n "Starting job..." | ||
while [[ $(kubectl get pods -n $namespace -l app=bitwarden-backup -o jsonpath="{.items[*].status.containerStatuses[*].ready}") != "true" ]]; do echo -n "..."; sleep 1; done | ||
echo "..." | ||
echo "Backing up..." | ||
kubectl logs -l app=bitwarden-backup -n $namespace -f |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
namespace="bitwarden" | ||
|
||
kubectl delete job -n $namespace -l app=bitwarden-restore | ||
kubectl apply -n $namespace -f $(dirname "$0")/restore-job.yaml | ||
echo -n "Starting job..." | ||
while [[ $(kubectl get pods -n $namespace -l app=bitwarden-restore -o jsonpath="{.items[*].status.containerStatuses[*].ready}") != "true" ]]; do echo -n "..."; sleep 1; done | ||
echo "..." | ||
echo "Restoring..." | ||
kubectl logs -l app=bitwarden-restore -n $namespace -f |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: "bitwarden-restore" | ||
labels: | ||
app.kubernetes.io/component: bitwarden-restore | ||
app: bitwarden-restore | ||
spec: | ||
ttlSecondsAfterFinished: 10 | ||
backoffLimit: 1 | ||
template: | ||
metadata: | ||
name: "bitwarden-restore" | ||
labels: | ||
app.kubernetes.io/component: bitwarden-restore | ||
app: bitwarden-restore | ||
spec: | ||
containers: | ||
- name: restore-db | ||
env: | ||
- name: MSSQL_CONN_STRING | ||
valueFrom: | ||
secretKeyRef: | ||
name: bitwarden-sql-connection-string | ||
key: globalSettings__sqlServer__connectionString | ||
image: "mcr.microsoft.com/mssql-tools" | ||
volumeMounts: | ||
- name: mssql-backups | ||
mountPath: /backups | ||
command: | ||
- "/bin/bash" | ||
- "-c" | ||
args: [ | ||
" | ||
svr=\"$(echo \"${MSSQL_CONN_STRING}\" | grep -Po \"Data Source=tcp:\\K[^,]*(?=.*)\")\"; | ||
pass=\"$(echo \"${MSSQL_CONN_STRING}\" | grep -Po \".*Password=\\K[^;]*(?=.*)\")\"; | ||
echo \"$pass\" | /opt/mssql-tools/bin/sqlcmd -S $svr -U SA -q \"ALTER DATABASE [vault] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; RESTORE DATABASE [vault] FROM DISK = '/var/opt/mssql/backups/vault.bak' WITH REPLACE; ALTER DATABASE [vault] SET MULTI_USER;\" | ||
" | ||
] | ||
restartPolicy: Never | ||
volumes: | ||
- name: mssql-backups | ||
persistentVolumeClaim: | ||
claimName: bitwarden-self-host-mssqlbackups |