Musings of an Apple Systems Administrator
A blog about the day to day tasks of a systems administrator. A how to guide and user tell all about OSX Server systems issues and challenges.


Blogroll
Recent Comments
  • Will: Great, so glad Apple is supporting this, about time!
  • Daniel Laughland: Thanks for this! Made my life a lot easier. This beats the pants off of Squirrel Mail.
  • Philip Van Luchene: Great tip, you saved me a lot of hours. Thnx
  • Del Brown: Looks good Jon…good tips are hard to find:)
  • Jeremy Welnar: Hi Jon! Was googling around and found your post on the mail backups. I’m playing with rsync right now...
III Syncing a failover website : Scheduling the sync
1

So now we have our backup script, we have our secure SSH tunnel between the two servers and we have successfully synced our two databases and our files. Now we just have to schedule this task so that we do not have to manually run this each time we need to synchronize our systems. On Mac OSX Servers you have two options you can use Crontab and run a Cronjob, or you can use Launchd. If your running a Linux server then your pretty limited to just a Cronjob. We will talk about both types of scheduling methods and which one makes the best sense for your setup.

Crontab is one of the longest lasting scheduling daemons around, its part of any linux / unix system and uses a file that will trigger a script at a specific time at specific intervals. Cron can be pretty amazing but pretty daunting too if you are unsure about how to use cron, I recommend starting out easy and using this GUI for Mac OSX called Cronnix.

Cronnix is a great tool because it lets you modify, save and create crontab cronjobs in a very easy to use interface. Before Cronnix you basically had to use the VI editor in order to edit the crontab file manually which did not always prove successful. Once your ready to make your first schedule then you need to know what time or at what intervals you want the backup to run. I had my backup script run at midnight every-night so my crontab looked like this.

1
0 0 * * * /bin/bash /path/to/my/sync/script.sh



Here are some other popular crontab examples that might give you some greater insight and understanding on the whole cronjob scheduling schema.

1
2
3
4
5
6
0 0 * * *          -- midnight every day
0 0 * * 1-5        -- midnight every weekday
0 0 1,15 * *       -- midnight on 1st and 15th
                      of month
0 0 1 * 5          -- midnight on 1st of month
                      and every Friday

The second method for scheduling tasks on a Mac OSX Server platform is Launcd. This is the timer system that Apple has written and sanctioned as being the best way to schedule tasks, the reason is that unlike a cronjob where if you want to pause the job, you must remove it from the system entirely and then re-enter it when you want it to resume. With launchd you can unload / or load schedules to run at startup or on regularly scheduled intervals. I would be lying if I told you I was a launchd master, but I do like the advantages that launchd has to offer.

While getting my script up and running I used This tutorial to get me started. The launchd file below is what I used in order to get my backup scheduled. In order to install your launchd file place it in one of these locations.

/System/Library/LaunchDaemons (admin level system daemons)
/System/Library/LaunchAgents (admin level user agents)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
< ? xml version="1.0" encoding="UTF-8" ? >
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \ "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<dict>
        <key>Label</key>
        <string>com.macresearch.backup</string>
        <key>LowPriorityIO</key>
        <true/>
        <key>Program</key>
        <string>/Users/gohara/Library/Scripts/backup.sh</string>
        <key>ProgramArguments</key>
        <array>
                <string>backup.sh</string>
        </array>
        <key>WatchPaths</key>
        <array>
        <string>/Volumes</string>
        </array>
</dict>
</plist>

Once you have your launchd file installed you must register the launchd file with your system by running

1
  launchctl load ~/Library/LaunchAgents

Then issue

1
 launchctl list

Then you should see something like this

1
2
[Voyager:~/Library/Scripts] gohara% launchctl list
com.macresearch.backup

for my sync script I chose to use a crontab, because my knowledge of launchd is limited and my experience with cronjobs is more extensive I found that adding a cronjob was faster, quicker and more efficient for permanent scheduled items on my servers. I would love to get your feedback however and learn more about launchd from you.

| More
Do you need system administration assistance? If you like what you are reading please consider subscribing to the RSS feed for comments on this post. If you have feedback you can leave a response, or trackback from your own site.
leave a comment
leave a comment
Leave a comment

1 + 4
You may add code snippets to your comments by using this format
<pre lang="php" line="1"></pre> replace "php" with your codebase .

* A Required Field