title: Parse the backup\restore path and filename during the backup\restore
body: <p>I'm writing a webapp that monitors backup and restores while they are happening.  What I've been asked to add to it was a way to show the backup\restore path and filename <strong><em>as it's happening</em></strong>.
  I'm able to, of course, get the command line that is running during the backup\restore so what I'd like to do is extract the path and filename from that command line.
  So with my current code I am able to get this in a return by itself:</p>
  
  <pre><code>BACKUP DATABASE [DatabaseName] TO DISK = N'\\nas01\sqlbackups$\ServerName\DatabaseName.bak'   WITH NOFORMAT,   INIT,   NAME = N'DatabaeName-Full Database Backup',   SKIP,   NOREWIND,   NOUNLOAD,   STATS = 10  
  </code></pre>
  
  <p>What I'd like to extract from that is <strong>\\nas01\sqlbackups$\ServerName\DatabaseName.bak</strong></p>
  
  <p>If not extracting from the code, is there a way to grab that from another table, <strong><em>while it's currently running?</em></strong></p>
  
  <p>This is the code I run to get the state of a current backup\restore:</p>
  
  <pre><code>SELECT r.session_id
  ,r.command
  ,CONVERT(NUMERIC(6, 2), r.percent_complete) AS [Percent Complete]
  ,CONVERT(VARCHAR(20), DATEADD(ms, r.estimated_completion_time, GetDate()), 20) AS [ETA Completion Time]
  ,CONVERT(NUMERIC(10, 2), r.total_elapsed_time / 1000.0 / 60.0) AS [Elapsed Min]
  ,CONVERT(NUMERIC(10, 2), r.total_elapsed_time / 1000.0 / 60.0 / 60.0) AS [Elapsed Hours]
  ,CONVERT(NUMERIC(10, 2), r.estimated_completion_time / 1000.0 / 60.0) AS [ETA Min]
  ,CONVERT(NUMERIC(10, 2), r.estimated_completion_time / 1000.0 / 60.0 / 60.0) AS [ETA Hours]
  ,CONVERT(VARCHAR(1000), (
          SELECT SUBSTRING(TEXT, r.statement_start_offset / 2, CASE 
                      WHEN r.statement_end_offset = - 1
                          THEN 1000
                      ELSE (r.statement_end_offset - r.statement_start_offset) / 2
                      END)
          FROM sys.dm_exec_sql_text(sql_handle)
          )) AS [TSQLCode]    
          FROM sys.dm_exec_requests r 
  WHERE command IN (
      'RESTORE DATABASE'
      ,'BACKUP DATABASE'
      ,'BACKUP LOG'
      ,'RESTORE LOG'
      )
  </code></pre>