Page 1 of 1
how to backup a text file every hour in windows 7
Posted: 20 Jul 2018 22:27
by batemanj
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!
Re: how to backup a text file every hour in windows 7?
Posted: 20 Jul 2018 22:36
by Squashman
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?
Posted: 20 Jul 2018 23:08
by batemanj
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.
Re: how to backup a text file every hour in windows 7?
Posted: 21 Jul 2018 00:13
by Squashman
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?
Posted: 21 Jul 2018 06:35
by batemanj
Many thanks Squashman
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?
Posted: 21 Jul 2018 10:24
by batemanj
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
Code: Select all
"d:\scratch.txt" "d:\scratch-%dt%.txt"
but this not working. Could you please modify it to set absolute paths?
Thanks!
Re: how to backup a text file every hour in windows 7?
Posted: 21 Jul 2018 10:27
by Squashman
batemanj wrote: ↑21 Jul 2018 10:24
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
Code: Select all
copy "d:\scratch.txt" "d:\scratch-%dt%.txt"
but this not working. Could you please modify it to set absolute paths?
Thanks!
Your example is an absolute path.