Newsflash
To post a question to the Harmony Forum or open a Help Desk ticket you must register. Click on the "create one" link in the Login Form. You must enter a valid email address. Your info is confidential and never shared with marketers.
Best Mac Backup Ever PDF E-mail

Here at HarmonyService, we assume you Mac users out there know what you know and stick with it. We hope that backing up your data is one of those things you know. Just in case, we'll show you an easy, secure, safe and complete backup solution for your OSX systems.

15 years in the technical profession has shown us just about every sort of data loss. Working in a college town has provided even more immediate experience. We've lost count of how many dissertations, term-papers, multi-media projects, and overdue homework assignments we've been asked to recover from dead media. Although we can recover just about anything, it's usually expensive and not 100% sure. We love to give the "computers are worthless without a good backup" speech to grieving customers.

Here are some facts about computers:

    1. Hard drives are likely to fail.
    2. Writable CD's and DVD's get scratched, wear out and are very slow.
    3. Zip disks are just about the least reliable hardware ever invented.
    4. Tape drives are expensive, slow and difficult to recover.
    5. Floppy disks are too small.
    6. Flash drives lose their formatting and get lost.

So, if everything in our computing world eventually dies, whatever shall we do to keep our valuable data among the living? The simple answer: backup to a remote host using rsync and ssh. This answers all local dilemmas: no need to buy hardware, someone else is responsible for hardware integrity, data is off-site and is quickly available for recovery to any system anywhere. The possible drawbacks to remote backups are speed and space. The speed depends on your internet connection and the space depends on your remote host. If you have a dialup internet connection, this is not for you. If you have 200 gigs of music to back up, you are better off using a large external firewire hard drive. But for 95% of your personal data backup needs, remote backups will work perfectly. Of course, HarmonyService always recommends redundant backups of important data on as many types of media as possible.

Requirements:

To get started, we first assume you have an internet connection and a remote host. A high-speed internet connection is best for all upload and download tasks but certainly not necessary. Because our backup strategy can run in the background, as long as your computer is on and connected to the internet, the backup will happen. A remote host is any other computer providing log-in and storage services. You can use another Mac on the same network running OS X if you like. Simply open System Preferences, click sharing and note your hostname (something.local). The ssh username and password will be the admin username and password of your other Mac. Then, check the box next to "Remote Login." However, for this tutorial, we use our web host as the remote host.

The advantages to using your web host as your backup destination are speed (they'll have the fastest connection), reliability (they must honor their "always on" promises), redundancy (they keep their own backups of your domain), availability (you can recover your data anywhere there is an internet connection), and security (if you have a competent web host, they'll have cutting edge security measures installed by default).

If you follow the Harmony How-To titled: Get Personalized Email and a Website, you'll have everything you need already setup. Be sure that you select a hosting plan that provides ssh access and plenty of space. The 1and1.com Linux Business Plan now offers ssh and 200 gigabytes! Before continuing, make sure you have your ssh username, password and domain name.

Now, on to the how-to:

Rsync is a command line utility traditionally used in synchronizing files between two computers, but rsync can also be used as an effective backup tool. This free and powerful tool is simple enough for anyone to use on their OS X desktop.

If you want to learn more about rsync, checkout the rsync Web site.

We are quite aware that Mac folks are by default GUI users (Graphical User Interface - all those windows, pretty buttons, folders, etc). This means that you never dabble in the command line. And you should never have to. Although for this task, the command line is recommended (and most powerful), checkout RsyncX or Psync for free GUI based backup programs. Apple also provides the .Mac backup application called Backup that will sync your files with your .Mac account. We recommend against this for several reasons, the best being that your .Mac account provides precious little space at a very expensive price, the second best: it's extremely slow. The new Leopard (10.5) operating system now has Time Machine! Time Machine will probably work fine for all local backups even if it does access the hard drive too often. However, for offsite or network backups, the techniques below are superior.

On the other hand, OS X is built on a form of UNIX called FreeBSD, which is the king of the command line. So we think you should do this tutorial to prove that you are really a Mac enthusiast. Impress your friends!! Besides, this way is cool and that's the most important thing, to be cool.... If you aren't turned off by the thought of the command line (once you work with it a bit, you might actually be seduced by it), please read on to execute the best backup imaginable. Moving on....

Now it's time to consider what to back up, to where, and when?

