Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Constants.
- $server = "127.0.0.1"
- $username = "root"
- $password = "ashley792"
- $backupFolder = "E:\MySQL_Backups\"
- $dbName = "AAProd"
- $MySQLDumpPath = "C:\Program Files\MariaDB 10.2\bin\mysqldump.exe"
- $MySQLPath = "C:\Program Files\MariaDB 10.2\bin\mysql.exe"
- $SevenZipPath = "C:\Program Files\7-Zip\7z.exe"
- $timestamp = Get-Date -format yyyy-MM-dd_HH-mm-ss
- $filename = $timestamp + "_" + $dbName + ".sql"
- $fullPath = $backupFolder + "" + $filename
- $zipfile = $backupFolder + $timestamp + "_" + $dbName + ".zip"
- #$limit = (Get-Date).AddDays(-31) # file retention period.
- # Flush all open tables before starting, may not need to do this any more.
- #& $MySQLPath --user="$username" --password="$password" --host="$server" --execute "FLUSH TABLES;"
- # Backup database to a file.
- & $MySQLDumpPath --user="$username" --password="$password" --host="$server" --routines --no-create-db --skip-opt $dbname > $fullPath
- # Archive the backup.
- & $SevenZipPath a -tzip $zipfile $fullPath
- # Remove unarchived copy.
- remove-item "$fullPath"
- # Delete old backups.
- # 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