Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a backup restore cron on staging #812

Merged
merged 39 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6b359b8
Create a backup restore cron on staging
euanmillar Dec 15, 2023
962d849
allowed label to be passed to script for snapshot usage
euanmillar Dec 15, 2023
1ae3655
Updated release action
euanmillar Dec 15, 2023
19c98e6
Add approval step to production deploys
euanmillar Dec 15, 2023
c906757
Add Riku's username to prod deploys
euanmillar Dec 15, 2023
7a30966
Merge branch 'infra-improvements' into restore-backup-cron
rikukissa Dec 22, 2023
1866e76
add separate config flag for provisioning for indicating if the serve…
rikukissa Dec 22, 2023
262b15d
make configuration so that qa can allow connections through the provi…
rikukissa Dec 22, 2023
872e8b3
create playbook for backup servers and the connection between app ser…
rikukissa Dec 22, 2023
11ae5aa
add tags
rikukissa Dec 22, 2023
332928e
add tag to workflow
rikukissa Dec 22, 2023
409f869
add task to ensure ssh dir exists for backup user
rikukissa Dec 22, 2023
868fd31
create home directory for backup
rikukissa Dec 22, 2023
4a95e99
Merge branch 'infra-improvements' into restore-backup-cron
rikukissa Jan 4, 2024
4b7453b
ensure backup task is always applied for root's crontab
rikukissa Jan 4, 2024
17b8580
add default value for periodic_restore_from_backup
rikukissa Jan 4, 2024
36edf30
make it possible to deploy production with current infrastructure
rikukissa Jan 4, 2024
3af12d8
Revert "make it possible to deploy production with current infrastruc…
rikukissa Jan 4, 2024
a8c172e
Merge branch 'infra-improvements' into restore-backup-cron
rikukissa Jan 4, 2024
25085d8
fix wait hosts definition for migrations
rikukissa Jan 4, 2024
c7852c1
make production a qa environment temporarily
rikukissa Jan 4, 2024
64b7f86
Merge branch 'infra-improvements' into restore-backup-cron
rikukissa Jan 4, 2024
cce578d
add shell for backup user so rsync works
rikukissa Jan 4, 2024
8d2e0e5
Merge branch 'infra-improvements' into restore-backup-cron
rikukissa Jan 5, 2024
1d44a53
explicitly define which user is the one running crontab, ensure that …
rikukissa Jan 5, 2024
197d99f
ensure .ssh directory exists for crontab user
rikukissa Jan 5, 2024
cb4148b
get user home directories dynamically
rikukissa Jan 5, 2024
e1f1e72
add missing tags
rikukissa Jan 5, 2024
7f0b999
add become
rikukissa Jan 5, 2024
11d8431
fix file path
rikukissa Jan 5, 2024
d2b16fe
define backup machine in staging config as well
rikukissa Jan 5, 2024
7a46e76
remove condition from fetch
rikukissa Jan 5, 2024
ecf0c5d
always create public key from private key
rikukissa Jan 5, 2024
cffa705
use hadcoded file name for public key
rikukissa Jan 5, 2024
8b22ad9
fix syntax
rikukissa Jan 5, 2024
1339272
make staging a QA environment so it reflects production
rikukissa Jan 5, 2024
04919be
separate backup downloading and restoring to two different scripts, u…
rikukissa Jan 5, 2024
d2736f6
fix an issue with a running OpenHIM while we restore backup
rikukissa Jan 5, 2024
9ca6a33
restart minio after restoring data
rikukissa Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .github/workflows/backup-check.yml

This file was deleted.

25 changes: 18 additions & 7 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
inputs:
branch_name:
description: Branch to build from
default: develop
default: master
required: true
release_version:
description: Release version number
description: Release tag. It will be prepended by your repository name
required: true

jobs:
Expand All @@ -20,15 +20,26 @@ jobs:
secret: ${{ github.TOKEN }}
approvers: euanmillar,rikukissa
minimum-approvals: 1
issue-title: "Release: ${{ github.event.inputs.release_version }}"
issue-body: "Please approve or deny the publishing of release: ${{ github.event.inputs.release_version }} to Dockerhub"
issue-title: "Release: ${{ github.event.repository.name }}-${{ github.event.inputs.release_version }}"
issue-body: "Please approve or deny the publishing of release: ${{ github.event.repository.name }}-${{ github.event.inputs.release_version }} to Dockerhub"
exclude-workflow-initiator-as-approver: false
- uses: actions/checkout@v2
if: github.event_name == 'workflow_dispatch'
with:
ref: '${{ github.event.inputs.branch_name }}'
- uses: actions/checkout@v2
if: github.event_name == 'push'
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: ${{ github.event.repository.name }}-
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially country config repos are tagged like this: opencrvs-farajaland-v1.3.2

