blob: ae5d0ec51d40f6cef7a490e52ed85d10ed09ce38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
|