0

We have a script that was supposed to move LOG files off a server onto a local repository. It turned out the author of the script added an apostrophe by accident in the destination:

MOVE /y "C:\XXX\XXX\XXX\audit.*.log" "\\[FQDN]\XXX`$\XXX\XXX\XXX"

(Notice the apostrophe before the dollar sign)

The log files have been disappearing from the server and, presumably because of the typo, they have not been showing up in the repository server.

The third-party vendor who monitors the server has also mentioned that it seems the hard drive is getting filled up, which would be consistent with the size of the missing log files (around 500MB each, daily for the last 6 weeks).

Question: are these missing log files recoverable? Does Windows store files from a MOVE operation somewhere in a hidden/temp folder, or are they gone for good? For the time being, I'm not worried about the hard drive space, as I've corrected the error. I would like to recover the logs, if possible.

The OS of the server & repository are both Windows Server 2019 (I think).

Jase
  • 1
  • Is this actually a PowerShell script? That `/y` would have been valid for Cmd's MOVE, but does not really make sense for PowerShell's 'move' (which interprets /y as a *path*, and the equivalent of MOVE /y would have been "-Force"). – u1686_grawity Mar 01 '23 at 19:06
  • That's not an apostrophe, it's a backtick. It's escaping the `$` to make it a literal in an expansion string (double-quoted) – Keith Miller Mar 01 '23 at 19:19
  • Interesting; the author of the script conceded that the backtick was a mistake, but maybe he had forgotten or just copied/pasted it from somewhere else. Oh! Also, the /y wasn't in the original script, just in the version I copied here. I apologize for the confusion. I'll leave it in teh OP for now, but I should have deleted it. – Jase Mar 01 '23 at 19:20
  • Sorry; what does "make it a literal in an expansion string" mean and why would that be useful or necessary in this case, especially given that removing it works when it didn't work before? In other words, why would anyone put that there in this exact scenario? – Jase Mar 01 '23 at 19:22

1 Answers1

0

We have a script that was supposed to move LOG files off a server onto a local repository. It turned out the author of the script added an apostrophe by accident in the destination:

The apostrophe might not necessarily be an accident; it is the 'escape' character in PowerShell (e.g. "`n" in PS has similar meaning to "\n" in other languages, both expanding to a newline character).

As PowerShell strings will expand $variables, it is normal to place an escape character in front of a $ that needs to remain a literal "$" (e.g. "foo`$bar"), and even though variable expansion won't happen in your specific example, the backtick still has the same result of making "`$" produce a literal dollar sign (which is what you probably want there).

Does Windows store files from a MOVE operation somewhere in a hidden/temp folder,

It doesn't. However, it also does not delete the originals until the copy from source to destination is successful. If the script had really been moving the files to a nonexistent share, both the PowerShell "Move-Item" and the Cmd.exe "MOVE" would have stopped after failing to create the output file, without deleting anything.

The fact that the server is slowly running out of disk space also indicates that the script did successfully create files on the target directory, implying that the target directory actually exists. (Windows doesn't invent share names out of nowhere, so this would not have happened if the script had incorrectly used "xxx`$" as the share name as you're assuming.)

Make sure that the UNC path actually represents the server-side folder that you're expecting (i.e. it's probably just that you're looking in folder A but the share is mapped to folder B). If you know the file names, search all of the server's disks for that exact name (e.g. Cmd's dir/a/b/s c:\foo.log). If the disk is filling up, run SpaceSniffer or WinDirStat and look at what the largest directory is – that's where your logs are.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Thanks for the answer. I don't know if the ' is intentional or not, but it didn't work with it and it works without it, so I'm pretty sure it was a typo. In any case, I'll look for those files to see where they might've gotten off to. Great suggestion. Thanks! – Jase Mar 01 '23 at 19:25