# Help with Batch file



## adamdaviddoy (Nov 12, 2004)

Hello, and thanks for the help in advance.

I have a batch file that we use to backup user data at my job here. i'm the author of this batch file. %1 is the user name variable and %2 is the backup path. i have one problem however. I have the log file being piped out and appended every time this batch file runs. and eventually the file size grows. This is not a huge problem i don't care about the file size that much i just would like it to trim it's self. And i'd like for it to trim it's self say once a week.

I know this should be able to be done w/ like an IF statement.

IF File is older than xdays then overwrite or something

here is the batch:

@echo off
:COMPACT PROFILE
cd c:\documents and settings\%1\desktop
compact /c /s /i *.*
cd c:\documents and settings\%1\favorites
compact /c /s /i *.*
cd c:\documents and settings\%1\my documents
compact /c /s /i *.*
:COPY PROFILE
date /T >> %2\"backuplog_"%1".log
time /T >> %2\"backuplog_"%1".log
xcopy "C:\Documents and Settings\%1\my documents\*.*" "%2\My Documents" /c /s /r /d /y /i /exclude:c:\exclude.txt >> %2\"backuplog_"%1".log "
xcopy "C:\Documents and Settings\%1\desktop\*.*" "%2\Desktop" /c /s /r /d /y /i /exclude:c:\exclude.txt >> %2\"backuplog_"%1".log"
xcopy "C:\Documents and Settings\%1\favorites\*.*" "%2\Favorites" /c /s /r /d /y /i /exclude:c:\exclude.txt >> %2\"backuplog_"%1".log"
ECOMPRESS PROFILE
Cd\
cd c:\documents and settings\%1\desktop
compact /u /s /i *.*
cd c:\documents and settings\%1\favorites
compact /u /s /i *.*
cd c:\documents and settings\%1\my documents
compact /u /s /i *.*
Cd\
:COMPACT DATA FOLDER
cd c:\documents and settings\data
compact /c /s /i *.*
:COPY DATA FOLDER
date /T >> %2\"backuplog_"%1".log
time /T >> %2\"backuplog_"%1".log
xcopy "C:\Documents and Settings\data\*.*" "%2\Data" /c /s /r /d /y /i /exclude:c:\exclude.txt >> %2\"backuplog_"%1".log"
ECOMPRESS DATA
compact /u /s /i *.*
exit


----------



## adamdaviddoy (Nov 12, 2004)

Bump.

Help me please


----------



## Squashman (Apr 4, 2003)

Why not just pipe it out to a new file with the date in the file name. Then just delete the old files as needed.


----------



## munt (Nov 25, 2004)

Hi,

Try using one ">" instead of two ">>".
the log file should be initialised each time it runs. If you wanted to clear it after a few days you could always put a condition around it.

i.e.
date /T > %2\"backuplog_"%1".log
instead of
date /T >> %2\"backuplog_"%1".log

hope it works


----------

