Skcript Technologies Private Limited

← All Articles

Scheduling Backup Jobs With Crontab

— Written by

Scheduling Backup Jobs With Crontab

Scheduling database backup jobs are super easy and necessary.

Backup is an insanely useful gem for, well backups. I use it in production all the time. It can run independent of your Rails app, which in in production can be quite helpful. I’m going to skip ahead and assume your Backup jobs are already set.

You can also schedule backups however it requires using another gem, Whenever. I don’t like to add another dependencies on my production servers. So the easiest way to over come that was to use Linux’s built in scheduling system, cron!

Cron is a system daemon used to execute desired tasks (in the background) at designated times.

Using Cron

To start using cron just type in,

crontab -e

This opens up a file in which you can enter any jobs you want to execute periodically. Each job starts on it’s own line. The general rule is,

<periodic intervals> <system command>

Scheduling A Backup

To periodically run your Backup jobs, we simply need to add the command to the crontab. But before that, we need to find the right Backup gem executable, that’s easy to do. Just run,

which backup
# /usr/local/bin/backup

Save the executable location, we’ll be using it next.

Now open up your cron tab and add,

0 */6 * * * /bin/bash -l -c '/usr/local/bin/backup perform --trigger mysql_backup'

This runs your Backup job every 6 hours! Simple! And no extra gems needed.

Up next

Useful Imagemagick Commands
Skcript /svr/scheduling-backup-jobs-with-crontab/ /svrmedia/heroes/backup-jobs.jpeg
Skcript Technologies Private Limited

Book a free consultation

Book a time with our consultants to discuss your project and get a free quote. No strings attached.