Scheduling Backup Jobs With Crontab15 Jul 2016
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 other 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.
To start using cron just type in,
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,
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,
Save the executable location, we’ll be using it next.
Now open up your cron tab and add,
This runs your Backup job every 6 hours! Simple! And no extra gems needed.