mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 05:33:53 +01:00
feat - Add TARGET_DB_DUMP_PERMISSION to set file and directory permissions
This commit is contained in:
21
README.md
21
README.md
@@ -175,16 +175,17 @@ Your Organization will be mapped to `DB_USER` and your root token will need to b
|
|||||||
|
|
||||||
### Scheduling Options
|
### Scheduling Options
|
||||||
|
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
|
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
|
||||||
| `DB_DUMP_FREQ` | How often to do a dump, in minutes after the first backup. Defaults to 1440 minutes, or once per day. | `1440` |
|
| `DB_DUMP_FREQ` | How often to do a dump, in minutes after the first backup. Defaults to 1440 minutes, or once per day. | `1440` |
|
||||||
| `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | |
|
| `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | |
|
||||||
| | Absolute HHMM, e.g. `2330` or `0415` | |
|
| | Absolute HHMM, e.g. `2330` or `0415` | |
|
||||||
| | Relative +MM, i.e. how many minutes after starting the container, e.g. `+0` (immediate), `+10` (in 10 minutes), or `+90` in an hour and a half | |
|
| | Relative +MM, i.e. how many minutes after starting the container, e.g. `+0` (immediate), `+10` (in 10 minutes), or `+90` in an hour and a half | |
|
||||||
| `DB_DUMP_TARGET` | Directory where the database dumps are kept. | `${DB_DUMP_TARGET}/archive/` |
|
| `DB_DUMP_TARGET` | Directory where the database dumps are kept. | `${DB_DUMP_TARGET}/archive/` |
|
||||||
| `DB_DUMP_TARGET_ARCHIVE` | Optional Directory where the database dumps archives are kept. | |
|
| `DB_DUMP_TARGET_PERMISSION` | Directory and File permissions to apply to files. | `700` |
|
||||||
| `DB_CLEANUP_TIME` | Value in minutes to delete old backups (only fired when dump frequency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything. | `FALSE` |
|
| `DB_DUMP_TARGET_ARCHIVE` | Optional Directory where the database dumps archives are kept. | |
|
||||||
| `DB_ARCHIVE_TIME` | Value in minutes to move all files files older than (x) from `DB_DUMP_TARGET` to `DB_DUMP_TARGET_ARCHIVE` - which is useful when pairing against an external backup system. | |
|
| `DB_CLEANUP_TIME` | Value in minutes to delete old backups (only fired when dump frequency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything. | `FALSE` |
|
||||||
|
| `DB_ARCHIVE_TIME` | Value in minutes to move all files files older than (x) from `DB_DUMP_TARGET` to `DB_DUMP_TARGET_ARCHIVE` - which is useful when pairing against an external backup system. | |
|
||||||
|
|
||||||
- You may need to wrap your `DB_DUMP_BEGIN` value in quotes for it to properly parse. There have been reports of backups that start with a `0` get converted into a different format which will not allow the timer to start at the correct time.
|
- You may need to wrap your `DB_DUMP_BEGIN` value in quotes for it to properly parse. There have been reports of backups that start with a `0` get converted into a different format which will not allow the timer to start at the correct time.
|
||||||
|
|
||||||
|
|||||||
@@ -30,3 +30,4 @@ SIZE_VALUE=${SIZE_VALUE:-"bytes"}
|
|||||||
SKIP_AVAILABILITY_CHECK=${SKIP_AVAILABILITY_CHECK:-"FALSE"}
|
SKIP_AVAILABILITY_CHECK=${SKIP_AVAILABILITY_CHECK:-"FALSE"}
|
||||||
SPLIT_DB=${SPLIT_DB:-"TRUE"}
|
SPLIT_DB=${SPLIT_DB:-"TRUE"}
|
||||||
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
|
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
|
||||||
|
DB_DUMP_TARGET_PERMISSION=${DB_DUMP_TARGET_PERMISSION:-"700"}
|
||||||
@@ -5,9 +5,11 @@ bootstrap_filesystem() {
|
|||||||
mkdir -p "${DB_DUMP_TARGET}"
|
mkdir -p "${DB_DUMP_TARGET}"
|
||||||
fi
|
fi
|
||||||
if [ "$(stat -c %U "${DB_DUMP_TARGET}")" != "dbbackup" ] ; then chown -R dbbackup:dbbackup "${DB_DUMP_TARGET}" ; fi
|
if [ "$(stat -c %U "${DB_DUMP_TARGET}")" != "dbbackup" ] ; then chown -R dbbackup:dbbackup "${DB_DUMP_TARGET}" ; fi
|
||||||
|
if [ "$(stat -c %a "${DB_DUMP_TARGET}")" != "${DB_DUMP_TARGET_PERMISSION}" ] ; then chmod -R ${DB_DUMP_TARGET_PERMISSION} "${DB_DUMP_TARGET}" ; fi
|
||||||
|
|
||||||
if [ -d "${DB_DUMP_TARGET_ARCHIVE}" ]; then
|
if [ -d "${DB_DUMP_TARGET_ARCHIVE}" ]; then
|
||||||
if [ "$(stat -c %U "${DB_DUMP_TARGET_ARCHIVE}")" != "dbbackup" ] ; then chown -R dbbackup:dbbackup "${DB_DUMP_TARGET_ARCHIVE}" ; fi
|
if [ "$(stat -c %U "${DB_DUMP_TARGET_ARCHIVE}")" != "dbbackup" ] ; then chown -R dbbackup:dbbackup "${DB_DUMP_TARGET_ARCHIVE}" ; fi
|
||||||
|
if [ "$(stat -c %a "${DB_DUMP_TARGET_ARCHIVE}")" != "${DB_DUMP_TARGET_PERMISSION}" ] ; then chmod -R ${DB_DUMP_TARGET_PERMISSION} "${DB_DUMP_TARGET_ARCHIVE}" ; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "${TEMP_LOCATION}" ]; then
|
if [ ! -d "${TEMP_LOCATION}" ]; then
|
||||||
@@ -690,6 +692,7 @@ generate_checksum() {
|
|||||||
print_notice "Generating ${checksum_extension^^} for '${target}'"
|
print_notice "Generating ${checksum_extension^^} for '${target}'"
|
||||||
cd "${TEMP_LOCATION}"
|
cd "${TEMP_LOCATION}"
|
||||||
run_as_user ${checksum_command} "${target}" | run_as_user tee "${target}"."${checksum_extension}" > /dev/null
|
run_as_user ${checksum_command} "${target}" | run_as_user tee "${target}"."${checksum_extension}" > /dev/null
|
||||||
|
chmod ${DB_DUMP_TARGET_PERMISSION} "${target}"."${checksum_extension}"
|
||||||
## TODO - We're doing this twice, why not just pull from the previously generated file
|
## TODO - We're doing this twice, why not just pull from the previously generated file
|
||||||
checksum_value=$(run_as_user ${checksum_command} "${target}" | awk ' { print $1}')
|
checksum_value=$(run_as_user ${checksum_command} "${target}" | awk ' { print $1}')
|
||||||
print_debug "${checksum_extension^^}: ${checksum_value} - ${target}"
|
print_debug "${checksum_extension^^}: ${checksum_value} - ${target}"
|
||||||
@@ -723,6 +726,7 @@ move_dbbackup() {
|
|||||||
print_notice "Backup of ${target} created with the size of ${filesize}"
|
print_notice "Backup of ${target} created with the size of ${filesize}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
chmod ${DB_DUMP_TARGET_PERMISSION} "${TEMP_LOCATION}"/"${target}"
|
||||||
case "${BACKUP_LOCATION,,}" in
|
case "${BACKUP_LOCATION,,}" in
|
||||||
"file" | "filesystem" )
|
"file" | "filesystem" )
|
||||||
print_debug "Moving backup to filesystem"
|
print_debug "Moving backup to filesystem"
|
||||||
|
|||||||
Reference in New Issue
Block a user