Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section B.2. Setting Up a Custom Log Rotation

B.2. Setting Up a Custom Log Rotation

The logrotate utility is sometimes perceived as a utility only for system administrators. However, any user on the system can utilize logrotate to rotate log files for applications that they have read/write permissions on the log files. For example, as the oracle user, you can use logrotate to rotate your database alert.log file. Here are the steps for setting up a job to rotate the alert log file of an Oracle database:

  1. Create a configuration file named alert.conf in the directory /home/oracle/config (create the directory if it doesn't already exist):

    /oracle/RMDB1/admin/bdump/*.log {
    daily
    missingok
    rotate 7
    compress
    mail oracle@localhost
    }

    In the previous configuration file, the first line specifies the location of the log file. The asterisk (wildcard) tells logrotate to look for any file with the extension of .log in that directory. The daily keyword specifies that the log file should be rotated on a daily basis. The missingok keyword specifies that logrotate should not throw an error if it doesn't find any log files. The rotate 7 keyword specifies that the log files should be kept for seven days. The compress keyword compresses the rotated log file. Lastly, a status e-mail is sent to the local oracle user on the server.

  2. Create a cron job to automatically run the job on a daily basis:

    0 9 * * * /usr/sbin/logrotate -s /home/oracle/config/alrotate.status
    /home/oracle/config/alert.conf

    The previous two lines of code should be one line in your cron table (it didn't fit nicely on this page on one line). The cron job runs the logrotate utility every day at 9 a.m. The -s (status) option directs the status file to the specified directory and file. The configuration file used is /home/oracle/config/alert.conf.

  3. Manually test the job to see whether it rotates the alert log correctly. Use the -f switch to force logrotate to do a rotation:

    $ /usr/sbin/logrotate -f -s /home/oracle/config/alrotate.status \
    /home/oracle/config/alert.conf


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint