Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Constants.
  2. $server         = "127.0.0.1"
  3. $username       = "root"
  4. $password       = "ashley792"
  5. $backupFolder   = "E:\MySQL_Backups\"
  6. $dbName         = "AAProd"
  7. $MySQLDumpPath  = "C:\Program Files\MariaDB 10.2\bin\mysqldump.exe"
  8. $MySQLPath      = "C:\Program Files\MariaDB 10.2\bin\mysql.exe"
  9. $SevenZipPath   = "C:\Program Files\7-Zip\7z.exe"
  10. $timestamp      = Get-Date -format yyyy-MM-dd_HH-mm-ss
  11. $filename       = $timestamp + "_" + $dbName + ".sql"
  12. $fullPath       = $backupFolder + "" + $filename
  13. $zipfile        = $backupFolder + $timestamp + "_" + $dbName + ".zip"
  14. #$limit          = (Get-Date).AddDays(-31) # file retention period.
  15.  
  16. # Flush all open tables before starting, may not need to do this any more.
  17. #& $MySQLPath --user="$username" --password="$password" --host="$server" --execute "FLUSH TABLES;"
  18.  
  19. # Backup database to a file.
  20. & $MySQLDumpPath --user="$username" --password="$password" --host="$server" --routines --no-create-db --skip-opt $dbname > $fullPath
  21.  
  22. # Archive the backup.
  23. & $SevenZipPath a -tzip $zipfile $fullPath
  24.  
  25. # Remove unarchived copy.
  26. remove-item "$fullPath"
  27.  
  28. # Delete old backups.
  29. # Get-ChildItem -Path $backupFolder -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement