I am trying to code a script to backup a server connected remotely. I just need to copy the “data” directory from “mysql” directory. For example, the file would be in \test_server\c$\mysql\data. And i want to copy to my own HD. In my own partition “D”. My code currently:
$date = Get-Date -Format dd.MM.yyyy
$source = “\teste\c$\teste.txt”
$destination = “D:$date”
$username = “xxx”
$password = “xxx”
$from = "XX "
$to = "XX "
$body = “Backup:”
$subject = “Backup of $date”
mkdir $date $WebClient = New-Object System.Net.WebClient $WebClient.Credentials = New-Object System.Net.NetworkCredential($username, $password) Copy-Item -Path \\teste\c$\test.txt -Destination D:\$date\test.txt; $backup_log = Dir -Recurse $destination | out-File "$destination\backup_log.txt" $attachment = "$destination\backup_log.txt"
send-MailMessage -From $from -To $to -Subject $subject -Attachments $attachment -Body $body -BodyAsHtml write-host "Backup Sucessfull" cd c:\