![]()
[<<]Message[>>] [<<]Author[>>] [<<]Subject[>>] [<<]Thread[>>]
Number : 7217 Date : 2004-02-08 Author : Garry Deane Subject : Re: Keep previous version Size(KB) : 3
--- In xxcopy@yahoogroups.com, "ray_mccormick" wrote: > I have developed a backup scheme that will keep the old > version of a file in a dated folder (The date that the file > would be overwritten). This is useful for 'live' files such > as accounts.xls where. if the file got garbled, it is > undesirable to finish up with two copies of the same garbled > file! > > The bare bones of my current scheme: > > 1. Parse today's date (Adapted from Garry, message 4409) > 2. Menu > 3. SET variables SRC, > DST, (The normal backup to folder: Volume\path\) > DST2, (The dated folder for the previous version: > Volume\%yy%%mm%%dd%\path\) > ErrorLog > 4. Do it: > xxcopy %DST% /AZ/S/H/R/oA%ErrorLog% // clear all the A-bits first > xxcopy %DST% %SRC% /AA/S/H/R/Bo/oA%ErrorLog% // tag the A-bit for > newer on SRC ones; > xxcopy %DST% %DST2% /RC/A/S/H/R/YY/oA%ErrorLog% // Remove after > copy > xxcopy %SRC% %DST% /BU/BN/oE2/oX2/oA%ErrorLog% // do the normal > backup > > I would much prefer to rename the old version of a file with > its last accessed date prepended to the file name and save it > in the same folder as the current backup (DST). Alternatively > the date it would have been overwritten could be substited for > the last accessed date. > > Is this possible with xxcopy, or xxcopy and other cmd line > statements? Xxcopy doesn't have renaming capabilities except in a few limited cases (I personally use the /SGN switch to create copies of previous versions in a separate directory). However you can use xxcopy and a FOR /F command to rename the older versions in the manner you want. I'm not sure that using the last accessed date is the best option due to reasons that Kan has previously explained but here's how to: 1. get the files that will be replaced 2. get the file's last accessed date 3. rename that file with the date pre-pended to the filename @echo off setlocal set src=d:\test\ set dst=f:\test\ :: Get the list of files that are about to be overwritten set "cmd=xxcopy %dst% %src% /S/H/R/Bo/U/LL^|find "\"" for /f "tokens=*" %%a in ('%cmd%') do call :rename "%%a" :: Carry out the normal backup xxcopy %src% %dst% /BU/BN/L goto :eof :rename "quoted fully qualified filename" :: Get the filename without the path set fn=%~nx1 :: Get its last accessed date and rename it with the date for /f "tokens=1-3 delims=/-. " %%i in ( 'dir /ta/n %1 ^| find "%fn%"') do ( echo {demo} ren %1 "%%i%%j%%k-%fn%") goto :eof NOTE: 1. This is just a demo that doesn't do anything. Remove the "echo {demo}" part and the /L switch when fully tested. 2. The assumed output from the DIR command is yy/mm/dd. Change the order of %%i, %%j and %%k for other date formats. 3. You need to add /U to your first xxcopy command so that it only lists the older files which will be overwritten by the later xxcopy /bu/bn command i.e. it excludes the files in %dst% which have been renamed and don't exist in the %src% 4. You may have to add some error checking if there's a possibility that the REN command will fail because a file has been accessed and backed up twice in the same day so will already exist with the date pre-pended. Alternately, you could use COPY (with changes to include the dst path) instead of REN so you only end up with the most recent version on any one date. Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.