-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows-plesk-dump-sql.ps1
More file actions
50 lines (41 loc) · 1.61 KB
/
windows-plesk-dump-sql.ps1
File metadata and controls
50 lines (41 loc) · 1.61 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Configurações
$BackupDir = "C:\backup_bancos"
$MySQLUser = "admin"
$MySQLPassword = "<YOUR-PASSWORD-SQL-PLESK>"
$MySQLPort = 3306
$MySQLPath = "C:\Program Files (x86)\Plesk\MySQL\bin"
$FilePath = "lista.txt"
$WaitSeconds = 10
# Criar diretório de backup, se não existir
if (-Not (Test-Path -Path $BackupDir)) {
New-Item -ItemType Directory -Path $BackupDir | Out-Null
}
# Verificar se o arquivo de bancos existe
if (-Not (Test-Path -Path $FilePath)) {
Write-Host "ERRO: O arquivo $FilePath nao foi encontrado!" -ForegroundColor Red
Pause
Exit
}
# Ler cada linha do arquivo e executar o mysqldump
Get-Content $FilePath | ForEach-Object {
$DbName = $_.Trim()
# Verificar se o nome do banco não está vazio
if ($DbName -ne "") {
Write-Host "Exportando banco de dados: $DbName"
# Construir o comando mysqldump
$DumpCommand = """$MySQLPath\mysqldump"" -u$MySQLUser -p`"$MySQLPassword`" -P$MySQLPort $DbName > `"$BackupDir\$DbName.sql`""
# Executar o comando
cmd.exe /c $DumpCommand
# Verificar o código de saída
if ($LASTEXITCODE -ne 0) {
Write-Host "ERRO ao exportar o banco de dados: $DbName" -ForegroundColor Red
} else {
Write-Host "Sucesso ao exportar o banco: $DbName" -ForegroundColor Green
}
# Aguardar antes de continuar
Write-Host "Aguardando $WaitSeconds segundos antes de continuar..."
Start-Sleep -Seconds $WaitSeconds
}
}
Write-Host "Exportação concluída. Backups salvos em $BackupDir." -ForegroundColor Green
Pause