Anlage des Repos
This commit is contained in:
79
current/Backup-MariaDatabase/Backup-MariaDatabase.ps1
Normal file
79
current/Backup-MariaDatabase/Backup-MariaDatabase.ps1
Normal file
@@ -0,0 +1,79 @@
|
||||
cls
|
||||
|
||||
import-module SQLPS
|
||||
|
||||
Set-Variable Servername -Value "localhost" -Scope global
|
||||
Set-Variable Username -Value "root" -Scope global
|
||||
Set-Variable Passwort -Value "123456789dd!" -Scope global
|
||||
Set-Variable SicherungsPfad -Value "E:\Sicherung\MariaDB" -Scope global
|
||||
Set-Variable SicherungsPfadTemp -Value $null -Scope global
|
||||
Set-Variable holedatum -Value (get-date -Format 'yyyyMMdd_HHmm') -Scope global
|
||||
Set-Variable SicherungsPfadFinal -Value "\\dd-sto01\f$\DD-STO01-A3\Backup\Computer\DD-VMP02-DB01\MariaDB" -Scope global
|
||||
Set-Variable Datenbanken -Value @("nextcloud") -Scope global
|
||||
|
||||
# $dbs = Get-SqlDatabase -ServerInstance $Servername
|
||||
#######################################################################################################################
|
||||
Function Backup-SQLDatabases {
|
||||
|
||||
# Parameter definieren
|
||||
param(
|
||||
[parameter(mandatory=$true)]
|
||||
[validatecount(1, 10)]
|
||||
[string[]]$instanzen,
|
||||
[parameter(mandatory=$true)]
|
||||
[validatepattern("[A-Z]")]
|
||||
[validatecount(1,99)] #[validatecount(1, 9)]
|
||||
[string]$dbs
|
||||
)
|
||||
|
||||
$pfadzumbackup = $SicherungsPfad
|
||||
|
||||
if(!(test-path -Path "$($pfadzumbackup)\$holedatum")){
|
||||
try {
|
||||
new-item -path $pfadzumbackup -Name $holedatum -ItemType Directory -ErrorAction Stop | Out-Null
|
||||
Set-Variable SicherungsPfadTemp -Value "$($pfadzumbackup)\$holedatum" -Scope global
|
||||
}
|
||||
|
||||
catch {
|
||||
write-host "Ordner für Backup konnte nicht erstellt werden" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
else{
|
||||
write-host "Backup-Ordner existiert bereits" -ForegroundColor Yellow
|
||||
Set-Variable SicherungsPfadTemp -Value "$($pfadzumbackup)\$holedatum" -Scope global
|
||||
}
|
||||
|
||||
write-host "Backup von der Datenbank $dbs wird erstellt" -ForegroundColor Yellow
|
||||
$arguments = "--host=$($Servername) --port=3306 --user=$($Username) --password=$($Passwort) --databases $($dbs) --result-file $($SicherungsPfadTemp)\$($db).sql"
|
||||
write-host "Parameter $($arguments)" -ForegroundColor Yellow
|
||||
Start-Process -FilePath "mysqldump.exe" -ArgumentList $arguments -Wait
|
||||
}
|
||||
#######################################################################################################################
|
||||
#Call backup task for every db
|
||||
|
||||
#target must be online
|
||||
if (test-path -Path $SicherungsPfadFinal ) {
|
||||
|
||||
FOREACH ($db in $Datenbanken) {
|
||||
|
||||
[string]$db = $db
|
||||
$db = ($db.replace("[",""))
|
||||
$db = ($db.replace("]",""))
|
||||
|
||||
If ($db -ne "tempdb" -and $db -ne "master" -and $db -ne "model" -and $db -ne "msdb") {
|
||||
Write-Host "Sicherung von $db"
|
||||
Backup-SQLDatabases -instanzen $Servername -dbs $db
|
||||
}
|
||||
}
|
||||
#######################################################################################################################
|
||||
#move dir incl. backup files to sto01
|
||||
write-host $SicherungsPfadTemp
|
||||
Move-Item -Path $SicherungsPfadTemp -Destination $SicherungsPfadFinal -Force
|
||||
|
||||
}
|
||||
|
||||
Else {
|
||||
|
||||
Write-Host "Target is offline!"
|
||||
|
||||
}
|
||||
45
current/Backup-MariaDatabase/Backup-MariaDatabase_Caller.cmd
Normal file
45
current/Backup-MariaDatabase/Backup-MariaDatabase_Caller.cmd
Normal file
@@ -0,0 +1,45 @@
|
||||
@ECHO OFF
|
||||
TITLE DIGITAL DATA - Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Batch Script
|
||||
ECHO Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Digital Data
|
||||
ECHO Ludwig-Rinn-Strasse 16
|
||||
ECHO 35452 Heuchelheim
|
||||
ECHO Tel.: 0641 / 202360
|
||||
ECHO E-Mail: info@didalog.de
|
||||
ECHO -
|
||||
ECHO Version 1.0.0.0
|
||||
ECHO Date: 13.08.2015
|
||||
ECHO -
|
||||
ECHO Program Startup %date% at %time:~0,8% oclock, on %computername%.
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------set variables-------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
setlocal enableextensions
|
||||
|
||||
SET DIRECTORY="%cd%"
|
||||
SET FILEEXTENSION=*.ps1
|
||||
SET COUNT=0
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ---------------------Program 1 / Script 1---------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (ECHO %%f && set /a count+=1)
|
||||
ECHO -
|
||||
ECHO Found %count% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||
ECHO %DIRECTORY%.
|
||||
|
||||
ECHO -
|
||||
ECHO Running this/them now, with your permissions!
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (PowerShell.exe -Command "& {Start-Process PowerShell.exe -WindowStyle hidden '-ExecutionPolicy Bypass -File "%%f"'}")
|
||||
|
||||
ECHO -
|
||||
ECHO This Window will close in:
|
||||
#timeout /T 10
|
||||
endlocal
|
||||
exit
|
||||
Binary file not shown.
Reference in New Issue
Block a user