Start by writing the script (it can be bash, php, perl, whatever your familiar with). The simply create a cron entry that calls the script.
To run every day at 2am you would want a cron entry like:
02 * * * * * /path/to/yourscript
Have a look at mysqldump, its really easy to run a shell command like:
mysqldump -u username -ppassword database > somefile.txt
Which will echo the results of your command to STDOUT.
So, you could do something like:
Make that script executable (chmod +x yourscript) and that should do it.
#!/usr/bin/php -q // Assuming this is where you php executable is
$filename = '/full/path/tofile/' . date('d-m-Y') . '.sql';
$cmd = `mysqldump -u username -ppassword database > $filename`;