aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2015-03-20 01:07:55 +0100
committerDavid Runge <dave@sleepmap.de>2015-03-20 01:07:55 +0100
commit7054dc69613f47d2b68dbca06f4895fe52412f7c (patch)
tree98ae005be114e410c1739c80febd493bc0402f9b /scripts
parentc10efa7645f9f135b0a8513eeb69cb9d162d1728 (diff)
downloadcrypted-backups-7054dc69613f47d2b68dbca06f4895fe52412f7c.tar.gz
crypted-backups-7054dc69613f47d2b68dbca06f4895fe52412f7c.tar.bz2
crypted-backups-7054dc69613f47d2b68dbca06f4895fe52412f7c.tar.xz
crypted-backups-7054dc69613f47d2b68dbca06f4895fe52412f7c.zip
backup-mariadb: Adding first version of backup-mariadb script, service and timer.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/backup-mariadb30
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/backup-mariadb b/scripts/backup-mariadb
new file mode 100755
index 0000000..ae5d0ec
--- /dev/null
+++ b/scripts/backup-mariadb
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+# Set required settings
+timestamp="$(date +"%Y%m%d-%H%M%S")-"
+
+# If the backup location doesn't exist yet, create it
+if [ ! -d $mariadb_folder_destination ]; then
+ mkdir -p $mariadb_folder_destination
+fi
+
+# Get the names of all databases
+databases=`mysql --user=$mariadb_user -p$mariadb_password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|tmp)"`
+
+cd $tmp
+# Iterate over all database names and create a backup for each, encrypting them afterwards
+for db in $databases; do
+ echo "$db -> $mariadb_folder_destination$timestamp$db$sql_suffix$tar_suffix$gpg_suffix"
+ # dump .sql to /tmp
+ mysqldump --force --opt --user=$mariadb_user -p$mariadb_password --databases $db > $tmp$timestamp$db$sql_suffix
+ # tar in /tmp
+ tar cfJ $timestamp$db$sql_suffix$tar_suffix $timestamp$db$sql_suffix
+ # gpg to mariadb_folder_destination
+ gpg -e \
+ -r "$gpg_public_key" \
+ -o $mariadb_folder_destination$timestamp$db$sql_suffix$tar_suffix$gpg_suffix \
+ $timestamp$db$sql_suffix$tar_suffix
+ # delete tar and sql in /tmp
+ rm -f $timestamp$db$sql_suffix*
+done
+