Hello,
I have windows 7 Pro on my laptop and I need to automate backup of a text file every hour with unique backup file name with date stamp.
For ex. My file name = scratch.txt and the backup file name should be scratch-201807210100 (at the time of 1:00 hours) and scratch-201807210200 (at the time of 02:00 hrs) and so on...
Please advise me on how to do this? I'm admin of this laptop.
Thanks!
how to backup a text file every hour in windows 7
Moderator: DosItHelp
Re: how to backup a text file every hour in windows 7?
Create the batch file and then open up Windows Task Scheduler to create a scheduled task that repeats every hour.
Re: how to backup a text file every hour in windows 7?
Thanks I should have been more clearer.
I know a batch script and keeping it in task scheduler would do but I dont know anything about batch scripting. Appreciate if someone could provide it.
I know a batch script and keeping it in task scheduler would do but I dont know anything about batch scripting. Appreciate if someone could provide it.
Re: how to backup a text file every hour in windows 7?
Code: Select all
@echo off
FOR /F "tokens=2 delims==.-" %%G IN ('wmic os get localdatetime /value') DO SET "dt=%%G"
set "dt=%dt:~0,12%"
copy "scratch.txt" "scratch-%dt%.txt"
Re: how to backup a text file every hour in windows 7?
Many thanks Squashman
It worked like charm with time stamp of minutes as well.
Best regards,
It worked like charm with time stamp of minutes as well.
Best regards,
Re: how to backup a text file every hour in windows 7?
It's working if i run the batch file from command prompt but not working from task scheduler because of lack absolute paths of the scratch file.
I tried to change it to copy but this not working. Could you please modify it to set absolute paths?
Thanks!
I tried to change it to copy
Code: Select all
"d:\scratch.txt" "d:\scratch-%dt%.txt"
Thanks!
Re: how to backup a text file every hour in windows 7?
Your example is an absolute path.batemanj wrote: ↑21 Jul 2018 10:24It's working if i run the batch file from command prompt but not working from task scheduler because of lack absolute paths of the scratch file.
I tried to change it tobut this not working. Could you please modify it to set absolute paths?Code: Select all
copy "d:\scratch.txt" "d:\scratch-%dt%.txt"
Thanks!