Backup-WebConfiguration (incrementing) ?

Welcome Forums General PowerShell Q&A Backup-WebConfiguration (incrementing) ?

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
1 day, 11 hours ago.

  • Author
    Posts
  • #128711

    Participant
    Points: 28
    Rank: Member

    Hi Folks,

    I have some PS scripts that do different IIS related things on multiple servers at the same time. So, before anything I'm making a backup of IIS, via the

    Backup-WebConfiguration -Name $backupname-$timestamp

    As I could run more scripts many times on all servers, it creates a lot of backups. That's not the problem. My problem (using the example above) is that the $timestamp variable to make each backup unique (because it will error if I give the same name each time) is set up as follows:

    $timestamp = get-date -Format 'dd.MM.yyy-HH.mm.ss''
    

    $backupname is the name of the application the script works on – usually a website name. ie – utilities.com etc

    That makes it quite unique even if I ran another script 1 second later.

    The problem is that if I run a script on about 10 servers, the backups are all slightly different file names (a couple seconds different, changes the file name)  This is fine, but when it comes to do a restore, I need to be able to restore on ALL 10 servers at once – ie, find the same backup set – so all are restored to before THAT script was run, ie. that backup.

    So I need a way to create a unique backup file each time on ALL servers, that is named the same. So if I do a restore, I can use the same name on all servers.

    I'm just stumped, thinking of how...

    I'd have to check set some kind of starting counter, and add that to a variable to add to the end of Backup-Webconfiguration -Name $string

    I guess I'd need an equal starting point on ALL servers too – ie. check the backup file names first?

    Perhaps I should do the backup, then just rename it to a file with an incrementing counter – that way it renames on all servers at the same time it runs the script on all servers?

    But I just cant figure out where to start.... any ideas or advice would be greatly appreciated!

     

    THANKS!

     

  • #128741

    Participant
    Points: 23
    Rank: Member

    How are you starting the scripts on the remote servers?

    Can you not just get the timestamp on the calling computer and pass it to all the remote machines with $using?

    It'll be something like this:

    $timestamp = get-date -Format 'dd.MM.yyy-HH.mm.ss''
    $backupname = 'MyApplication'
    
    Invoke-Command -ComputerName server01,server02,server03 -ScriptBlock { Backup-WebConfiguration -Name "$using:$backupname-$using:timestamp" }
    

    I don't have a another machine to test on so I suspect the syntax is a bit wonky, but that should give you an idea.

    • #128787

      Participant
      Points: 28
      Rank: Member

      Hey Matt, Yes – that is the easiest solution. I'll pass the timestamp from the 'script running server', so it gets a unique value there and then – then sends to the other servers to create the backupname ! Sweet ! I should have thought of that.  Now, at least all backups have the exact unique name, and then a restore, I only need to request the same value in the variable, and all 10 servers would be restored with that same back up file!

      PS. I'm using a fantastic tool called System Frontier, from Noxigen LLC. It's a role based access model web app to manage servers, but the coolest part is the front end to powershell scripts (it creates the HTML form and everything! Really worth a look, if you need that type of setup – plus their support is top notch!

      Thanks for all who replied, this forum is always super friendly and non judging ! 🙂

      Have a great week folks!

  • #128765

    Participant
    Points: 306
    Helping Hand
    Rank: Contributor

    As for this...

    I need to be able to restore on ALL 10 servers at once

    … this is what PS sessions / jobs / parallel processing is all about.

    https://blogs.technet.microsoft.com/heyscriptingguy/2012/11/07/powertip-run-a-powershell-command-on-multiple-servers-at-the-same-time

You must be logged in to reply to this topic.