-
Notifications
You must be signed in to change notification settings - Fork 2
Backup cron jobs #307
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
Merged
Merged
Backup cron jobs #307
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
71d763b
wip: script to backup postgres database
paigewilliams 6b82fc0
Merge branch 'main' into backup-cron-jobs
paigewilliams 4ba064e
add script to set up cron job for sql dumps
paigewilliams 3392b0e
refactor db backup cron to just dump the db
paigewilliams 9cb57df
add flags to pg_dump
paigewilliams fa2ceb5
add instructions on setting up the backup cron job in install-docker-…
paigewilliams a06d019
fix name of db dump script to run
paigewilliams 8c648f2
copy instead of move .env.prod file
paigewilliams de8c67b
Merge branch 'main' into backup-cron-jobs
paigewilliams ca33bea
use path to docker in db-dump
paigewilliams e97fa9c
temporarily use backup-cron-jobs branch in install script
paigewilliams 12a10d3
check docker locations
paigewilliams 6840198
update TEKDB_ROOT dir
paigewilliams f61d806
store backups one directory out
paigewilliams eba4e3e
use docker group in install-docker-env.sh
paigewilliams 8e2853a
use sudo for docker commands
paigewilliams 4e2c476
include datetime in db-dump logs
paigewilliams 34b3e28
fix syntax for date parsing
paigewilliams a5c65f8
include datetime in all db-dump logs
paigewilliams 8b3d04c
switch to main branch in install-docker-env.sh
paigewilliams cff10e1
use sudo for crontab
paigewilliams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| ENV_FILE="${1:-}" | ||
|
|
||
| if [ -f "$ENV_FILE" ]; then | ||
| set -a | ||
| echo "$(date +"%Y-%m-%d %H:%M:%S") - Loading environment variables from $ENV_FILE..." | ||
| source "$ENV_FILE" | ||
| set +a | ||
| else | ||
| echo "$(date +"%Y-%m-%d %H:%M:%S") - Error: File "$ENV_FILE" not found. Please provide a valid environment file as an argument." | ||
| exit 1 | ||
| fi | ||
|
|
||
| CONTAINER_NAME=db | ||
| SQL_USER=${SQL_USER:?SQL_USER is not set} | ||
| SQL_DATABASE=${SQL_DATABASE:?SQL_DATABASE is not set} | ||
| BACKUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)/backups/postgres" | ||
|
|
||
| BACKUP_FILE="${BACKUP_DIR}/${SQL_DATABASE}.sql" | ||
|
|
||
| mkdir -p "${BACKUP_DIR}" | ||
|
|
||
| # Use full path to docker for cron compatibility | ||
| # Find docker location | ||
| if [ -x "/usr/bin/docker" ]; then | ||
| DOCKER_CMD="/usr/bin/docker" | ||
| elif [ -x "/usr/local/bin/docker" ]; then | ||
| DOCKER_CMD="/usr/local/bin/docker" | ||
| else | ||
| DOCKER_CMD="docker" | ||
| fi | ||
|
|
||
| echo "$(date +"%Y-%m-%d %H:%M:%S") - Dumping database '${SQL_DATABASE}' from container '${CONTAINER_NAME}' to '${BACKUP_FILE}'..." | ||
| "${DOCKER_CMD}" exec -t "${CONTAINER_NAME}" pg_dump -b -c -n public -O --quote-all-identifiers --no-acl -w -U "${SQL_USER}" "${SQL_DATABASE}" > "${BACKUP_FILE}" | ||
| echo "$(date +"%Y-%m-%d %H:%M:%S") - Database dump completed successfully." |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to change to
sudoto prevent error ofpermission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock