How-To
Customizing Your AWS Backup Schedule with CRON Expressions
Like most other cloud backup solutions, AWS Backup makes it easy to schedule your backup so that it runs according to a schedule. Even so, the standard scheduling options aren't necessarily going to be a good fit for every situation. If you want your backup to run daily, weekly, monthly or even twice a day, then you don't need to worry about using CRON expressions. If however, you find yourself needing schedule backups to run according to a very specific schedule, then you can use CRON expressions to get the job done.
AWS Backup creates backup schedules as a part of a backup rule. Normally for example, you would create a backup plan and then add one or more backup rules to that plan. As you can see in Figure 1 for example, you can choose one of the built in backup frequencies and then pick a start time.
The options shown in the figure vary a bit based on the backup frequency that you select. If you opt to create a monthly backup for example, you can choose which day of the month you want to run the backup on. As an alternative, you might choose to run the backup on the second Tuesday of the month, or something like that. Although these options do give you a bit of flexibility with regard to backup scheduling, there are limits to what the built-in backup frequencies can do.
This is where CRON expressions come into play. A CRON expression is essentially a text-based code that AWS Backup interprets as a backup schedule.
If you look back at the previous figure, you will notice that the last option on the dropdown menu is Custom CRON Expression. Selecting this option causes AWS Backup to display a text box where you can enter a CRON expression, as shown in Figure 2.
Although the CRON expression shown in the figure above might appear to be a bit cryptic, there is a method to the madness. The really important thing to pay attention to in the CRON expression shown in the figure is the existence of spaces. The CRON expression is made up of 6 separate values and those values have to be separated by a space. As such, the values for the CRON Expression shown in the figure are:
Value 1: 0
Value 2: 1
Value 3: ?
Value 4: *
Value 5: 2#1
Value 6: *
So now that I have shown you the individual values that make up the expression, let's take a look at what these values mean.
The first two values pertain to minutes and hours respectively. In this case, the first value is 0, indicating 0 minutes. The second value is 1, indicating 1 o'clock. These two values collectively tell AWS Backup to run the backup rule at 1:00 a.m.
As another example, let's pretend that the first value was a 5 and the second value was 13. Because the backup rule uses a 24-hour clock, the number 13 corresponds to 1:00 p.m. However, the presence of the number 5 in the minutes field would make it so that the rule would execute at 1:05 p.m.
The next two values correspond to the day of the month and the month. In this case, the day of the month is set to ? and the month is set to *. Both of these are wildcard values. The question mark means any (any day of the month in this case). Another way of thinking of this is that the day of the month will be ignored, which is what you have to do when you are specifying a day of the week instead. The asterisk is a wildcard meaning all. Here, it means all months, or rather that the backup rule will execute every month.
The last two fields are Day of Week and Year. The Year field contains an asterisk, indicating that the rule will run regardless of the year. However, the Day of Week field needs a bit of explaining.
The Day of Week is set to 2#1. The 2 indicates the second day of the week, or Monday. The pound sign indicates that you want to use an instance of the specified day. The number 1 following the pound sign means that the rule will run on the first Monday of the month.
When you put all of this together, the code indicates that the backup rule will run at 1:00 a.m. on the first Monday of each month.
Incidentally, there are a few more symbols that you can use. The letter L means Last, so you could use an L to indicate that you want to run a backup rule on the last day of the week or the last day of the month. Similarly, the letter W means Weekday. You can take things a step further by inserting a number before a W. For example, 20W would mean that you want to execute the rule on the weekday that is the closest to the 20th of the month.
You can also use standard abbreviations for days and months, and you can use commas and dashes. Some common expressions might include Mon-Fri or Jan,Feb,Mar.
About the Author
Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.