custom_tag: ${{ github.event.inputs.release_version }}
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand All @@ -39,6 +50,6 @@ jobs:
DOCKERHUB_ACCOUNT: ${{ secrets.DOCKERHUB_ACCOUNT }}
DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_REPO }}
run: |
export COUNTRY_CONFIG_VERSION=${{ github.event.inputs.release_version }}
export COUNTRY_CONFIG_VERSION=${{ github.event.repository.name }}-${{ github.event.inputs.release_version }}
echo "Publishing a Docker image with a tag $COUNTRY_CONFIG_VERSION"
bash build-and-push.sh && unset COUNTRY_CONFIG_VERSION
70 changes: 0 additions & 70 deletions .github/workflows/test-restore-backup.yml

This file was deleted.

67 changes: 0 additions & 67 deletions infrastructure/backup-check.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ for i in "$@"; do
done

print_usage_and_exit() {
echo 'Usage: ./emergency-backup-metadata.sh --passphrase=XXX --ssh_user=XXX --ssh_host=XXX --ssh_port=XXX --production_ip=XXX --remote_dir=XXX --replicas=XXX --label=XXX'
echo 'Usage: ./backup.sh --passphrase=XXX --ssh_user=XXX --ssh_host=XXX --ssh_port=XXX --production_ip=XXX --remote_dir=XXX --replicas=XXX --label=XXX'
echo "Script must receive SSH details and a target directory of a remote server to copy backup files to."
echo "Optionally a LABEL i.e. 'v1.0.1' can be provided to be appended to the backup file labels"
echo "7 days of backup data will be retained in the manager node"
Expand Down Expand Up @@ -102,6 +102,10 @@ if [ "$IS_LOCAL" = false ]; then
echo "Error: Argument for the --replicas is required."
print_usage_and_exit
fi
if [ -z "$PASSPHRASE" ]; then
echo "Error: Argument for the --passphrase is required."
print_usage_and_exit
fi
# In this example, we load the MONGODB_ADMIN_USER, MONGODB_ADMIN_PASSWORD, ELASTICSEARCH_ADMIN_USER & ELASTICSEARCH_ADMIN_PASSWORD database access secrets from a file.
# We recommend that the secrets are served via a secure API from a Hardware Security Module
source /data/secrets/opencrvs.secrets
Expand Down Expand Up @@ -316,7 +320,7 @@ fi
if [[ "$OWN_IP" = "$PRODUCTION_IP" || "$OWN_IP" = "$(dig $PRODUCTION_IP +short)" ]]; then

# Create a temporary directory to store the backup files before packaging
BACKUP_RAW_FILES_DIR=/tmp/backup-$LABEL/
BACKUP_RAW_FILES_DIR=/tmp/backup-${LABEL:-$BACKUP_DATE}/
mkdir -p $BACKUP_RAW_FILES_DIR

# Copy full directories to the temporary directory
Expand Down
8 changes: 4 additions & 4 deletions infrastructure/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ mkdir -p /tmp/opencrvs/infrastructure/cryptfs
# Copy decrypt script
cp $BASEDIR/decrypt.sh /tmp/opencrvs/infrastructure/cryptfs/decrypt.sh

# Copy emergency backup script
cp $BASEDIR/emergency-backup-metadata.sh /tmp/opencrvs/infrastructure/emergency-backup-metadata.sh
# Copy backup script
cp $BASEDIR/backup.sh /tmp/opencrvs/infrastructure/backup.sh

# Copy emergency restore script
cp $BASEDIR/emergency-restore-metadata.sh /tmp/opencrvs/infrastructure/emergency-restore-metadata.sh
# Copy restore script
cp $BASEDIR/restore.sh /tmp/opencrvs/infrastructure/restore.sh

# Download base docker compose files to the server
rsync -e "ssh -p $SSH_PORT" --exclude='vagrant/' -rP /tmp/docker-compose* infrastructure $SSH_USER@$SSH_HOST:/opt/opencrvs/
Expand Down
7 changes: 7 additions & 0 deletions infrastructure/logrotate.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ include /etc/logrotate.d
rotate 1
}

/var/log/opencrvs-restore.log {
missingok
monthly
create 0660 root application
rotate 1
}

/var/log/setup-deploy-config.log {
missingok
monthly
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/monitoring/filebeat/filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ filebeat.inputs:
enabled: true
paths:
- /var/log/opencrvs-backup.log
- type: log
enabled: true
paths:
- /var/log/opencrvs-restore.log

# https://github.com/elastic/beats/blob/master/filebeat/filebeat.reference.yml

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/restore-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ cat $ARCHIVE_PATH | tar -xzf - -C $OPENCRVS_CORE_PATH/data/backups
# Automatically detect the label
LABEL=$(ls -t $OPENCRVS_CORE_PATH/data/backups/influxdb | head -n 1)

yes | bash $DIR/infrastructure/emergency-restore-metadata.sh --label=$LABEL --replicas=1
yes | bash $DIR/infrastructure/restore.sh --label=$LABEL --replicas=1
Loading