Usually websites have some management tasks to do in the background once in a week, day, or every hour. This can be achieved using cron jobs that are also known as scheduled tasks. These are scripts that run on the server for the specified period of time. In this recipe, we will create two cron jobs: one to clear sessions from the database and another to back up the database data. Both will be run every night.
To start with, deploy your Django project on to a remote server. Then, connect to the server by SSH.
Let's create the two scripts and make them run regularly by following these steps:
Create the
commands
,db_backups
andlogs
directories in your project's home directory:(myproject)myproject@server$ mkdir commands (myproject)myproject@server$ mkdir db_backups (myproject)myproject@server$ mkdir logs
In the
commands
directory, create acleanup.sh
file with the following content:# /home/myproject/commands/cleanup.sh #! /usr...