Create a Cron Job
When you set a shell script to run at a certain time, it is called a cron job. We can create a cron job to run our backup script for us every day, then we don't need to do anything and our files will be backed up! Automating tasks like this is what Sys Admin is all about.
Add Cron Job to Crontab
crontab file is your list of cron jobs - it's all the scripts you want to run automatically and when. To open it, in Terminal, type:
sudo contrab -e
enter to select option two. This opens the file inside of Terminal, and you can edit it in Terminal, too! Use the down arrow key to scroll all the way to the bottom.
This is where you will add your cron job to the list. The line
# m h dom mon dow command is the column headers for minute, hour, day of the month, month, day of the week and what command to execute. On the line below this, we'll add:
0 0 * * * bash /home/ubuntu/bin/backup
This tells it at 12:00am every day, run the backup file (our script for backing up).
To save cron job to the file, hold down control and O. This writes out the file. Hit
enter to save. To exit the file, hold down control and X. Now your cron job is saved and will back up your files every day.