-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add DB Backup Script #692
base: master
Are you sure you want to change the base?
Add DB Backup Script #692
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Set the current date | ||
current_date=$(date +%m_%d_%Y) | ||
|
||
# Set the file name pattern | ||
file_name="coyote_db_${current_date}.sql" | ||
|
||
# Docker container name | ||
container_name="coyote_db_1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this is orchestrated via Docker Compose, can we execute commands via compose too, and reference service names instead of container names? I don't want to rely on container names when service names can be considered more stable. |
||
|
||
# Directory on the host where backups will be stored | ||
backup_dir=/root/db_backups | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think making this |
||
|
||
# 1. Create Postgres Dump inside the Docker Container | ||
docker exec -it $container_name bash -c "pg_dump -U postgres -d coyote > /$file_name" | ||
|
||
# 2. Copy the Dump from the Docker Container to the Host | ||
# Make sure the backup directory exists | ||
mkdir -p $backup_dir | ||
|
||
# Copy the file from the container to the host | ||
docker cp $container_name:/$file_name $backup_dir | ||
|
||
# 3. Compress the dump file using `gzip` | ||
xz $backup_dir/$file_name | ||
|
||
# 4. Remove the dump file from the container | ||
docker exec -it $container_name bash -c "rm /$file_name" | ||
|
||
# 5. Remove backup files older than 30 days | ||
find $backup_dir -type f -name "coyote_db_*.sql" -mtime +30 -exec rm {} \; |
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.
I thin
coyote_prod
would be more helpful here, in case we do end up backing up other environments. Even if we don't, it's more explicit, and unambiguous is what you need while restoring a broken system.