Page MenuHomeDevCentral

No OneTemporary

diff --git a/roles/dbserver-mysql/init.sls b/roles/dbserver-mysql/init.sls
index d5e7c10..9b0c33d 100644
--- a/roles/dbserver-mysql/init.sls
+++ b/roles/dbserver-mysql/init.sls
@@ -1,11 +1,12 @@
# -------------------------------------------------------------
# Salt — Database server — MySQL
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-10-27
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
include:
- .mysql-server
- .grc
+ - .treasure-chest
diff --git a/roles/dbserver-mysql/treasure-chest/files/db-treasure-import.sh b/roles/dbserver-mysql/treasure-chest/files/db-treasure-import.sh
new file mode 100755
index 0000000..c825c77
--- /dev/null
+++ b/roles/dbserver-mysql/treasure-chest/files/db-treasure-import.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# -------------------------------------------------------------
+# Import a MySQL database from the databases treasure chest
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: BSD-2-Clause
+# Source file: roles/dbserver-mysql/treasure-chest/files/db-treasure-import.sh
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+set -e
+
+DATABASES_BACKUP_PATH=/var/backups/db-treasure-chest
+DATABASES_MYSQL_PATH=/var/db/mysql
+
+# -------------------------------------------------------------
+# Ensure user is root
+#
+# Note: POSIX shells don't always define $UID or $EUID.
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ "$(id -u)" -ne 0 ]; then
+ echo "This command must be run as root." >&2
+ exit 1
+fi
+
+# -------------------------------------------------------------
+# Parse arguments
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ $# -eq 0 ]; then
+ echo "Usage: $(basename $0) <database>" >&2
+ exit 1
+fi
+
+DATABASE=$1
+
+if [ -d "$DATABASES_MYSQL_PATH/$DATABASE" ]; then
+ echo "Database $DATABASE seems already imported: directory exists in $DATABASES_MYSQL_PATH." >&2
+ exit 2
+fi
+
+if [ ! -f "$DATABASES_BACKUP_PATH/$DATABASE.sql" ]; then
+ echo "Database $DATABASE dump can't be found in DATABASES_BACKUP_PATH" >&2
+ exit 4
+fi
+
+# -------------------------------------------------------------
+# Restore database
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+mysql -e "CREATE DATABASE $DATABASE"
+mysql "$DATABASE" < "$DATABASES_BACKUP_PATH/$DATABASE.sql"
+echo "[$(date +%FT%H:%M:%S%z)] $DATABASE restored." >> "$DATABASES_BACKUP_PATH/_restored/_restore.log"
+mv "$DATABASES_BACKUP_PATH/$DATABASE.sql" "$DATABASES_BACKUP_PATH/_restored/"
diff --git a/roles/dbserver-mysql/treasure-chest/init.sls b/roles/dbserver-mysql/treasure-chest/init.sls
new file mode 100644
index 0000000..a54bb5a
--- /dev/null
+++ b/roles/dbserver-mysql/treasure-chest/init.sls
@@ -0,0 +1,35 @@
+# -------------------------------------------------------------
+# Salt — Database server — MySQL
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Description: A treasure chest to store databases we can
+# restore if needed. Those databases are no
+# longer in use but may contain valuable data
+# or serve to our inheritance.
+# -------------------------------------------------------------
+
+{% from "map.jinja" import dirs with context %}
+
+# -------------------------------------------------------------
+# X marks the spot.
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+/var/backups/db-treasure-chest:
+ file.directory:
+ - user: root
+ - mode: 700
+
+/var/backups/db-treasure-chest/_restored:
+ file.directory:
+ - user: root
+ - mode: 700
+
+# -------------------------------------------------------------
+# Found something? Here is the shovel.
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{{ dirs.bin }}/db-treasure-import:
+ file.managed:
+ - source: salt://roles/dbserver-mysql/treasure-chest/files/db-treasure-import.sh
+ - mode: 755

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 24, 21:16 (7 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2258932
Default Alt Text
(4 KB)

Event Timeline