dev | 2016-07-16 00:00:00 +0000
Scheduling Backup Jobs With Crontab
Hellonext Team / 2016-07-16 00:00:00 +0000
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.
Last updated: September 7th, 2023 at 7:42:06 AM GMT+0
Hellonext Team
Hellonext is a user feedback tool and this article was written by many people at Hellonext. Hellonext helps prioritize product roadmap based on user-input.