Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Robocopy Timestamp

blackvan253

Technical User
Sep 13, 2024
3
Hi, I hope I'm in the correct forum ...

Here's my issue: when running a Robocopy backup, the timestamps in the log file output are all GMT-0 times, whereas my time zone is GMT+11.

However, the Date/time for the backed up files in Explorer is correctly reported. The Date/time in CMD is also correctly reported.

In Windows settings (WIN 10) my time zone is correctly set at UTC+10 with auto adjust for DST (currently true).

I can't think of one but is there another setting somewhere that I should be checking to get the log file to show my correct time zone?

Thanks!
 
Nope, Robocopy doesn't have any way to switch those entries from UTC to local time. The unwritten idea is that the log files were really meant to be parsed by a log file parser (I wrote one many years ago to support a disaster recovery program).
But a minimal idea would be to replace all the UTC time codes in the file with local times. And one way of doing that is to use Powershell , e.g

Rich (BB code):
$logPath = "d:\downloads\Logs\robocopy.log"
$outputPath = "d:\downloads\Logs\robocopy_localtime.log"

# Read the log file
$logLines = Get-Content $logPath

# Process each line
$convertedLines = $logLines | ForEach-Object {
    if ($_ -match '(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2})') {
        # Convert the found UTC timestamp to local time
        $utcTime = [datetime]::ParseExact($matches[1], "yyyy/MM/dd HH:mm:ss", $null, [System.Globalization.DateTimeStyles]::AssumeUniversal)
        $localTime = $utcTime.ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss")
        
        # Replace UTC timestamp with local time in the line
        $_ -replace $matches[1], $localTime
    } else {
        $_  # If no timestamp found, keep the line as is
    }
}

# Write the converted log to a new file
$convertedLines | Set-Content $outputPath

Write-Output "Conversion complete. Local time log saved to: $outputPath"
 

Part and Inventory Search

Sponsor

Back
Top