need batch file to take auto back up important files.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
girish
Posts: 4
Joined: 25 Mar 2014 04:10

need batch file to take auto back up important files.

#1 Post by girish » 25 Mar 2014 04:19

Hi Team,

I need a batch script to take auto back up of important files with the scheduled time from the server to the local machine and the details given below. the folder should be copied with the name of current date. Please assist me at the earliest. Thanks.

destination - \\10.99.2.222\reports (server example)
where to copy = D:\reports

Note: the batch file should not recommend me to press any key to take back up of files.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: need batch file to take auto back up important files.

#2 Post by foxidrive » 25 Mar 2014 04:27

Do you have access to this share without logging in?

girish
Posts: 4
Joined: 25 Mar 2014 04:10

Re: need batch file to take auto back up important files.

#3 Post by girish » 25 Mar 2014 04:30

yes i have option to access the server without logging in...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: need batch file to take auto back up important files.

#4 Post by foxidrive » 25 Mar 2014 04:40

This should copy \\10.99.2.222\reports to D:\reports\date-time

It is untested:


Code: Select all

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

robocopy "\\10.99.2.222\reports" "D:\reports\%fullstamp%"  /mir

girish
Posts: 4
Joined: 25 Mar 2014 04:10

Re: need batch file to take auto back up important files.

#5 Post by girish » 25 Mar 2014 07:53

I tried by copying the above code to text file and saved it to batch file, i run the batch file manually but the files are not copied. please check and advise. Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: need batch file to take auto back up important files.

#6 Post by foxidrive » 25 Mar 2014 08:40

Try the code above now. I removed the /zb from the end which generated an error to do with rights/permissions here.

girish
Posts: 4
Joined: 25 Mar 2014 04:10

Re: need batch file to take auto back up important files.

#7 Post by girish » 25 Mar 2014 12:16

Thank u very much it worked wellllllll............

Post Reply