Cron jobs

Hi,

I am a Linux administrator (newbie) in my company. The distro being used in the servers here is Centos 5.3

Just need to know, as a Linux administrator is it better for me to use /etc/crontab to set my cron jobs. I do not want to use the crontab -e to schedule my cron jobs.

That means can I edit the default settings (to different time settings) in etc/crontab in order to get my database to backed up?

And another question is, how do I set the cron job to only show the current week's backup (in the database backup directory) and remove the previous week's backups.

One week would mean Monday to Saturday.

Pls help.

Tqs.

Unless there's real urgent need to change it, you should leave /etc/crontab as is. The primary use of /etc/crontab is to allow the system to manage its own log files and environments. If there are tasks that you would like to include in the system housekeeping to be maintained at the times listed within /etc/crontab, they can be included in the appropriate /etc/cron.<time> file.

For purposes of a database backup, 'crontab -e' is the best option. Create your crontab entry and reference a script. This way you will not need to modify your crontab entry unless you need to change the time of your backup. All other aspects of the backup will be controlled from the script.

Deleting the old backup files will depend on how you perform your backups. If you perform a full database backup every night, then you can use something along the lines of this at the top of your script to remove the oldest file prior to performing the nightly backup:

find /backup-dir -atime +7 -exec rm ()\;

This will remove any files older than 7 days from the directory. Since this executes every night, there will only ever be one file deleted per night.

If you're performing a full backup the first night, and incrementals on subsequent nights, then you'd want to only perform the removal operation prior to your full backup with something similar to the following prior to performing the backup (assuming you perform your full backup on Monday):

if [ "`date +%a`" == "Mon" ]
then
    cd /backup-dir
    /bin/rm backup-files
fi

That will preserve your incremental backups until the night of your next full backup.

Hope this helps.