Custom backup schedule via cron
How to set the right backup schedule using cron expression, sample cron expressions.
Custom Backup Schedule via Cron Expressions
If you want to schedule backups in a customized manner, you can use a cron expression to configure the backup schedule on SimpleBackups. Cron expressions are highly flexible and allow you to define the exact time, day, and frequency of your backups.
Understanding Cron Expressions
A cron expression consists of six fields that define the schedule for a particular job. These fields represent the minute, hour, day of the month, month, day of the week, and year. The fields are separated by spaces and the values within each field are separated by commas. The parts of a CRON schedule are as follows:
* * * * *
- - - - -
| | | | |
| | | | |
| | | | +----- day of week (0 - 7) (Sunday=0 or 7)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
Configuring Cron Expressions for Backup
To configure a custom backup schedule using cron expressions, you need to follow these steps:
- When setting how often we should take a snapshot/backup in SimpleBckups click on the schedule drop down menu
- Look for the Custom option
- In the cron expression field, enter the desired expression that defines your backup schedule.
- Save the settings.
Here are some examples of cron expressions that you can use to schedule backups:
- Backup every day at 2:00 AM:
2 * * *
- Backup every Sunday at 5:00 AM:
5 * * 0
- Backup every last day of the month at 8:00 PM:
20 28-31 * *
Special Characters
Cron syntax incorporates logical operators, which are special characters that perform operations on the values provided in the cron fields.
Character | Description |
* | Any value, meaning all valid values for the field |
? | No specific value, used in day-of-month or day-of-week fields when you need to specify one field but not the other |
- | Used to specify a range of values |
, | Used to separate multiple values |
/ | Used to specify increments |
L | Used to specify the last possible value of a field |
W | Used to specify the nearest weekday for a given day |
# | Used to specify the nth occurrence of a weekday in a month |
The Question Mark Character (?):
A question mark ( ? ) is allowed in the day-of-month or day-of-week fields. It is used to specify “no specific value,” which is useful when you need to specify something in one of these two fields, but not in the other.
For example: If you want a trigger to fire on a particular day of the month (for example, the 10th), but you don't care what day of the week that is, enter 10 in the day-of-month field, and ? in the day-of-week field.
For a cron expression that fires on the 10th day of the month but doesn't care what day of the week it is, you can use the following expression:
0 10 * * ?
Please note that you can only use the question mark character in one of the two parts (day of the month or day of the week). Having multiple question marks is not a valid cron expression.
Conclusion
Using cron expressions to schedule backups offers a lot of flexibility and customization options. With a little bit of knowledge about cron expressions, you can easily configure a backup schedule that suits your needs.
Last updated on February 2, 2023