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 let your nightly tape backups pick up the files.
The blackberrydbbackup utility will produce a .bak file that is roughly the same size as your database, so if you don't clean these files 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


I've been playing with the forfiles command after reading this post. Shouldn't you be using -6 rather than 6 if you want to find files greater than 6 days old?
I also found that I couldn't use /C "del @file" I had to use /C "cmd /c del @file"
I'm running the script on Windows 2003 in case that makes a difference!
OK Smarty pants you are quite right. Just checked my E:\backup folder and found all my previous .bak and .txt files in there. I modified it your way and it works!
Cheers Ant.
I found your script whilst searching the Internet for a simple backup script to do JUST THIS! I was wondering if you could fill me in on one part though: What is the significance of the string 's05010086' in the switches for the blackberrybackup.exe?
Thanks,
Dave
Hi Dave,
S05010086 is the server name of my BES.
Cheers!
forfiles -m*.bak -d-6 -c"cmd /C del @FILE"
forfiles -m*.txt -d-6 -c"cmd /C del @FILE"
Thanks for spotting the missing "/" in front of the C.
I have another question about the 1st command line, and the results I get on my BES.
When I run the command
blackberrybackup.exe -b -o c:\backup\S86_backup.txt -y -w lcua42 -n lcua42 -m "BlackBerryServer"
I receive this prompt for a file password...
Choose profile of BES
Using BlackBerryServer
Did not provide a valid password.
Please enter a Password:
(this password will be required in order to load data
from this backup file. Minimum size of 7 characters)
********
Please confirm Password:
********
How did I get this setting/request? ... how do I get around it?
Thank you!
JLH
Hi Joel, are you running the script using the blackberry service account? Running as BesAdmin on my BES doesn't prompt for a password.
Joel - Password has to be 7 characters....
"-w lcua42"