Initial
This commit is contained in:
		
							parent
							
								
									b18a7736a9
								
							
						
					
					
						commit
						9c8e60987d
					
				
							
								
								
									
										16
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								README.md
									
									
									
									
									
								
							| @ -1,3 +1,15 @@ | ||||
| # backupscript-collection | ||||
| # Mein Repository für Backup-Skripte | ||||
| 
 | ||||
| Eine kleine Sammlung an verschiedenen Backup-Scripten | ||||
| Dieses Repository dient als Plattform für eine Sammlung von Backup-Skripten. Hier werden Backup-Skripte gespeichert, versioniert und bearbeitet. | ||||
| 
 | ||||
| ## Beschreibung | ||||
| 
 | ||||
| Dieses Repository enthält eine Sammlung von Backup-Skripten, die für verschiedene Zwecke und Systeme entwickelt wurden. Es bietet eine zentrale Plattform zur Verwaltung dieser Skripte. | ||||
| 
 | ||||
| ## Verwendung | ||||
| 
 | ||||
| 1. **Klonen des Repositorys:** Um die Backup-Skripte herunterzuladen und zu verwenden, führe den folgenden Befehl aus: | ||||
| 
 | ||||
|    ```bash | ||||
|    git clone https://git.media-techport.de/scriptos/backup-script-collection.git | ||||
|    ``` | ||||
							
								
								
									
										49
									
								
								mariadb-backup.v1.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								mariadb-backup.v1.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| #!/bin/bash | ||||
| # Script Name:  MARIADB_BACKUP.V1.SH | ||||
| # Beschreibung: Macht ein Backup aller MariaDB-Datenbanken in ein Verzeichnis der Wahl | ||||
| # Aufruf:       ./bash MARIADB_BACKUP.V1.SH | ||||
| # Autor:        Patrick Asmus | ||||
| # Web:          https://www.media-techport.de | ||||
| # Git-Reposit.: https://git.media-techport.de/scriptos/backup-script-collection | ||||
| # Version:      2.0 | ||||
| # Datum:        03.09.2023 | ||||
| # Modifikation: Neuerstellung | ||||
| ##################################################### | ||||
| 
 | ||||
| # Variablen | ||||
| SCRIPT_NAME="mariadb-backup.v1.sh" | ||||
| BACKUP_DIR="/var/backup" | ||||
| LOGDIR="/var/log/script-logs" | ||||
| EMAIL_ADDRESS="system@media-techport.de" | ||||
| HOSTNAME=$(hostname) | ||||
| DB_USER="mysqlbackup" | ||||
| DB_PASSWORD="PASSWORD" | ||||
| BACKUP_RETENTION_DAYS=20 | ||||
| 
 | ||||
| # Erstelle Log-Verzeichnis | ||||
| mkdir -p $LOGDIR | ||||
| 
 | ||||
| # Sichern jeder Datenbank in separater SQL-Datei | ||||
| DATABASES=$(mysql -u "$DB_USER" -p"$DB_PASSWORD" -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql|sys)") | ||||
| ERROR_OCCURRED=0 | ||||
| 
 | ||||
| for DB in $DATABASES; do | ||||
|     DATE=$(date +%F) | ||||
|     BACKUP_FILE="$BACKUP_DIR/$DB-$DATE.sql" | ||||
|     echo "Sichere $DB-Datenbank in $BACKUP_FILE" | tee -a "$LOGDIR/$SCRIPT_NAME.log" | ||||
|     mysqldump -u "$DB_USER" -p"$DB_PASSWORD" "$DB" > "$BACKUP_FILE" | ||||
|     if [ $? -ne 0 ]; then | ||||
|         ERROR_OCCURRED=1 | ||||
|         echo "Fehler beim Sichern der $DB-Datenbank" | tee -a "$LOGDIR/$SCRIPT_NAME.log" | ||||
|     fi | ||||
| done | ||||
| 
 | ||||
| # Loeschen von Backups, die aelter als X Tage sind | ||||
| find "$BACKUP_DIR" -type f -name "*.sql" -mtime +$BACKUP_RETENTION_DAYS -delete | ||||
| 
 | ||||
| # Ueberpruefe, ob das Backup erfolgreich war oder Probleme aufgetreten sind | ||||
| if [ $ERROR_OCCURRED -eq 1 ]; then | ||||
|     echo "Backup konnte nicht ausgefuehrt werden." | tee -a "$LOGDIR/$SCRIPT_NAME.log" | ||||
|     mail -s "Fehler beim Ausführen des MariaDB-Backups auf $HOSTNAME" "$EMAIL_ADDRESS" < "$LOGDIR/$SCRIPT_NAME.log" | ||||
| fi | ||||
| exit 0 | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user