how to backup a text file every hour in windows 7

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batemanj
Posts: 4
Joined: 20 Jul 2018 22:24

how to backup a text file every hour in windows 7

#1 Post by batemanj » 20 Jul 2018 22:27

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!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: how to backup a text file every hour in windows 7?

#2 Post by Squashman » 20 Jul 2018 22:36

Create the batch file and then open up Windows Task Scheduler to create a scheduled task that repeats every hour.

batemanj
Posts: 4
Joined: 20 Jul 2018 22:24

Re: how to backup a text file every hour in windows 7?

#3 Post by batemanj » 20 Jul 2018 23:08

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.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: how to backup a text file every hour in windows 7?

#4 Post by Squashman » 21 Jul 2018 00:13

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"

batemanj
Posts: 4
Joined: 20 Jul 2018 22:24

Re: how to backup a text file every hour in windows 7?

#5 Post by batemanj » 21 Jul 2018 06:35

Many thanks Squashman :D

It worked like charm with time stamp of minutes as well.

Best regards,

batemanj
Posts: 4
Joined: 20 Jul 2018 22:24

Re: how to backup a text file every hour in windows 7?

#6 Post by batemanj » 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 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!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: how to backup a text file every hour in windows 7?

#7 Post by Squashman » 21 Jul 2018 10:27

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.

Post Reply