-
Notifications
You must be signed in to change notification settings - Fork 1
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 email notify support #1
Open
abhinand-tw
wants to merge
3
commits into
dopos:master
Choose a base branch
from
abhinand-tw:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -9,6 +9,10 @@ BACKUP_ENABLED ?= no | |
DB_NAME ?= template1 | ||
# Cron args | ||
BACKUP_CRON ?= 10 5 * * * | ||
# The address to which error messages will be sent | ||
# to change address you need delete file /etc/cron.d/backup, | ||
# change address and update deploy | ||
EMAIL_ADMIN ?= admin@domain.local | ||
|
||
# dcape container name prefix | ||
DCAPE_PROJECT_NAME ?= dcape | ||
|
@@ -26,6 +30,10 @@ BACKUP_ENABLED=$(BACKUP_ENABLED) | |
DB_NAME=$(DB_NAME) | ||
# Cron args | ||
BACKUP_CRON=$(BACKUP_CRON) | ||
# The address to which error messages will be sent | ||
# to change address you need delete file /etc/cron.d/backup, | ||
# change address and update deploy | ||
EMAIL_ADMIN=$(EMAIL_ADMIN) | ||
|
||
# dcape postgresql container name | ||
DCAPE_DB=$(DCAPE_DB) | ||
|
@@ -39,21 +47,49 @@ export CONFIG_DEF | |
|
||
define EXP_SCRIPT | ||
[[ "$$DCAPE_DB_DUMP_DEST" ]] || { echo "DCAPE_DB_DUMP_DEST not set. Exiting" ; exit 1 ; } ; \ | ||
WEEK_PARITY=$$(($$(date +%U) %2)); \ | ||
DAY_TO_PROC=4; \ | ||
DAY_OF_MONTH=$$(date +%d); \ | ||
DAY_OF_WEEK=$$(date +%u); \ | ||
MONTH_TO_KEEP=(1 * 30); \ | ||
WEEKS_TO_KEEP=(2 * 7); \ | ||
DAYS_TO_KEEP=3; \ | ||
find $$DCAPE_DB_DUMP_DEST -type f -mtime +$$MONTH_TO_KEEP -name "*-monthly.tgz" | xargs --no-run-if-empty 'rm -f' ';' \ | ||
find $$DCAPE_DB_DUMP_DEST -type f -mtime +$$WEEKS_TO_KEEP -name "*-weekly.tgz" | xargs --no-run-if-empty 'rm -f' ';' \ | ||
find $$DCAPE_DB_DUMP_DEST -type f -mtime +$$DAYS_TO_KEEP -name "*-daily.tgz" | xargs --no-run-if-empty 'rm -f' ';' \ | ||
DBS=$$@ ; \ | ||
[[ "$$DBS" ]] || DBS=all ; \ | ||
dt=$$(date +%y%m%d) ; \ | ||
if [[ $$DBS == "all" ]] ; then \ | ||
echo "Exporting all databases..." ; \ | ||
DBS=$$(psql --tuples-only -P format=unaligned -U postgres \ | ||
DBS=$$(psql --tuples-only -P format=unaligned -U postgres \ | ||
-c "SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'") ; \ | ||
fi ; \ | ||
echo "Backup DBs: $$DBS" ; \ | ||
for d in $$DBS ; do \ | ||
dest=$$DCAPE_DB_DUMP_DEST/$${d%%.*}-$${dt}.tgz ; \ | ||
echo -n $${dest}... ; \ | ||
[ -f $$dest ] && { echo Skip ; continue ; } ; \ | ||
echo -n "Make daily backup DBs: $$DBS" ; \ | ||
dest=$$DCAPE_DB_DUMP_DEST/$${d%%.*}-$${dt}-daily.tgz ; \ | ||
echo -n "$${dest}..." ; \ | ||
[ -f $$dest ] && { echo Exist ; } ; \ | ||
pg_dump -d $$d -U postgres -Ft | gzip > $$dest || echo "error" ; \ | ||
echo Done ; \ | ||
echo "Daily done!" ; \ | ||
echo -n "Make weekly backup DBs: $$DBS" ; \ | ||
dest=$$DCAPE_DB_DUMP_DEST/$${d%%.*}-$${dt}-weekly.tgz ; \ | ||
echo -n "$${dest}..." ; \ | ||
[ -f $$dest ] && { echo Exist ; } ; \ | ||
if [ $$WEEK_PARITY == "0" ]; then \ | ||
if [[ $$DAY_OF_WEEK == $$DAY_TO_PROC ]]; then \ | ||
pg_dump -d $$d -U postgres -Ft | gzip > $$dest || echo "error" ; \ | ||
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. не стоит нагружать БД дублированием дампа. Файл уже есть, можно его |
||
echo "Weekly done!" ; \ | ||
fi; \ | ||
fi; \ | ||
echo -n "Make monthly backup DBs: $$DBS" ; \ | ||
dest=$$DCAPE_DB_DUMP_DEST/$${d%%.*}-$${dt}-monthly.tgz ; \ | ||
echo -n "$${dest}..." ; \ | ||
[ -f $$dest ] && { echo Exist ; } ; \ | ||
if [[ $$DAY_OF_MONTH == "03" ]]; then \ | ||
pg_dump -d $$d -U postgres -Ft | gzip > $$dest || echo "error" ; \ | ||
echo "Monthly done!" ; \ | ||
fi; \ | ||
done | ||
endef | ||
export EXP_SCRIPT | ||
|
@@ -93,10 +129,15 @@ docker-wait: | |
# DB operations | ||
|
||
## Setup host system cron | ||
## If need change the target "cron", you need delete file /etc/cron.d/backup | ||
## otherwise: make cron -> make: nothing to do for cron | ||
cron: /etc/cron.d/backup | ||
|
||
/etc/cron.d/backup: | ||
echo "$$BACKUP_CRON op cd $$PWD && make backup" > $@ | ||
echo "# Set the email to wich error message will be sent" > $@ | ||
echo "MAILTO=$$EMAIL_ADMIN" >> $@ | ||
echo "# Set cron command with disable STDOUT for cron sent mail only if error exist" >> $@ | ||
echo "$$BACKUP_CRON op cd $$PWD && make backup > /dev/null" >> $@ | ||
|
||
## dump all databases or named database | ||
backup: docker-wait | ||
|
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
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.
space?