What should be backed up? Do you want to run a full system or a partial system backup? A full system backup creates a second copy of everything on your hard drive. This has the advantage of providing a means to quickly restore your system to the exact state it was in when you made the backup. Full system backups take a long time to complete, take up a lot of disk space, and are often unnecessary. If you don't have your OSX installer CD and all your program CD's, you might just have to do a full hard drive backup.

Otherwise, it's best to simply backup your HOME folder. OS X has the handy feature of storing all of your data, including system settings, email, bookmarks, desktop items, dock settings, etc in your little house folder located in the Users folder in your hard drive. Of course, this means that you have to be vigilant about not saving stuff outside the HOME folder. Don't worry, the Desktop stuff is part of the HOME folder. Either way, you must have enough room on your web server to hold whatever you wish to backup.

Where should it be backed up? Your imagination is the limit when it comes to rsync's backup destination options. The scope of this tutorial, however, is limited to a remote web host.

When should it be backed up? Automated daily backups are a good choice for most OS X desktop scenarios. You can use OS X's iCal scheduler to automate your backups. Read on....

Using rsync

The basic command line implementation of rsync is: rsync -a source/ target/. This command copies the source folder to the target as if you were copying by dragging one folder to a hard drive. Unlike copying, rsync uses the rsync algorithm to check for differences between source and destination files. Since it copies only new changes, a technique known as incremental backup, rsync provides a very fast method for updating your backups.

Make exact copies using the --delete flag. You can apply the --delete flag when making system backups, which causes rsync to delete any files found in the target that are not present in the source. This ensures that the target is an exact copy of the source, so that if you delete an unwanted document, it is also removed from your backup. Rsync preserves files found in the target and not in the source by default, allowing for multiple sources to be added to a single target destination.

Let's get down now into the dirt of it....

The Terminal

Step 1

Open the Terminal.  This should be an icon on your dock - hee hee.  If not, open your Macintosh HD/Applications/Utilities/Terminal. Now don't freak out, just flow with it, m'kay?!

When you open Terminal, you should see something that looks like this:

Welcome to Darwin!
The-Universe:~ harmony$

Except that instead of "The-Universe:~ harmony$" you will see something like:  "SomethingSomething:~ yourusername$"

The "$" symbol is the command prompt.  You will type commands there and hit the return key after every command.

For example, try typing the word "date," without the quotes or comma and press the "return" key. Now try typing the word "cal," without the quotes or comma and press the "return" key. Pretty cool eh? No? Whatever!

Step 2

