mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 13:44:08 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbe9dde4a1 | ||
|
|
eb2a18672b | ||
|
|
5f784ed156 | ||
|
|
d9a4690ea2 |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,3 +1,22 @@
|
|||||||
|
## 3.0.16 2022-03-23 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix for SPLIT_DB not looping through all databse names properly
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.15 2022-03-22 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Rework compression function
|
||||||
|
- Fix for Bzip compression failing
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.14 2022-03-22 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Rearrange Notice stating when next backup is going to start
|
||||||
|
|
||||||
|
|
||||||
## 3.0.13 2022-03-21 <dave at tiredofit dot ca>
|
## 3.0.13 2022-03-21 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ services:
|
|||||||
- example-db
|
- example-db
|
||||||
volumes:
|
volumes:
|
||||||
- ./backups:/backup
|
- ./backups:/backup
|
||||||
- ./post-script.sh:/assets/custom-scripts/post-script.sh
|
#- ./post-script.sh:/assets/custom-scripts/post-script.sh
|
||||||
environment:
|
environment:
|
||||||
- DB_TYPE=mariadb
|
- DB_TYPE=mariadb
|
||||||
- DB_HOST=example-db
|
- DB_HOST=example-db
|
||||||
@@ -30,8 +30,8 @@ services:
|
|||||||
- DB_DUMP_FREQ=1440
|
- DB_DUMP_FREQ=1440
|
||||||
- DB_DUMP_BEGIN=0000
|
- DB_DUMP_BEGIN=0000
|
||||||
- DB_CLEANUP_TIME=8640
|
- DB_CLEANUP_TIME=8640
|
||||||
- CHECKSUM=MD5
|
- CHECKSUM=SHA1
|
||||||
- COMPRESSION=XZ
|
- COMPRESSION=ZSTD
|
||||||
- SPLIT_DB=FALSE
|
- SPLIT_DB=FALSE
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,5 @@
|
|||||||
#!/command/with-contenv bash
|
#!/command/with-contenv bash
|
||||||
|
|
||||||
bootstrap_compression() {
|
|
||||||
### Set Compression Options
|
|
||||||
if var_true "${ENABLE_PARALLEL_COMPRESSION}" ; then
|
|
||||||
print_debug "Utilizing '${PARALLEL_COMPRESSION_THREADS}' compression threads"
|
|
||||||
bzip="pbzip2 -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS}"
|
|
||||||
gzip="pigz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS}"
|
|
||||||
xzip="pixz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS}"
|
|
||||||
zstd="zstd --rm -${COMPRESSION_LEVEL} -T${PARALLEL_COMPRESSION_THREADS}"
|
|
||||||
else
|
|
||||||
print_debug "Utilizing single compression thread"
|
|
||||||
bzip="pbzip2 -${COMPRESSION_LEVEL} -p 1"
|
|
||||||
gzip="pigz -${COMPRESSION_LEVEL} -p 1"
|
|
||||||
xzip="pixz -${COMPRESSION_LEVEL} -p 1"
|
|
||||||
zstd="zstd --rm -${COMPRESSION_LEVEL} -T1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
bootstrap_variables() {
|
bootstrap_variables() {
|
||||||
case "${dbtype,,}" in
|
case "${dbtype,,}" in
|
||||||
couch* )
|
couch* )
|
||||||
@@ -95,7 +78,7 @@ backup_couch() {
|
|||||||
target=couch_${dbname}_${dbhost}_${now}.txt
|
target=couch_${dbname}_${dbhost}_${now}.txt
|
||||||
compression
|
compression
|
||||||
print_notice "Dumping CouchDB database: '${dbname}'"
|
print_notice "Dumping CouchDB database: '${dbname}'"
|
||||||
curl -X GET http://${dbhost}:${dbport}/${dbname}/_all_docs?include_docs=true ${dumpoutput} | $dumpoutput > ${TEMP_LOCATION}/${target}
|
curl -X GET http://${dbhost}:${dbport}/${dbname}/_all_docs?include_docs=true ${compress_cmd} | $compress_cmd > ${TEMP_LOCATION}/${target}
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code
|
check_exit_code
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -156,13 +139,14 @@ backup_mysql() {
|
|||||||
fi
|
fi
|
||||||
if var_true "${SPLIT_DB}" ; then
|
if var_true "${SPLIT_DB}" ; then
|
||||||
DATABASES=$(mysql -h ${dbhost} -P $dbport -u$dbuser --batch -e "SHOW DATABASES;" | grep -v Database | grep -v schema)
|
DATABASES=$(mysql -h ${dbhost} -P $dbport -u$dbuser --batch -e "SHOW DATABASES;" | grep -v Database | grep -v schema)
|
||||||
for db in "${DATABASES}" ; do
|
print_debug "Backing up everything except for information_schema and _* prefixes"
|
||||||
|
print_debug "Databases Found: ${DATABASES}"
|
||||||
|
for db in ${DATABASES} ; do
|
||||||
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
|
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
|
||||||
print_debug "Backing up everything except for information_schema and _* prefixes"
|
|
||||||
print_notice "Dumping MySQL/MariaDB database: '${db}'"
|
print_notice "Dumping MySQL/MariaDB database: '${db}'"
|
||||||
target=mysql_${db}_${dbhost}_${now}.sql
|
target=mysql_${db}_${dbhost}_${now}.sql
|
||||||
compression
|
compression
|
||||||
mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -h $dbhost -P $dbport -u$dbuser ${single_transaction} ${stored_procedures} ${EXTRA_OPTS} --databases $db | $dumpoutput > ${TEMP_LOCATION}/${target}
|
mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -h $dbhost -P $dbport -u$dbuser ${single_transaction} ${stored_procedures} ${EXTRA_OPTS} --databases $db | $compress_cmd > "${TEMP_LOCATION}"/"${target}"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code
|
check_exit_code
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -172,7 +156,7 @@ backup_mysql() {
|
|||||||
else
|
else
|
||||||
compression
|
compression
|
||||||
print_notice "Dumping MySQL/MariaDB database: '${DB_NAME}'"
|
print_notice "Dumping MySQL/MariaDB database: '${DB_NAME}'"
|
||||||
mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -A -h $dbhost -P $dbport -u$dbuser ${single_transaction} ${stored_procedures} ${EXTRA_OPTS} | $dumpoutput > ${TEMP_LOCATION}/${target}
|
mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -A -h $dbhost -P $dbport -u$dbuser ${single_transaction} ${stored_procedures} ${EXTRA_OPTS} | $compress_cmd > "${TEMP_LOCATION}"/"${target}"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code
|
check_exit_code
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -183,15 +167,15 @@ backup_mysql() {
|
|||||||
backup_pgsql() {
|
backup_pgsql() {
|
||||||
export PGPASSWORD=${dbpass}
|
export PGPASSWORD=${dbpass}
|
||||||
if var_true "${SPLIT_DB}" ; then
|
if var_true "${SPLIT_DB}" ; then
|
||||||
|
|
||||||
authdb=${DB_USER}
|
authdb=${DB_USER}
|
||||||
[ -n "${DB_NAME}" ] && authdb=${DB_NAME}
|
[ -n "${DB_NAME}" ] && authdb=${DB_NAME}
|
||||||
DATABASES=$(psql -h $dbhost -U $dbuser -p ${dbport} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' )
|
DATABASES=$(psql -h $dbhost -U $dbuser -p ${dbport} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' )
|
||||||
for db in "${DATABASES}"; do
|
print_debug "Databases Found: ${DATABASES}"
|
||||||
|
for db in $DATABASES ; do
|
||||||
print_notice "Dumping Postgresql database: $db"
|
print_notice "Dumping Postgresql database: $db"
|
||||||
target=pgsql_${db}_${dbhost}_${now}.sql
|
target=pgsql_${db}_${dbhost}_${now}.sql
|
||||||
compression
|
compression
|
||||||
pg_dump -h ${dbhost} -p ${dbport} -U ${dbuser} $db ${EXTRA_OPTS} | $dumpoutput > ${TEMP_LOCATION}/${target}
|
pg_dump -h ${dbhost} -p ${dbport} -U ${dbuser} $db ${EXTRA_OPTS} | $compress_cmd > ${TEMP_LOCATION}/${target}
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code
|
check_exit_code
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -199,8 +183,8 @@ backup_pgsql() {
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
compression
|
compression
|
||||||
print_notice "Dumping PostgreSQL: '${DB_NAME}'"
|
print_notice "Dumping PostgreSQL database: '${DB_NAME}'"
|
||||||
pg_dump -h ${dbhost} -U ${dbuser} -p ${dbport} ${dbname} ${EXTRA_OPTS} | $dumpoutput > ${TEMP_LOCATION}/${target}
|
pg_dump -h ${dbhost} -U ${dbuser} -p ${dbport} ${dbname} ${EXTRA_OPTS} | $compress_cmd > ${TEMP_LOCATION}/${target}
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code
|
check_exit_code
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -227,7 +211,7 @@ backup_redis() {
|
|||||||
done
|
done
|
||||||
target_original=${target}
|
target_original=${target}
|
||||||
compression
|
compression
|
||||||
$dumpoutput "${TEMP_LOCATION}/${target_original}"
|
$compress_cmd "${TEMP_LOCATION}/${target_original}"
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_backup
|
move_backup
|
||||||
}
|
}
|
||||||
@@ -242,7 +226,7 @@ backup_sqlite3() {
|
|||||||
sqlite3 "${dbhost}" ".backup '${TEMP_LOCATION}/backup.sqlite3'"
|
sqlite3 "${dbhost}" ".backup '${TEMP_LOCATION}/backup.sqlite3'"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code
|
check_exit_code
|
||||||
cat "${TEMP_LOCATION}"/backup.sqlite3 | $dumpoutput > "${TEMP_LOCATION}/${target}"
|
cat "${TEMP_LOCATION}"/backup.sqlite3 | $compress_cmd > "${TEMP_LOCATION}/${target}"
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_backup
|
move_backup
|
||||||
}
|
}
|
||||||
@@ -340,34 +324,38 @@ check_exit_code() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compression() {
|
compression() {
|
||||||
|
if var_false "${ENABLE_PARALLEL_COMPRESSION}" ; then
|
||||||
|
PARALLEL_COMPRESSION_THREADS=1
|
||||||
|
fi
|
||||||
|
|
||||||
case "${COMPRESSION,,}" in
|
case "${COMPRESSION,,}" in
|
||||||
gz* )
|
gz* )
|
||||||
print_notice "Compressing backup with gzip"
|
print_notice "Compressing backup with gzip"
|
||||||
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
||||||
target=${target}.gz
|
target=${target}.gz
|
||||||
dumpoutput="$gzip "
|
compress_cmd="pigz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS} "
|
||||||
;;
|
;;
|
||||||
bz* )
|
bz* )
|
||||||
print_notice "Compressing backup with bzip2"
|
print_notice "Compressing backup with bzip2"
|
||||||
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
||||||
target=${target}.bz2
|
target=${target}.bz2
|
||||||
dumpoutput="$bzip "
|
compress_cmd="pbzip2 -${COMPRESSION_LEVEL} -p${PARALLEL_COMPRESSION_THREADS} "
|
||||||
;;
|
;;
|
||||||
xz* )
|
xz* )
|
||||||
print_notice "Compressing backup with xzip"
|
print_notice "Compressing backup with xzip"
|
||||||
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
||||||
target=${target}.xz
|
target=${target}.xz
|
||||||
dumpoutput="$xzip "
|
compress_cmd="pixz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS} "
|
||||||
;;
|
;;
|
||||||
zst* )
|
zst* )
|
||||||
print_notice "Compressing backup with zstd"
|
print_notice "Compressing backup with zstd"
|
||||||
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
print_debug "Compression Level: '${COMPRESSION_LEVEL}'"
|
||||||
target=${target}.zst
|
target=${target}.zst
|
||||||
dumpoutput="$zstd "
|
compress_cmd="zstd --rm -${COMPRESSION_LEVEL} -T${PARALLEL_COMPRESSION_THREADS}"
|
||||||
;;
|
;;
|
||||||
"none" | "false")
|
"none" | "false")
|
||||||
print_notice "Not compressing backups"
|
print_notice "Not compressing backups"
|
||||||
dumpoutput="cat "
|
compress_cmd="cat "
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ source /assets/functions/00-container
|
|||||||
source /assets/functions/10-db-backup
|
source /assets/functions/10-db-backup
|
||||||
source /assets/defaults/10-db-backup
|
source /assets/defaults/10-db-backup
|
||||||
PROCESS_NAME="db-backup"
|
PROCESS_NAME="db-backup"
|
||||||
|
CONTAINER_LOG_LEVEL=DEBUG
|
||||||
|
|
||||||
bootstrap_compression
|
|
||||||
bootstrap_variables
|
bootstrap_variables
|
||||||
|
|
||||||
if [ "${MODE,,}" = "manual" ] ; then
|
if [ "${MODE,,}" = "manual" ] ; then
|
||||||
@@ -25,7 +25,7 @@ case "${1,,}" in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
### Container Startup
|
### Container Startup
|
||||||
print_debug "Backup routines Initialized on $(date)"
|
print_debug "Backup routines Initialized on $(date +'%Y-%m-%d %H:%M:%S')"
|
||||||
|
|
||||||
### Wait for Next time to start backup
|
### Wait for Next time to start backup
|
||||||
case "${1,,}" in
|
case "${1,,}" in
|
||||||
@@ -142,7 +142,7 @@ while true; do
|
|||||||
exit ${exit_code};
|
exit ${exit_code};
|
||||||
else
|
else
|
||||||
### Go back to sleep until next backup time
|
### Go back to sleep until next backup time
|
||||||
sleep $(($DB_DUMP_FREQ*60-backup_total_time))
|
|
||||||
print_notice "Sleeping for another $(($DB_DUMP_FREQ*60-backup_total_time)) seconds. Waking up at $(date -d@"$(( $(date +%s)+$(($DB_DUMP_FREQ*60-backup_total_time))))" +"%Y-%m-%d %T %Z") "
|
print_notice "Sleeping for another $(($DB_DUMP_FREQ*60-backup_total_time)) seconds. Waking up at $(date -d@"$(( $(date +%s)+$(($DB_DUMP_FREQ*60-backup_total_time))))" +"%Y-%m-%d %T %Z") "
|
||||||
|
sleep $(($DB_DUMP_FREQ*60-backup_total_time))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user