There are 2 utilities on the BES CD for backing up the BES. blackberrybackup.exe for backing up the config to a text file, and blackberrydbbackup.exe for taking care of the database. These can be scripted in a batch file and run using task scheduler, and then you can simply let your nightly backups pick up the files. The blackberrydbbackup will produce a .bak file that is roughly the same size as your database, so if you don't clean them up regularly you will notice your disk space diminish as your backup folder grows massive in size. To counter this I wanted to add a bit at the end of my backup script that would delete files older than a certain age. I found many, many long and complicated scripts that would do this, using if and for statements and masses of variables. I also found vbscripts pages long for doing this but I kept looking for something simple, because I recently looked into how to script this sort of thing using Unix commands (and blogged about it), and I was sure there would be a way using "command prompt" (DOS) commands that would be equally as short and elegant.
I discovered a new command for this called forfiles. Here's the syntax I used:
The /m switch specifies the search criteria. If you do not use /m it will default to *. The /D +6 is number of days, 6 days old in this instance. The /C switch will execute a command which you need to place inside double quotes. The @file variable in the example represents each file in the search results.
Here's the complete script:
cd\backup
blackberrybackup.exe -b -o e:\backup\S86_backup.txt -y -w s05010086 -n s05010086 -m "BlackBerryServer"
blackberrydbbackup.exe -d BESMgmt -E -p -f e:\backup\
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do SET mdate=%%c%%b%%a
rename E:\backup\S86_backup.txt e:\backup\%mdate%S86_backup.txt
echo Finished.
rem ** Cleanup old files **
forfiles /m *.bak /D -6 C "cmd /c del @file"
forfiles /m *.txt /D -6 C "cmd /c del @file"
Technorati Tags: Batch Files, Blackberry, Backups
Recent Comments