Script to copy files last modified yesterday or earlier?

Caporegime
Joined
8 Mar 2007
Posts
37,146
Location
Surrey
Hey guys

Being a bit lazy, but also finding it quite hard to Google this as people always have different requirements.

Anywhoo, this is what I am trying to acheive:

I have a HTPC running W7 Media Centre with a freeview turner. TV is recorded onto the hard drive in that PC. I also have a Server running WHS. What I want to do is every time the HTPC wakes up to back itself up (or pretty much every time it wakes up) for it to copy any recorded TV programs onto my server. However, I need to make sure it doesn't try to copy any recordings that are currently being recorded.

Therefore I was thinking of writing a little batch file that would copy from the D:\Recorded TV directory on the HTPC to the \\server\Recorded TV directory any files that were modified up to and including yesterday. Working on the assumption that the PC doesn't wake up at exactly 00:00 and try to copy a recording in use, there should always be a few hours buffer of inactivity on files to prove they aren't active recordings.

Anyone know how to do this with either inbuilt Windows functions or something like xcopy?

I don't want to record directly to the Server as if there are any issues with the network or the server it will still record to the local HTPC. The HTPC spends most of its time in hibernate, waking up to record TV or babckup somewhen between 3am and 7am, so there is no guaranteed time it will be on on a daily basis.

Cheers
 
Robocopy should give you the options you need. Should be available in both O/Ses already. Check here for more info.

You should be able to use the maxage function to specify yesterday's files, and even if it was recording over midnight, you could use /r:1 to limit copying active file, and then /mot: to retry after certain period.
 
Robocopy works great. Now I just need to figure out how to stop the PC automatically hibernating while its running? Any ideas?
 
The only thing I can think of is to add the following to the batch file

Code:
powercfg.exe /hibernate off
robocopy (with required options)
powercfg.exe /hibernate on

I have no idea if it would work or completely screw up Windows so don't blame me if all hell breaks loose. ;)
 
Having issue getting the powercfg command to run. Gave up last night as it was late. If you right click on the .bat file and run as Admin, it works. If you run it as a scheduled task it doesn't (yet it runs the robocopy part of the script).
 
Well this is random as hell...

I have set the script to run with highest privileges, and it turns hibernation on and off...

Only thing is, my PC now goes to sleep after 15 minutes, yet its never set to sleep in any of the power configs (only to hibernate).

:confused:
 
I wonder whether resetting the hibernate like that has confused which config it is using.

You could add an extra flag to the second command to set which profile is active. The bottom line of the batch file should become

Code:
powercfg.exe -hibernate on -setactive [I]Scheme_GUID[/I]

Where Scheme_GUID is the name of the profile. To find out what the available names are separately run powercfg.exe -l at the command prompt to list them.

If all you profiles now have sleep active, either modify a profile, or create a new one, and set that as active.
 
Back
Top Bottom