Automated file backup, renaming with current date & compress using batch file


Sometimes we need to take back up of some particular folder that regularly get updated and very crucial folder too. So what we need to do either use a third party tool or windows backup utility but I do not like both of them because of different reason.


For most of backup thing I love scripts and scheduling to do backup because you plant the tree once and get mangos always.


This time someone asked me to take a vss backup on daily basis but I can’t do this manually daily so I wrote a script and scheduled it to take the backup and rename it with current date. After that I thought if I can compress the folder it will save lot of disk space so I added one more line and it was all done.


For this compression thing you need to download an additional tool called 7zip command line version. That you can download from 7Zip download page here. After downloading it extract the zip file and copy the 7za.exe file in c:\WINDOWS\system32 folder. It’s very important to copy it in this system32 folder else you will need to give the full path of this 7za.exe file.


After this copy the bellow code and paste it in notepad.


xcopy D:\Data\*.* e:\backup\*.* /e /h /r /y

7za a -tzip e:backup.zip "e:\Backup"

rename "E:\backup.zip" %Date:~-10,2%_%Date:~-7,2%_%Date:~-4,4%.zip


Save the above file as backup.bat.


If you will run it by double click it will open a command prompt window immediately and will start processing after execution of all task it will get close and you can see the backup files at backup location.


In the above script fist line will copy the data second line will compress the folder and third line will rename the zip file to current date name.


Now here is next task, scheduling the backup.

For scheduling thing we will use windows scheduler. For this go to Control Panel->Scheduled Tasks and then double click on Add scheduled task. It will open a wizard just follow the wizard and it’s all done when you are at end of wizard.


Things do remember

1) Make sure to change the folder path.

2) Do not do any change other than the folder path

3) make sure to test it on a test environment before putting it live.


I hope it was useful for you please comment if you face any problem or have any suggestion for this.


Thanks for visiting my blog.

7 comments:

raajjjeev is blogging said...

I tried this. Fantastic. Thanx a ton for this.

Anonymous said...

Lots of Thanks Buddy for the nice and clean post.

Unknown said...

it is really working.

Prav said...

Superb!!! it works!! many many thanks..

Anonymous said...

big thanks!

Anonymous said...

can someone help me..?
i have problem with the backup..
if have picture,will easy to understand..
big thankz :)

Chamara Lanka said...

Any one can help me please...............

bro can u help me this is not working
i got d 7Zip but the there are 3 .EXE's
1 is 7zG.exe

2 is 7zFM

3 is 7z

i have change some places in this command here it is


xcopy D:\ACCTOP\data\ *.* e:\Acctop\Original files\ *.* /e /h /r /y

7za a -tzip e:backup.zip "e:\Backup"

rename "E:\Acctop\Original files backup.zip" %Date:~-10,2%_%Date:~-7,2%_%Date:~-4,4%.zip


but it's not working can u help me

Clicky Web Analytics