TIP OF THE DAY: Inteligent cleaning of SW Backups

If you are like me you have SW backups set to 2 copies in the very unlikely event that you make a mistake and have to go back and restore a SW document. This leads to another distasteful task, cleaning out the SW Backup directory from time to time. One of my associates pointed out that he likes to keep 3 days of backups. So how to keep 3 days of backups without spending time every day manually deleting files? Enter DELOLD and the Task Scheduler.

  1. Goto
    formatting link
    grab this command file using cut and paste. Paste it into notepad and save to a convenient place on your system's search path with the name DELOLD.CMD.

  1. Create another command file called SWCLEAN.CMD and put in:

CD "SW Backup Directory" DELOLD 4 *.SLD*

  1. Create a task in the Task Scheduler that runs SWCLEAN.CMD at some early hour of the morning.

  1. Before letting this go and run, test SWCLEAN.CMD. If all is well edit DELOLD.CMD and replace ECHO with DEL so that it actually deletes files.

Note that you could also add a line to SWCLEAN.CMD to clean out your temp directory and defragment. Defragment is simply DEFRAG C:

Reply to
P.
Loading thread data ...

Good find.

I'm having some trouble though. Are you set for more than one backup? For me, this thing chokes on "Backup (1) of 28160 PALLET.SLDPRT" with "of was unexpected at this time." ECHO was choking on the (1). So,I removed it from my file names.

If I replace ECHO with DEL, I get "Could Not Find C:\SW Backups\Backup" for each file, and .SLDASM was unexpected at this time. Further testing reveals that DEL is truncating file names at the first space. Changing to DEL "% Filename%" deleted everything.

Running XP Pro sp1. Any thoughts?

Reply to
Dale Dunn

In the spirit of Beta testing with users many thanks.

I think it has to do with the spaces in the path or filename. I didn't write the cmd file so it will take a bit of sleuthing to figure out how to deal with the more modern filenames. As far as the path goes try CDing to the backup directory in the batch file that calls the delete program.

If this is a good idea I suppose it could be translated > Good find.

Backups\Backup" for

Reply to
P.

I reached the same conclusion about the spaces in the filename. As far as implementing in other forms, that may be a good idea if someone has the time. Console batch files are limited and uh, obscure.

Reply to
Dale Dunn

To use a file name with spaces you have to enclose it with Quotes in any app that uses the console.

Corey

Reply to
CS

and the fix is.....................

DEL /P "%FileName%"

put quotes around the filename (and add a /P for checking).

Reply to
P.

I was all excited, but it didn't work. It's still confused by spaces, and deletes everything else.

Reply to
Dale Dunn

Are you running XP and using it from cmd not command? I didn't have any trouble in my backup directory and I have spaces in filenames.

Reply to
P.

XPsp1. I re-copied the script into a text file and made sure it was running in CMD. After changing to:

del /P "%FileName%"

it still wants to delete everything. I almost think I have a syntax error in the file calling it.

CD "C:\SW Backups" delold 1 *.SLD*

It doesn't matter if I have 30 or 3000 in here, it wants to delete everything. At least it's not discriminating against spaces now. Unfortunately, it's also ignoring the wildcards and deleting files that don't match *.SLD*.

Reply to
Dale Dunn

Try this. After reading the help I noticed it doesn't take a filename as a second argument so I added that.

:: --------DELOLD.BAT---------- @echo off SET OLDERTHAN=%1 SET SEARCHFOR=%2 IF NOT DEFINED OLDERTHAN GOTO SYNTAX IF NOT DEFINED SEARCHFOR SET SEARCHFOR="*.*"

for /f "tokens=2" %%i in ('date /t') do set thedate=%%i

set mm=%thedate:~0,2% set dd=%thedate:~3,2% set yyyy=%thedate:~6,4%

set /A dd=%dd% - %OLDERTHAN% set /A mm=%mm% + 0

if /I %dd% GTR 0 goto DONE set /A mm=%mm% - 1 if /I %mm% GTR 0 goto ADJUSTDAY set /A mm=12 set /A yyyy=%yyyy% - 1

:ADJUSTDAY if %mm%==1 goto SET31 if %mm%==2 goto LEAPCHK if %mm%==3 goto SET31 if %mm%==4 goto SET30 if %mm%==5 goto SET31 if %mm%==6 goto SET30 if %mm%==7 goto SET31 if %mm%==8 goto SET31 if %mm%==9 goto SET30 if %mm%==10 goto SET31 if %mm%==11 goto SET30 if %mm%==12 goto SET31

goto ERROR

:SET31 set /A dd=31 + %dd% goto DONE

:SET30 set /A dd=30 + %dd% goto DONE

:LEAPCHK set /A tt=%yyyy% %% 4 if not %tt%==0 goto SET28 set /A tt=%yyyy% %% 100 if not %tt%==0 goto SET29 set /A tt=%yyyy% %% 400 if %tt%==0 goto SET29

:SET28 set /A dd=28 + %dd% goto DONE

:SET29 set /A dd=29 + %dd%

:DONE if /i %dd% LSS 10 set dd=0%dd% if /I %mm% LSS 10 set mm=0%mm% for %%i in (%SEARCHFOR%) do ( set FileName=%%i call :PROCESSFILE %%~ti )

set mm= set yyyy= set dd= set thedate= goto EXIT

:SYNTAX ECHO. ECHO USAGE: ECHO DELOLD X [FILENAME] ECHO Where X is the number of days previous to Today. ECHO Where FILENAME is an optional filename or wildcards. ECHO. ECHO EX: "DELOLD 5" Deletes files older than 5 days. GOTO EXIT

