Help with Copying backup files and capture results in output file with details

  • Hi Team - I have the below PowerShell script which is working for me to capture the results for one set of backup file but my requirement is to copy 10 or more backups files parallelly to a shared location and capture the result and append the result to the result_log .CSV format....with the following result set....

    Can someone help me modify the script to capture these results plz ?  I am a newbie to PowerShell

    DBName  BackupPathAndName  BackupSizeMB  CopyStartDateTime  CopyEndDateTime  DurationSeconds

    --Working Powershell Script

    Start-Transcript

    $Password = ConvertTo-SecureString -AsPlainText -Force -String "Password"

    $User = "UserName"

    $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

    $item = get-item 'C:\Temp\BackupFileName.bak'

    $time=Measure-Command -Expression {Copy-Item -literalpath 'C:\Temp\BackupFileName.bak' '\\IP\Shared\TEST\BackupFileName.bak'}

    $TransferRate = ($item.length/1024/1024) / $time.TotalSeconds

    write-host "$TransferRate MB/Sec"

    $result = New-Object -TypeName psobject -Property @{

    Source = $item.fullname

    TimeTaken = $time.TotalSeconds

    TransferRateMBs = $TransferRate

    }

    $result|Export-Csv 'C:\temp\Result_Log.CSV' -Force -Append -NoTypeInformation

    Stop-Transcript

     

    Regards,
    SQLisAwe5oMe.

  • I'm no help here but that "password in text" stuff is one of the reasons I hate it. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I would recommend using Robocopy - it can be called from a PS script and there are many possible parameters to fit almost any requirement.

    The output from Robocopy also provides all of the information you need to track here - and that output can be redirected to another file and/or the console.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thanks Jeffrey, do you have a link you can refer me to?

    Regards,
    SQLisAwe5oMe.

  • SQLisAwe5oMe wrote:

    Thanks Jeffrey, do you have a link you can refer me to?

    It's part of the windows operating system.  Just Google it.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply