forked from Mailtrain-org/mailtrain
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
MYSQL_DATABASE=${MYSQL_DATABASE:-'mailtrain'} | ||
BACKUP_KEEP_DAYS=${BACKUP_KEEP_DAYS:-'90'} | ||
# test if variables S3_BUCKET, S3_ACCESS_KEY, S3_SECRET_KEY, S3_ENDPOINT, S3_REGION, S3_PATH are set | ||
if [ -z "${S3_BUCKET}" ] || [ -z "${S3_ACCESS_KEY}" ] || [ -z "${S3_SECRET_KEY}" ] || [ -z "${S3_ENDPOINT}" ] || [ -z "${S3_PATH}" ]; then | ||
echo "S3_BUCKET, S3_ACCESS_KEY, S3_SECRET_KEY, S3_ENDPOINT, S3_REGION, S3_PATH are not set" | ||
exit 1 | ||
fi | ||
|
||
# test is mysql variables are set | ||
if [ -z "${MYSQL_HOST}" ] || [ -z "${MYSQL_ROOT_PASSWORD}" ]; then | ||
echo "MYSQL_HOST and MYSQL_ROOT_PASSWORD must be set" | ||
exit 1 | ||
fi | ||
|
||
# test if mc is installed | ||
if [ -z "$(which mc)" ]; then | ||
echo "mc is not installed" | ||
exit 1 | ||
fi | ||
|
||
# Test if mc alias s3backup exists | ||
if [ -z "$(mc alias list | grep s3backup)" ]; then | ||
echo "s3backup alias not found" | ||
echo "create s3backup alias" | ||
mc alias set s3backup ${S3_ENDPOINT} ${S3_ACCESS_KEY} ${S3_SECRET_KEY} | ||
fi | ||
|
||
NOW=$(date -I) | ||
/usr/bin/mysqldump -h $MYSQL_HOST --password="$MYSQL_ROOT_PASSWORD" --all-databases >/app/server/files/backup.sql | ||
tar -cv /app/server/files/backup.sql /app/server/files/campaign /app/server/files/certs /app/server/files/imports /app/server/files/reports /app/server/files/template /app/server/files/uploaded | xz -9 >/app/server/files/backup.tar.xz | ||
rm /app/server/files/backup.sql | ||
mc cp /app/server/files/backup.tar.xz s3backup/${S3_BUCKET}/${S3_PATH}/backup-${NOW}.tar.xz | ||
|
||
# Remove backups older than BACKUP_KEEP_DAYS days | ||
mc rm --recursive --force --older-than ${BACKUP_KEEP_DAYS}d s3backup/${S3_BUCKET}/${S3_PATH} |