To be able to logon to your web host without being prompted for your password, you need to generate a key that will be trusted by the host, where your backups will be sent to. To accomplish this, type the following command at the $ prompt - then press the "return" key (you might want to copy and paste the command exactly as it's written here to avoid errors):

ssh-keygen -b 2048 -t dsa

If you are using the Tiger operating system or above as the server (10.4 or above), you should use this command from the client:

ssh-keygen -b 1024 -t dsa

After a long pause, you will then be prompted for a file name. Leave it as the default by simply pressing "Enter".

Generating public/private dsa key pair.
Enter file in which to save the key (/Users/harmony/.ssh/id_dsa):

The last step of the key creation is the passphrase. Since the purpose of this is to not enter a password, hence being able to automate the backup, just hit "Enter" twice, leaving them blank.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/harmony/.ssh/id_dsa.
Your public key has been saved in /Users/harmony/.ssh/id_dsa.pub.
The key fingerprint is:
a6:84:5a:a8:cf:ff:31:38:21:85:ca:46:93:88:7a:50 harmony@localmachine

Don't worry about all this text, just let it go. This command just created 2 files in your home folder; one named "id_dsa" and one named "id_dsa.pub." So you open your home folder and don't see the files?? Bwahahhahaha. I shouldn't tell you, but they are located in a hidden folder named ".ssh." Don't worry about this yet (except that if you want to make a folder or file invisible, type a period at the beginning of its name - careful - you won't be able to see it except in the Terminal).

The id_dsa.pub is your public key, which you share with the remote host. The id_dsa is your private key, and this is only for you. Do not lose it or share it with anyone, as this is your passkey! Let's make sure the file is not readable by anyone by cutting and pasting this command into the $ prompt and pressing the "return" key:

chmod 600 ~/.ssh/id_dsa

Anyone having a copy of this key could steal your identity and login to this host as you. It is not any more dangerous to use this method then to use a traditional password, but I will not enter into a debate here. This procedure is safer than shopping online, and you do want your crap backed up right?

Step 3

Now you'll upload the public key to your host with this command using ssh. Remember "sshusername" and "domainname" is the ssh username and hostname of your website (or other computer). You will be asked for your ssh password after you press "return":

cat ~/.ssh/id_dsa.pub |ssh -l sshusername domainname "cat > id_dsa.pub"

Log into your web host with ssh and create the ".ssh" directory if it isn't already there:

ssh -l sshusername domainname

Example: ssh -l ednacrabapple pricipleskinner.com

or

ssh -l usernameOfOtherMacComputer hostnameOfOtherMac.local

mkdir .ssh

Believe it or not, you are now logged into your webhost (or other computer) through the command line. That's right, you are working on their computer right now!

To complete the automated authorization process, create the authorization key:

cat id_dsa.pub >> .ssh/authorized_keys

delete the public dsa file,

rm id_dsa.pub

and protect the new authorization file.

chmod 600 .ssh/authorized_keys

Log out of the web host by typing:

exit

Press "return" and then we'll test the connection. Now that you and your host have the secret authorization key, you should be able to "ssh" into your web host without entering a password - sneaky....Give it a try by entering the following command and pressing "return":

ssh -l sshusername domainname

You should be logged in automatically without being prompted for a password! Remember, we went through that complex (not!) process so that we could do automated backups. Create your backup folder (it's best if this folder lives outside of your web root):

mkdir myBackup

(you can change the name "myBackup" to be anything you want, as long as it's under 13 characters, has no punctuation, and has no spaces.)

Log out again by typing exit and move on.

Build a Program

Groovy, now we are back at our own command prompt, that trusty $ sign. As Bob Ross used to say: "Let's get crazy."

In order to actually backup your crap, we now have the privilege of building a computer program. Never thought you'd do that, eh? So gather yourself and stare at that $ prompt. Or better yet, do the following:

Step 1

We need more power to create programs, so we'll activate the Super User (root). Zoinks. The Super User has absolute power over your system, so be sure to use him wisely (you could conceivably delete your entire system with him). If you are not an "administrator" on your computer, you'll have to use the 'sudo' command. But we like living on the edge, so we'll tell you how to activate the Super User. You've been warned. We'll deactivate the Super User when we are finished, just in case.

Open your hard drive/Applications/Utilities/NetInfo Manager. Click on the Security menu and click Authenticate. Enter your OS X system password. Then go back to the Security menu and click "Enable Root User." You will be asked to enter a new password for the Super User. It would be best not to enter something simple like "root" or "password." If anyone got ahold of this password, you'd be f*d. Leave NetInfo Manager open and get back to the Terminal.

Step 2

Log in as the Super User (Super!) by typing the following and pressing "return":

su

Password:

(enter the root password you just created)

You won't see much different at this point, but beware, you have great power.

Step 3

Enough jive, let's build the program. Type the following set of commands and press "return" after each. You will be going to a program folder, then writing the program, m'kay?

cd /usr/bin

(go to the hidden program folder)

vi backup

(create a program named "backup" using the text editor vi)

Copy (Ctrl + c) this code exactly from the "#!/bin/sh" all the way to the "exit 0."

#!/bin/sh

rsync -av --delete --stats -e ssh /Users/homefolder sshusername@domainname:~/myBackup > ~/Documents/backup.log

exit 0

Go back to the terminal and type the letter "i." You will see the word "Insert" at the bottom of the page. Paste (Ctrl + v) the code and it should appear at the top of the page. You'll have to edit the code to match your info using the arrow keys to move the cursor and the delete key to delete "homefolder," "sshusername" and "domainname." Be careful not to add extra spaces, or delete any other part of the script. Your homefolder name can be found by opening your hard drive/Users folder. See the little house? See it's name? That's your homefolder name. You should know your sshusername and domainname by now, right? If you used a backup folder name other than "myBackup," change that too. The last part of the script tells the program to display the action of the script in the file /Users/HOMEFOLDER/Documents/backup.log. If you want to watch the backup in progress, you can double-click this file while the backup script is running and the Console will open to display the files being checked and/or backed up. You can also choose to save the log in any directory.

When you are satisfied the information is correct, press the "Control" key and the "c" key. Now type a colon (:) and the letter "x" and press "return." Congratulations, you just wrote a program, sort of like how they made Photoshop, eh eh, right.

Rsync is a very flexible program and can do all sorts of things. It can act as your internal network wide backup system too (free and easy). You can push data from your client computers to your OSX server or you can pull data from all the computers on your network to the backup server. For example, if you wanted your OSX server to pull data from a computer with the sharing name "Pully," you'd setup rsync on the OSX server as follows (this will only work with Server version 10.4 or greater):

#!/bin/sh

rsync -avE --delete --stats -e ssh :~/myBackup /NetworkBackup > ~/Documents/backup.log

exit 0

Notice that the only difference is the "E" flag and that the source and destination have switched places. The E tag allows the transfer of Macintosh resource forks so that your Mac will know which program belongs to which file (only with OSX 10.4 or greater). Switching the source and destination makes the local computer pull data from the remote computer instead of push, as in the first example.

Make the program executable using the following command and pressing "return":

chmod +x backup

and exit to your regular safe user:

exit

Step 4

Let's deactivate the Super User now by going back to NetInfo Manager, clicking on the Security menu and clicking "Disable Root User." Click on the Security menu again and click "deauthenticate."

Step 5

You're now ready to make a decision. You can start your first backup now or you can configure the scheduler to run the backup at any recurring time you please. Either way, your first backup is going to take a long time (depending on how big your home folder is). A 2.1 gigabyte home folder took about 4 hours with cable internet. But hey, we have nothing but time right; just start the backup at 5:00pm one day and in the morning (or next week) you'll have your first backup complete. Once that's done, the subsequent backups will be almost instantaneous. If you want to execute your first backup now, read on. Instructions on automating the process are further down.

To start the backup manually at any time, all you have to do is open the Terminal and type:

backup

It will appear that nothing is happening. The cursor drops to another line. But if you open the file located in your Documents folder named "backup.log," you will see the action of the backup. The computer will build a list of new files and then send them to your website backup folder. That's it. Plan to leave your computer on and not let it sleep for the duration of the first backup. Just turn your monitor off and leave it be. As soon as the backup is complete, the command prompt will return.

Automation

Assuming "backup" ran successfully, and that you now have a copy of your important files on the host, it is time to automate the process. You have the option of using a cron job, a LaunchDaemon or an AppleScript. We prefer cron jobs, but we'll use OS X's calendar program "iCal" and AppleScript Editor to do this just for kicks.

If you want to setup a cron job, open the terminal as the regular user and type the following:

crontab -e

This will edit the local scheduling system. Now type the letter "i" once in order to edit the file. Type the following if you want to run the backup every day at midnight (assuming you named your backup script "backup"). Each character is separated by a tab.

#Backup my HOME folder every day at Midnight

0 0 * * * backup

Press and hold the Control Key on the keyboard and type the letter "c". Now type a semicolon (:) and then type wq and press return. Your cron job will be saved and activated. If you want to confirm this, type:

crontab -l

This command lists your active schedules. If you want to edit the schedule, type crontab -e

If you want to learn more about cron formats, click here

To use AppleScript and iCal, keep reading

Open the Script Editor in your hard drive/Applications/AppleScript folder. You'll see an untitled script window. Copy and paste this code into the window:

do shell script "backup"

Click on the "File" menu and click "Save As." Make sure the file format is "script," name it "BackupApp" and save it to a place you won't forget, move, or remove - the Applications folder would be apropo.

Open iCal in your Applications folder or on your dock. Double click on todays date. This will enter a new appointment. On the info pane to the right or left, you will see the appointment details, like this:

Change the title of the event from "New Event" to something like "Backup". Make the "from" and "to" times exactly the same. To the right of the word "alarm" click "None" and change it to "Run Script." Click the "None" below "Run Script" and click "Other." Go find where you put the "BackupApp" script, click on it and then click "select." Below that, change the 15 to 0 and click the pull down to "minutes before." Now, above that, click the "None" pull down menu to the right of the word "repeat." Select "every day" if you want to backup everyday, etc. Make sure the Backup appointment is set for everyday over the next few months (just to be sure) and then quit iCal.

You can also schedule the backup using the cron or launchd systems built into OSX. Click here for a good tutorial on using cron jobs, and click here to learn about the Launch Daemon.

That's all there is to it. Take a deep breath and pat yourself on the back for applying some OS X potential ... or shake your fist at the screen for not cooperating. If you have any problems with this process, please send us an email.

top

Next >

© Copyright 2006 ::HarmonyService:: All rights reserved