Solved

I think this batch file question should be easy

Posted on 2002-07-15
3
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 96

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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