Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Add lock capabilities during snapshot (home-assistant#2063)
Browse files Browse the repository at this point in the history
* Add service which locks database tables

Add an additional service which helds a lock on all database tables.
This allows to safely snapshot the database files.

* Lock database during snapshot operation

Fixes: home-assistant#1353

* Update config.json

* Update CHANGELOG.md

Co-authored-by: Pascal Vizeli <[email protected]>
  • Loading branch information
agners and pvizeli authored Jun 17, 2021
1 parent 3cb9777 commit 1a10f96
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mariadb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.4.0

- Add lock capabilities during snapshot

## 2.3.0

- Option to grant user specific privileges for a database
Expand Down
4 changes: 3 additions & 1 deletion mariadb/config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "MariaDB",
"version": "2.3.0",
"version": "2.4.0",
"slug": "mariadb",
"description": "A SQL database server",
"url": "https://github.com/home-assistant/hassio-addons/tree/master/mariadb",
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
"startup": "system",
"init": false,
"timeout": 20,
"snapshot_pre": "/bin/s6-svc -wU -u /run/s6/services/mariadb-lock/",
"snapshot_post": "/bin/s6-svc -wd -d /run/s6/services/mariadb-lock/",
"services": ["mysql:provide"],
"ports": {
"3306/tcp": null
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions mariadb/rootfs/etc/services.d/mariadb-lock/notification-fd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
28 changes: 28 additions & 0 deletions mariadb/rootfs/etc/services.d/mariadb-lock/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start MariaDB client to lock tables (for snapshots)
# ==============================================================================

bashio::log.info "Lock tables using mariadb client..."

exec 4> >(mariadb)
MARIADB_PID=$!

echo "FLUSH TABLES WITH READ LOCK;" >&4

# Notify s6 about successful service start
echo "" >&3

bashio::log.info "MariaDB tables locked."

# Register stop
function stop_mariadb_client() {
echo "UNLOCK TABLES;" >&4
bashio::log.info "MariaDB tables unlocked."
exec 4>&-
# Successful exit, avoid wait exit status to propagate
exit 0
}
trap "stop_mariadb_client" SIGTERM SIGHUP

wait "${MARIADB_PID}"

0 comments on commit 1a10f96

Please sign in to comment.