Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3773465
D2985.id7619.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D2985.id7619.diff
View Options
diff --git a/roles/dbserver-mysql/init.sls b/roles/dbserver-mysql/init.sls
--- a/roles/dbserver-mysql/init.sls
+++ b/roles/dbserver-mysql/init.sls
@@ -9,3 +9,4 @@
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
--- /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
--- /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
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 07:21 (21 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260765
Default Alt Text
D2985.id7619.diff (4 KB)
Attached To
Mode
D2985: Allow to import database from Ysul on dbserver-mysql role
Attached
Detach File
Event Timeline
Log In to Comment