0

I have written a simple script that launches robocopy in order to perform a backup. Now I would like to track the progress of such task.

In order to accomplish this I have measured the file size both from source and destination path with a chunck such as $size = Format-FileSize ((Get-Item $file).length). But it returns the same sizes for both source and destination, despite the fact that the copy was not finished yet.

As a workaround I also tried a dry run with robocopy (robocopy $file c:\fakepath /L /XJ /R:0 /W:1 /NP /E /BYTES /NFL /NDL /NJH /MT:64), but I have obtained the same result.

How can I actually check the backup progress?

  • Check out this [answer](https://stackoverflow.com/a/21209726/14903754) – Abraham Zinala Jul 05 '21 at 12:34
  • Your suggestion (as mine solution) work well if you have many little files to backup. Suppose, instead, of backupping a single very big file (ie 20GB). Robocopy first allocate the size, then proceeds with the copy. In this case the progress will inevitably show 100% for all the time. – Dario Corrada Jul 06 '21 at 09:30
  • I don't think you understand what's happening in the script. It will backup the files one at a time calculating the byte size as it goes; can also change your multi-threading to 128. An alternative is to calculate all the files to be copied first, then copy one at a time showing the progress of what file you're on. Is that what you're looking for? meant to comment, not answer lol – Abraham Zinala Jul 06 '21 at 12:19
  • Please correct me if I'm wrong... The function Copy-WithProgress reads the robocopy log in real time, the last line refers to the file it is currently copying and the script parse the original file size and sum it with the previuous ones to define the progress related to the total size. In such a way if the current file is so big (ie 20GB) the script will give an advance estimate of the size while it is still copying (20GB+ before finishing copying that file). In other words, if I would backup a folder with only a single huge file it would mark me 100% right away – Dario Corrada Jul 06 '21 at 12:40
  • The alternative solution of adopting cmdlet Copy-Item instead of robocopy sound to me not suitable for a backup task – Dario Corrada Jul 06 '21 at 12:49
  • You only have so much options, with the RoboCopy progress you're calculating the byte size, not the file count. – Abraham Zinala Jul 06 '21 at 12:54

1 Answers1

1

I have found a workaround, here there is my script for backup.

The progress is based on file count and NOT on transferred bytes (as I wished)