How to make cronjob for Django in Hosing, VPS or Server. This config also what we do in this site.

For example, in your file of /yourproject/yourapp/management/commands/

from import BaseCommand, CommandError

class Command(BaseCommand):
    help = 'To backup your app!'
    def add_arguments(self, parser):
            help='To backup your app!'
    def handle(self, *args, **options):
        if options['backup'] == 'yes':
            # Do stuff
            self.stdout.write('[+] Successfully backup!'))
            self.stdout.write('[-] Can not backup!'))

If you work with hosting, you can setup on Cron Jobs, and setup your time with following this command:

source /path/to/yourenv/bin/activate && cd /path/to/yourenv/yourproject && ./ autobackup yes

But, if you work with VPS or SERVER, please following this command bellow:

$ sudo crontab -e

and then edit it:

# Setup to daily method.
[minute] [hour] [date] [month] [year]
59 23 * * * source /path/to/yourenv/bin/activate && cd /path/to/yourenv/yourproject && ./ autobackup yes


See also:

101 1 1 0