Solved

I think this batch file question should be easy

Posted on 2002-07-15
3
164 Views
Last Modified: 2010-04-13
I want to back up a single file (a backup file made by msbackup.exe) to a networked harddrive on a daily or weekly basis. I would like to write a batch file to rename and move the temporary backup file off the local computer and onto the networked drive. Finally, I want to be able to move it to a folder which gets created each transfer and named with today's date.

Eg:

1. create c:\backuptemp.bkf with a scheduled task
2. create z:\date_of_backup directory (or even ##-##-## as the name of the folder)
3. move c:\backuptemp.bkf z:\date_of_backup\backupfile.bkf

can someone help me write this batch file? basically I need help understanding how a batch file can get to the date and store it to a variable. I know 'date' and 'temp' keywords exist but not how to use them. Your help is appriceated.

AJMan
0
Comment
Question by:AJMan
3 Comments
 
LVL 63

Accepted Solution

by:
SysExpert earned 100 total points
ID: 7154650
The following should be enough to get you started.

You might also look into scripting languages etc.
WSH, Kixtart etc.
-----------

From: czpczp    Date: 06/25/2001 12:59PM PST Time date in batch file name directory by date
     The following script does *exactly* what you're looking for.  It will use the Time command
   (not time/t 'cause it doesn't give the seconds which is what you want), and parses the output string
 to extract the time in reverse order SEC:MIN:HR *extracting* the semi-colons.  THEN, it creates a directory
     *including* the client's name.  I did extensively test the script using varying times without having
      any problems.


     Cut and paste (verbatim) the script below into file with a BAT extension.  The following creates the
       directory on the root of the current drive (last line) -- you can alter where the directory is created
        depending on your needs (i.e. Md F:\LOG\%UserName%_%DirTemp%).

 Rem  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  MakeDir.Bat ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                 @echo off
                 cls

                 REM ** the following line gets the current time into a variable
                 echo.|time >holdstr

     REM ** The following 5 For statements parse the holdstr var to extract the time in reverser order
                 for /f "eol=E tokens=1,2,3*" %%a IN (holdstr) do echo %%a%%b%%c%%d  >holdstr
                 for /f "tokens=1,2* delims= " %%a IN (holdstr) do echo %%b  >holdstr
                 for /f "tokens=1,2* delims=." %%a IN (holdstr) do echo %%a  >holdstr
                 for /f "tokens=1,2,3 delims=:" %%a IN (holdstr) do echo %%c%%b%%a  >holdstr
                 for /f "tokens=1,2* delims= " %%a IN (holdstr) do set DirTemp=%%a%%b

                 REM ** remove temp file
                 del holdstr

                 Md \%UserName%_%DirTemp%

      Rem  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  MakeDir.Bat ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I hope this helps !
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 7155183
Well, I've pushed this a number of times, but...

I wrote a little 16 bit program that creates directories in the format you choose (with 8 character limits) that creates a directory and changes into it.  The batch file I would use with my utility is:

z:
cd\
mdate /c /f
copy c:\backuptemp.bkf .

The mdate program is what I wrote and by default, it creates a directory based on the current date in the format YYYYMMDD.  /C changes into the created directory (allowing the following copy line) and /F forces the creation of the directory - if it finds another directory there using the current date, it appends a .001, etc up to .999

But sysexperts solution should work fine as well.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 7155829
1) for scheduling, either AT (command line) or WinAT (Windows) does fine

2) for daily backup, I've found no need to create a separate directory for each run for each day. One time creation for a slot for each of the seven days of the week is more than enough.

2a) Retaining anything older than a week is overkill for a daily

2b) by not changing name, the name retains meaningful information AND permits self-cleaning through overwriting of the previous run, whether a week old or an earlier botch-up for that day (bear in mind these require space that will quickly grow, otherwise, to point of eating up the server's drive). Date of backup is assessed by both the time-stamp of the file and the content of a log file I copy along with it (that can and does serve other purposes)

2c) tools are available for more of this, I've run Kixtart (see SysExpert comment) successfully in this respect

3) moving a file is trivial enough, but for a file such as this, critical, big, and bandwidth consumptive, you should include some additional error checking and validation of the transfer.

4) also validate 'restore' options.  You may find... how shall we say, that you'd really prefer a backup utility that is easier to use more effectively more often, that also has scheduling capability built in

5) consider also the use of pkzip, or one of its clones. by adding compression, the file(s) cost less to transfer and store, and other nomenclature possibilities are available
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
A procedure for exporting installed hotfix details of remote computers using powershell
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now