How it works...

With the current setup, every night, cleanup.sh will be executed at 1:00 A.M., and backup_db.sh will be executed at 2:00 A.M. The execution logs will be saved in cleanup.log and backup_db.log. If you get any errors, you should check these files for the traceback.

The cleanup script is fairly straightforward. Every day, it executes the clearsessions management command, which, as its name alludes to, clears expired sessions from the database, using the default database settings.

The database backup script is a little more complex. Every day of the week, it creates a backup file for that day, using a naming scheme of 0-Sunday.sql, 1-Monday.sql, and so on. Therefore, you will be able to restore data that was backed up seven days ago or later. First, the backup script dumps the database schema for all of the tables, and then, it dumps the content data for all of the tables, except for any that are given in the EXCLUDED_TABLES list (here only including django_session).

The crontab file follows a specific syntax. Each line contains a specific time of day, indicated as a series of numbers, and then a task to run at that given moment. The time is defined in five parts, separated by spaces, as shown in the following list:

  • Minutes, from 0 to 59.
  • Hours, from 0 to 23.
  • Days of the month, from 1 to 31.
  • Months, from 1 to 12.
  • Days of the week, from 0 to 7, where 0 is Sunday, 1 is Monday, and so on. 7 is
    Sunday again.

An asterisk (*) means that every time frame will be used. Therefore, the following task defines that cleanup.sh  is to be executed at 1:00 AM every day of each month, every month, and every day of the week:

00 01 * * * /home/myproject/commands/cleanup.sh 

You can learn more about the specifics of the crontab at https://en.wikipedia.org/wiki/Cron.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.130.24