:PROCESSFILE set temp=%1 set fyyyy=20%temp:~6% set fmm=%temp:~0,2% set fdd=%temp:~3,2% if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%

:: +*************************************+ :: | This is where the files are deleted | :: | Change the ECHO command to DEL to | :: | delete. ECHO is used for test. | :: +*************************************+ if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% ( ECHO "%FileName%" )

set temp= set fyyyy= set fmm= set fdd=

:EXIT

:: ----------END-DELOLD.BAT-------------

Reply to
P.

"P." wrote in news:1111034768.149093.119790 @l41g2000cwc.googlegroups.com:

Ok, that's better. Now it only deletes the SW files. But it still deletes all of them. If I create a text file, re-name it test.sldprt, and run again with a 4 day argument, it still wants to delete the file I created less than 30 seconds ago.

I copied your program text into a new file without changing anything, and still, it ECHOes everything regardless of the date. Could there be an environment variable affecting this?

Reply to
Dale Dunn

Boy, have they increased the capablities of batch files in XP. I am going through this thing now bit by bit trying to understand it. If Windoze main feature over DOS and Unix was ease of use then Unix has them beat in writing understandable shell files.

Dale Dunn wrote:

filename

Reply to
P.

You ain't kidding. That thing is impenetrable to me. I can see some of the branching, but I just don't get the variable syntax. I tried to ECHO the contents of a variable to try to debug, and I couldn't even make that work.

Reply to
Dale Dunn

I use this free little utility to empty temp files inclusive the contents of the SolidWorks Autobackup folder. I have it set to delete files older than 30 days

formatting link

Regards

John Layne Solid Engineering Ltd

Reply to
John Layne

Here is another method to consider, the one I'm currently using: External Hard Drives. I set the SolidWorks Back-Up settings to "Zero". It takes time to read/write these back-up files every time you "Save".I back up to an External Hard Drive #1 every 30 minutes or so. I also delete all Temp files every 4 hours or so. The keeps the Internal Drives on my computer clean. Then, one a week, I back up the #1 Hard Drive to External Hard Drive #2. I also Defrag my Internal and External Hard Drives at the end of everyday. I also recommend the method of keeping the Applications on the C: Drive and all Data on another Internal Hard Drive. Best Regards, Devon T. Sowell

formatting link

"John Layne"

Reply to
Devon T. Sowell

Devon,

That is a very good insight. I like Layne's idea too. There is a batch file on the SW site that does a lot of cleanup and I wanted to integrate to that. But your idea of not using SW backups has some merit. The only issue with it is that I like the backups because it is a means of undo and I work both on local drives and on network drives. It would be kind of hard to track where I was working and only back that up. Since SW backup is done to a local drive that is very fast and the second copy is just a rename operation I don't think I am loosing that much by leaving SW backup set to 2.

Layne's idea with a little customizati> Here is another method to consider, the one I'm currently using: > External Hard Drives.

Reply to
P.

Hi Devon

Another utility I use to backup at the end of each day is ViceVersa Pro. It's not free but well worth the cash.

formatting link
I find it invaluable as it has excellent control over what?s being backed up or synchronized.

My Methodology using ViceVersa:

C Drive Internal 80Gb ATA F Drive Internal 120Gb SATA Raid 0 array (working files) H Drive External 40Gb USB Drive

At the end of each day I ?Replicate and Prune? working folders from F drive "Source" to C drive "Target". Hence the working folders on C become a mirror of F.

I then backup F "Source" to H "Target" using the ?Advanced Sync with History? method and have it set to keep the previous 10 copies of any particular file, it?s also set to delete backup files older than 6 months. The "Advanced Sync" method allows me to work on the USB drive from my home office and return to my clients and sync with my PC located at their office. This method is also used to sync with their server.

My data files occupy approximately 20GB. Due to only updated files being backed up the entire process above takes about 5 minutes.

Below an extract from the ViceVersa help file on Synchronization Methods the software has

"Simple Sync (No History)"

*All single (=unpaired) files and folders in the Source are copied to the Target. *All single (=unpaired) files and folders in the Target are copied to the Source. *Older files in the Target are replaced with their newer counterpart in the Source. *Older files in the Source are replaced with their newer counterpart in the Target.

"Replication (Augment)"

*All single (=unpaired) files and folders in the Source are copied to the Target.

"Replication (Refresh)"

*Older files in the Target are replaced with their newer counterpart in the Source.

"Replication (Update)"

*All single (=unpaired) files and folders in the Source are copied to the Target. *Older files in the Target are replaced with their newer counterpart in the Source.

"Replication (Update and Prune)"

*All single (=unpaired) files and folders in the Source are copied to the Target. *Older files in the Target are replaced with their newer counterpart in the Source. *All single (=unpaired) files and folders in the Target are removed (pruned).

"Replication (Mirror)" Creates a mirror of the Source in Target = Backup Source(s) to Target(s)

*All single (=unpaired) files and folders in the Source are copied to the Target. *Older files in the Target are replaced with their newer counterpart in the Source. *Newer files in the Target are replaced with their older counterpart in the Source. *All single (=unpaired) files and folders in the Target are removed (pruned).

"Advanced Sync (With History)" Bidirectional Synchronization

*All newly added files and folders in Source since last sync are copied to Target and vice versa. *All deleted files and folders in Source since last sync are deleted from Target and vice versa. *Newer files in Source are copied over their older counterpart in Target and vice versa. *If a file was changed both in Source AND Target, the file is identified as a conflict.

Regards

John Layne Solid Engineering Ltd

Reply to
John Layne

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.