Can a file backup be appended to a copy in the destination folder


  1. Posts : 20
    Windows7 32bit
       #1

    Can a file backup be appended to a copy in the destination folder


    I want to run a script as a bat file so it can be scheduled as a daily task. I think that ROBOCOPY is my best option but i cannot find suitable switches to make the script do what i want.

    I want to copy "eventfile.txt" from a source to destination folder.
    However, as this is a daily task, eventfile.txt will have a different text content each day (it is in fact my openvpn logfile) and after robocopy is run only the latest version of the file is copied to the destination, the previous day being overwritten.
    What I want it to do is append eventfile.txt to the destination file so I can build a history of all my vpn events. None of the switches appear to allow me to do that.
    Is there a workaround for this task or another way of doing this?
      My Computer


  2. Posts : 259
    windows 7 ultimate x64
       #2

    It'll have to be a bit more complicated than a switch. The following batch file will rename each log file by adding the date and time of creation.

    Code:
    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" 
    set "YY=%dt:~2,2%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" 
    set "datestamp=%YY%%MM%%DD%"  
    set "datafolder=WHEREVER YOUR LOG FILE TO BE COPIED IS" 
    set "backupfolder=WHEREVER YOU WANT THE COPY TO GO\%datestamp%"  
    set switches=/r:0 /w:0 /mir /ns /nc /ndl /np /njh /njs  robocopy %switches% "%datafolder%" "%backupfolder%"  
    pause
      My Computer


  3. Posts : 20
    Windows7 32bit
    Thread Starter
       #3

    That was just great. works as expected .
    Thanks!
      My Computer


  4. Posts : 259
    windows 7 ultimate x64
       #4

    Glad it worked! :)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 19:11.
Find Us