2022-10-01 19:59:53

This commit is contained in:
henk
2022-10-01 19:59:53 +02:00
parent b748aac2df
commit 51152e60c7
2 changed files with 51 additions and 2 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
Verschillende mysql tips mysql tips
Ik gebruik mariadb, installeren met
Ik gebruik mariadb, installeren als
apt install mariadb-server -y apt install mariadb-server -y
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
# Basic configuration: datestamp e.g. YYYYMMDD
DATE=$(date +"%Y%m%d")
# Location of your backups (create the directory first!)
BACKUP_DIR="/backup/mysql"
# MySQL login details
MYSQL_USER="root"
MYSQL_PASSWORD="YOURSECUREPASSWORD"
# MySQL executable locations (no need to change this)
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
# MySQL databases you wish to skip
SKIPDATABASES="Database|information_schema|performance_schema|mysql"
# Number of days to keep the directories (older than X days will be removed)
RETENTION=14
# ---- DO NOT CHANGE BELOW THIS LINE ------------------------------------------
#
# Create a new directory into backup directory location for this date
mkdir -p $BACKUP_DIR/$DATE
# Retrieve a list of all databases
databases=`$MYSQL -u$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "($SKIPDATABASES)"`
# Dumb the databases in seperate names and gzip the .sql file
for db in $databases; do
echo $db
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --skip-lock-tables --events --databases $db | gzip > "$BACKUP_DIR/$DATE/$db.sql.gz"
done
# Remove files older than X days
find $BACKUP_DIR/* -mtime +$RETENTION -delete