My Insights
Using batch files to do daily backups
Often times there are situations where you want to use batch files that run on a continuous basis but are aware of the date that they are running on.
Let me illustrate by using as example. Let’s say that I want to backup a critical executable file on a daily basis by simply using the copy command in DOS but I want the backup filename to reflect today’s date. If today was 08/09/2007, i want my target filename to be backup20070809.exe
In order to accomplish that with a batch file, use the following code-
date /t > temp.txt
set /p date= < temp.txt
del temp.txt
echo %date:~4,2%
echo %date:~7,2%
echo %date:~10,4%
The last three lines can be taken out and you can use the code from the last 3 lines to perform your backup operation
5 Responses to Using batch files to do daily backups
Leave a Reply Cancel reply
Pages
What I'm Doing...
- Laundry or #EUSPHack 5 years ago I would've considered that choice a sad Friday night, but today I find it to be glorious. 16 hrs ago
- More updates...
Archives
- May 2012
- December 2011
- August 2011
- June 2011
- April 2011
- March 2011
- September 2010
- August 2010
- July 2010
- May 2010
- February 2010
- January 2010
- November 2009
- March 2009
- January 2009
- April 2008
- March 2008
- October 2007
- September 2007
- August 2007
- July 2007
- May 2007
- March 2007
- February 2007
- December 2006
- October 2006
- September 2006
- August 2006
- June 2006
- May 2006
- April 2006
- March 2006
- December 2005
- September 2005
- August 2005
- June 2005
- April 2005
- March 2005
- February 2005
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- March 2004
- September 2003
- August 2003
- April 2003
Categories
- Chromium OS
- Internet Explorer 7
- Kwizcom
- Miscellaneous
- Movies
- MS Office
- Music
- Night on the Town
- Office 2007
- Outlook 2007
- Pictures
- Products/Shopping
- Recovered Entries (01/19/2005)
- Restaurants/Food
- Sharepoint 2007 ( MOSS / WSS )
- Sharepoint 2010 (SPS / Foundation)
- Tech
- The Law
- TV
- Uncategorized
- Video Games
- Vista
- Visual Studio 2010
- VMWARE
- VMWARE Server 2.0
- Website
- Windows Live
- Work
- XP





hi boss
Can u help me in dos batch files plz?? reply me on
arpansharma2000@hotmail.com
hello!can you help me, please???i want to backup a directory every day(with a batch file), but i want to update only the things that change not the entire dir.Also the backup directory should change the name with the new date! i know how to backup using batchfile, but it creates one directory for each day!i want to renew(backup) the directory only if it is made a change, and changing also the name of the directory. tankyou!
you can contact me on gherciudan06@yahoo.it
Hi,
Can you please send me the code you already have so I can better understand what you are trying to do. However, if you just want to make backup of data, I recommend that you try mozy.com – you get 2GB of free backup (full & incremental)
-Pranav
hello!look at this batch (I put it as a scheduled task at 0:00 for all week long)
@echo off
:: variables
set drive=e:\Backup
set folder=”%date:~0,2%-%date:~3,2%-%date:~6,6%”
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
echo ### Backing up directory…
%backupcmd% “C:\Programmi\Acer” “%drive%\%folder%”
echo Backup Complete!
@pause
this batch create a dir. in e:\backup\currentdate with the current backup
but tommorow I don’t change the source dir, so it should not create a new backup directory
after tommorow I make some changes in the source dir, so it should backup everything in a new dir with the current date
the question is: how to compare two directories to see the differences and how to implement it in a batch file(it will be an “if function” ??? or comp???)
thankyou
I recommend you take a look at this free utility: http://www.download.com/Everyday-Auto-Backup/3000-2242_4-10713232.html?tag=lst-0-5
If you want to do this with a batch file, then you have to get the ‘Last Modified’ date for your folder and then compare it to the last modified date from your last backup. You can just dump the last modified date into a text file right after your xcopy command.
The main problem is how to get the last modified date of a folder. I’ve used a utility in the past called modtime.exe that does exactly that. However a quick google search didn’t reveal a download link for it – see if you can find the same utility or something similar.
Batch files DO take IF statements. Take a look at microsoft’s documentation for batch files- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true
Hope that helps.