Rsync For Mac Os

Posted on  by 



  1. Rsync For Macos

Windows and Mac filesystems are very different, so you could be comparing apples to oranges. Rsync first checks to see if the destination file exists and has a later timestamp than the source. If so, it skips it. If not, and the times are equivalent, it will compare file sizes. If the sizes are the same, it skips updating the file. Rsync mac free download. Rclone Rclone is a command line program for syncing files and directories to and from various cloud storage. Acrosync for Mac is a new rsync client for OS X with an easy-to-use GUI and Dropbox-like automatic upload. It can be also be configured to create hourly incremental network backups similar to Time Machine, but without the need to install server software.

We all know we need to make backups. Apparently, 30 procent of all computer users lose all of their files sometime in their life. Not a pretty foresight.

Jul 10, 2018 Before we get into details about using rsync on the Mac, a note about versions. The version of rsync that’s distributed with the Mac tends to lag behind the current version available on the rsync website. The Mac version has been at 2.6.9 for a number of years, while the current version is at 3.1.3 (as of January, 2018). I did a backup to a remote NFS folder using rsync, from a Mac to a remote Debian system. The final backup is 58GB less than the original. Rsync says that everything was OK, and there's nothing to update.

Fortunately, Mac Leopard users have a program called Time Machine that makes things a lot easier. But is Time Machine the perfect backup solution? I don’t think so. There are a couple of things that make Time Machine very unsuitable for me:

  • You need to get a seperate external hard drive that can only be used for Time Machine (and has to be formatted first)
  • That drive has to be formatted in HFS+, hence, without any (commercial) third-party plugins it’s not readable on Windows or Linux systems
  • You have to leave your drive on all the time to make sure Time Machine makes backups
  • You can’t make a list of things you want to have backed up, you can only exclude folders from your complete hard disk
  • Time Machine makes an exact copy of your hard drive

Especially that last ‘feature’ is very irritating to me. I have an external drive with about 300G of files, including lots of music and video files. My MacBook drive is only 80GB big, so i can never have the complete contents of my external drive on my MacBook. Let’s say i have 10GB of MP3 files, which i backup with Time Machine, then i remove about 5GB of files from my MacBook to free some space. What happens when the next backup round is happening? Exactly, the 5GB of files get deleted from the external disk as well. When i want to play a certain MP3 file from my external drive i now have to ‘restore’ and ‘look back in history’ to find it. Not very user-friendly.

Luckily, there is a very good (free) alternative to Time Machine that does exactly what i want with backups: it lets you specify which folders you want to backup, it doesn’t delete things on the backup drive when you delete files from your original drive, and it’s compatible with any external drive and can even backup files over a network. This piece of software is called rsync. Here’s how to use it.

rsync is a command-line utility shipped with every copy of Mac OS X. It originated from the UNIX/Linux world, where it has been part of most Linux distributions for many years. rsync is reliable, fast, and easily configurable. Try running it by opening up the Terminal.app (located in your Applications/Utilities folder) and running the command:

rsync

You’ll get an overview of all possible options. In essence the syntax is very simple:

rsync OPTIONS SOURCE DESTINATION

What you’ll probably want is a one-way transfer of all files in SOURCE to DESTINATION, where only files are copied that are not available on the DESTINATION disk or different. Aside from that you’ll want to include all subdirectories, links, permissions, date/time, groups, owner and devices. To do that simply use this easy-to-remember option list:

rsync -rlptgoD

Ha, just kidding! Fortunately there is another switch that does all of that with one switch, namely the archive switch:

rsync -a

So, let’s say you want to backup the files in your Documents directory to your external harddrive, which you appropriately named ‘backup’, then this would be the command:

rsync -a ~/Documents/ /Volumes/backup/Documents

For those of you who don’t use the Terminal very often: the tilde (~) is a shortcut for your home directory. If, for example, your name would be ‘Alice’ your home directory would probably be

/Users/alice

In essence you could write the statement above also as

rsync -a /Users/alice/Documents/ /Volumes/backup/Documents

The /Volumes/ path always leads to your drives under Mac OS X. This is also true for DMG files and CDs and DVDs you load.

An important thing to remember is that you should always include a trailing slash (/) after the SOURCE directory and no slash after the DESTINATION. If you wouldn’t do that, and you forgot the slash after ~/Documents rsync would create a directory named ‘Documents’ in the /Volumes/backup/Documents directory, so your files would eventually be backed up under

/Volumes/backup/Documents/Documents/

If you want to get a little more feedback on what rsync is actually doing you can add a few more options to let it output a little more to the screen:

rsync -a --progress ~/Documents/ /Volumes/backup/Documents

You might also want to exclude a few sub-directories or files with the backup. A good example of this is the virtual machine files Parallels makes in the /Documents/ directory and which can be quite large and will be backed up every time. If you have a large virtual machine, this could easily take 15 minutes.

rsync -a --exclude Parallels/ ~/Documents/ /Volumes/backup/Documents

Mac

Another option that you might need is when you use a FAT-32 formatted drive. FAT-32 is currently the only filesystem that is supported by all major operating systems, until Apple finally adds write support for NTFS under Mac OS X (There is a very good free / open source alternative called NTFS-3G that works beautiful, but isn’t supported officially by Apple yet). FAT-32 has a shortcoming that it can’t handle files over 4GB, which is pretty irritating if you have large DV video files or DVD backups. Another shortcoming is that it doesn’t properly set file update times, so it will copy all files, modified or not, every time you run your backup. Fortunately, there is a switch to fix this:

rsync -a --modify-window=1 ~/Documents/ /Volumes/backup/Documents

So, we have all the ingredients to make a proper backup script with only the directories you want. What i did to make my own backup script is simply copying the rsync command many times with alternate source / destination paths. A Linux guru could probably come up with a better solution, but this solution works fine for me. For some inspiration for your own backup script, here’s a portion of my script:


#!/bin/bash
rsync -a --progress --exclude Parallels/ ~/Documents/ /Volumes/backup/Documents
rsync -a --progress ~/Music/MP3/ /Volumes/backup/Media
rsync -a --progress ~/Pictures/ /Volumes/backup/Media/Pictures
rsync -a --progress ~/Backup/ /Volumes/backup/Data
rsync -a --progress ~/Movies/ /Volumes/backup/Media/Video

Note the first line of the script (‘#!/bin/bash’). This line says that it is a script executed by the shell. To make this script runnable you need to set some permissions. If you named your script ‘backup’ this would be the command

chmod u+x backup

Now simply run the backup script at any time you like and be very happy knowing that your data is safe on your external hard drive!

Rsync for windows download

Just one last word of advice: rsync isn’t as fool-proof as Time Machine. If you would, let’s say, per accident swap the SOURCE and DESTINATION values you would lose data. Be very careful before running your backup script with any valuable data.

So, hopefully this article has given you some advice on how to use rsync to back up your Mac. Feel free to drop any comments in the comment field below.

Vond je dit een leuk artikel? Abonneer je dan op mijn nieuwsbrief: De Circulaire. Elke twee weken in je mailbox!

Add a comment

42 comments

  • Better than Time Machine: backup your Mac with rsync

    […] Game Posts wrote an interesting post today onHere’s a quick excerpt We al know we need to make backups. Apparently, 30 procent of all computer users lose all of their files sometime in their life. Not a pretty foresight. Fortunately, Mac Leopard users have a program called Time Machine that makes things a lot easier. But is Time Machine the perfect backup solution? I don’t think so. There are a couple of things that make Time Machine very unsuitable for me: You need to get a seperate external hard drive that can only be used for Time Machine (and has to be […]

  • rsync backup script

    […] Fortunately, Mac Leopard users have a program called Time Machine that makes things a lot easier.http://www.haykranen.nl/2008/05/05/rsync/An open source, completely automatic on-line backup system for UNIX.This is better than rsync, since […]

  • include date in folder name in unix

    […] […]

  • jon

    “You need to get a seperate external hard drive that can only be used for Time Machine (and has to be formatted first)”

    False.

    The hard drive can be used for other things as well. It doesn’t have to be external either. It doesn’t even have be separate, but you’d be stupid to think that backing up your only hard drive to your hard is any kind of protection.

    Still, it doesn’t seem time machine is a good match for you since you don’t want the kind of backup solution it offers (complete and mindless backups).

  • Tim

    This was just what I was looking for. I have an old HHD from old PC. And just want to backup the Documents folder on my new iMac. And do it whenever I what, whithout having the HDD on all the time. Much, much easier than figuring out how TimeMachine works/doesn’t work. thanks!

  • Grover

    Thanks for the very straightforward overview of using Rsync. It was exactly what I needed to solve a problem I was having.

    @jon
    Is Time Machine your girlfriend or something? Why are you taking it personally that Mr. Kranen wants to use something else?

  • Xl Organism

    This was exactly what I was looking for. Thanks for posting this. Ciao!

  • Kranki

    1) TimeMachine does not do a complete backup of your harddrive. Do a full restore and you will find (for instance) that you are missed the “/User/Shared/SC Info” directory which is your iTunes authorization data. Apache will be missing a directory.
    2) I have yet to do a full TimeMachine backup and have it be 100% of what I used to have. For instance, recently my harddrive failed and I did have to do a full restore. Well, things like Terminal started having lines through it that just did not exist prior to the backup.
    3) If it were implemented as a full backup such as what you can do with asr or hdiutil, but with history. Then I would be more positive on it. But for now it is back to rsync, hdiutil and asr.

  • Anonymous

    What would be your strategy for creating multiple backups…as in how Time Machine keeps archives of backups along the lines of daily/weekly for up to one month? I like Time Machine, but I don’t like that it requires my network drive to be on all the time. I’d rather make one backup per day (not hourly like Time Machine wants), but also be able to keep archives as far back as one month, like this:

    1. Daily backups for one week (last 7 days worth)
    2. Weekly backups for one month (4 backups)

    Hopefully I’m explaining this clearly. Thanks.

  • Hay

    @09: you could write a cron job that makes a backup every day and another one that archives them weekly. Note that this means that you end up with many duplicates of the same files, that might fill up your backup disk pretty quickly. The beauty of Time Machine is that it takes up less space because it uses symbolic links.

  • dantux

    If anyone is interested, I posted some time ago, my rsync backup script. It does just that: saves hourly, daily, weekly, monthly, yearly backups using the same concept as Time machine does (hard linking). This does not hard link directories, but does for existing files, which saves a lot of space.
    Check it out:
    http://dantux.com/weblog/2009/03/23/using-rsync-as-a-backup-solution/

  • Drew Stephens

    Time Machine actually uses hard links, not symbolic links, allowing the oldest backups to be removed when space runs out on the backup drive.

  • WeaselSpleen

    Yo, Time Machine is MY girlfriend, you best step back son.
    Nobody treats her betta than me.

  • Mr MArk

    Hey Guys,

    Just thought you should know the RSYNC that shops with osx does NOT backup OSX File Metadata efficiently!

    This sucks. Read this for more info.

  • Dov

    FAT32 can handle drive up to 16 TB, the 4GB limit is imposed in Microsofts Format command which artificially limits the ability to create large volumes.

    This seems originally to be a move to force people to upgrade from Win98 to win2000 and NTFS if they want large disk support. Most external hardrives are formatted as FAT32 using the manufacturers own version of a formatting tool with no 4GB limits at all

    There are utilities that will format a FAT32 volume in excess of 4GB that can be found with a simple web search

  • Anonymous

    As a new Apple user – this is another example of an OS not allowing it’s users any flexibility.

    Backup via Time Machine could be useful if it was written in such a way as to allow the user to choose what is backed up and schedule it accordingly.

    I know, Apple people will bleat loudly, but the OS has some significant drawbacks for users that know what the are doing and, don’t want be nannied.

  • Anonymous

    TimeMachineEditor lets you adjust the interval that TimeMachine backs up at. http://timesoftware.free.fr/timemachineeditor/

  • Anonymous

    You need to get a seperate external hard drive that can only be used for Time Machine
    -> Wrong! You can backup to a partition on your internal harddisk if you want. (Would be stupid, but it IS possible) Also, the same goes for EVERY other backup program. Also, the disk is NOT exclusive for Time Machine. It’s just a drive with files and you can add/edit/delete files all you want.

    (and has to be formatted first)
    -> Depends; I ALWAYS buy Western Digital drives in the Studio range; preformatted for mac. My choice. If you choose another; formatting takes about 3 minutes.

    That drive has to be formatted in HFS+, hence, without any (commercial) third-party plugins it’s not readable on Windows or Linux systems
    -> We’re backing up a Mac, what’s wrong with using a Mac file system? Second; the better linux distros can read HFS+ without any trouble. It’s Windows that sucks big time.

    You have to leave your drive on all the time to make sure Time Machine makes backups
    -> Well, I’d like you to show me ANY ONE backup that can backup to a disk that is not on.

    You can’t make a list of things you want to have backed up, you can only exclude folders from your complete hard disk
    -> Which serves it’s purpose very well; that way you cant forget to include newly created files/folders.

    Time Machine makes an exact copy of your hard drive
    -> As opposed to …. what, exactly? What is wrong with having a full copy of your drive? I don’t want to spend hours reinstalling my OS, then my Apps and then my files after a crash. I used to have to do that with WIndows and I’m sick and tired of that. With Time Machine, i place a new drive, boot from the OS CD and recover my drive. Easy as that.

    I really like your approach with rSync, but your reasoning is flawed.

    @Anonymous #16; As a new Apple user – this is another example of an OS not allowing it’s users any flexibility.
    -> OSX _IS_ giving it’s users all the flexibility it can give; Use Time Machine for a full backup with revisioning, or use rSync (shipped with it) for the more complex tasks. Compared to windows; no backup software to speak of, no revisioning, no rsync.
    On a Mac, there is NO reason whatsoever to not backing up your harddisk. On Windows there is, well, windows IS the biggest reason but that’s beyond the scope of this topic.

    @Kranki #8
    I do not share your (bad) experience with Time Machine. I’ve restored not many machines but a few and all of them restored without any problem whatsoever (including our mac mini server that lost a drive due to a power outage)

  • Anonymous

    Why do so many say it’s silly to backup a hard disk to another portion of the same hard disk? For me, one HUGE value of backing up (with whatever method, but preferably with some form of history) is to get an earlier version of a file I messed up. In fact, that’s the only reason I’ve ever actually used a backup in practice (I admit: I’ve been lucky). OK, it WOULD be silly to not ALSO backup to an external drive for protection against the drive crash scenario… It does happen, I know. And I will do that too. Just don’t discount the value of a simple historical copy of the work you do as part of everyday workflow.

    For the curious: I use TM to backup up my SSD drive to the internal HD on my iMac. In addition, I use a sym link from my desktop to a “working” directory on the HD (I don’t want my every day files to start filling up the SSD), and hoped that TM would back up that working directory too. Not surprising, but unfortunate: it faithfully backed up the sym link, but that’s it — meaning that the TM backup process doesn’t FOLLOW the sym link and backup the files & directories it finds there. (Of course, I can’t use a hard link since it’s across file systems.) So an rsync solution such as described here is something I’m considering for that “working” directory.

    Similarly, I’ll probably develop an rsync solution to fully backup the HD to an external device, for that rare day when the HD decides to croak. Yes, I could use TM itself, manually switching it from the SSD to work instead with the HD, then switching back after its done (yuck) — or fool with the TM plist to do the switching. Much to do, much to learn….

  • Online Backups Over Google Fiber: Crashplan or Backblaze?

    […] for a flat monthly rate. (Given my backup size, I want to avoid paying a per-gigabyte price.) I use rsync to back up my live files to a 2TB backup drive that I then want to mirror to an online backup. I […]

  • Time Machine sucks, use rsync instead « Brian Windheim

    […] won't go into too much detail on rsync usage (some resources that might help: 1, 2, 3), but here's how I backup an entire external volume using […]

  • James

    Can both Source AND Destination be external, or does one have to be in home directory/interbal? I’ve got an external drive of >1TB and I’d like to sync its backup to it.

    Thanks,

    James

  • lucidsystems

    If you are using rsync for backups on OS X, then you may also find LBackup of interest : http://www.lbackup.org

    LBackup is an rsync wrapper designed for backup of user data.

  • Brian H

    Yes, James, I’m synching two external drives as we speak. Many folks put pictures and movies on external drives to save space on their computers, but fail to back those up.

  • joe

    rsync -a is missing -H

    So, if you want to preserve hardlinks then you need to add that option.
    This will increase the amount of time it takes for the overall rsync to perform.

    And, this is not necessary if you are backing up directories that you know do not include hardlinks. However, if you are backing up system directories, you may want to be sure and include that option.

  • New Year’s Resolutions | Monkeyologist

    […] like to roll my own Time Machine replacement using the Unix utility rsync, mainly because you can’t exclude folders from Time Machine. I often eject it in frustration […]

  • Terry Flannery

    Many thanks for the excellent doc.

  • flow in

    thanks hon, works well. to share to a windows box, i mounted the windows share onto the mac (adding the share mount into the login items) then rsync’d to the mac’s mounted volume – rsync wouldn’t work direct to the shared folder.

  • Madhu

    Useful article and the solution I was looking for. I just have the need to keep copying the changed and new files to external hard drive. I may periodicaly delete the files from my Mac, but still need them to be available in the external disk. So looks like rsync is the solution rather than Time Machine

  • Malcolm

    Thanks Hay, your info is clear and easy to understand. I will be using it.

  • Dave

    Backaroo from Bonhard Computing is a wrapper for rsync and rsyncd. It lets you schedule rsync via a simple user interface. It’s made for exactly this sort of thing. Polycom realpresence for mac. (Disclosure: I am the developer.)

  • Stove99pipe

    Excellent first approximation of how to use rsync and how to automate it. Thanks from a beginning Terminal user. 10 stars :-)

  • Sandman619

    • It’s safe to partition a hard drive to include the backup. Since it is a sep partition directory failure will not affect the backup files.
    • If a disk is not mounted & misses a scheduled backup, Time Machine immediately initiates a backup when the backup drive returns
    • Time Machine completes an initial full backup with future backups only containing changed or new files, its incremental.
    • Time Machine respects other non-Time Machine files on the backup drive, but the more files on the backup drive the less available space for Time Machine backups
    • Time Machine keeps recent backups, a weekly backup & a monthly backup.

  • Dave - developer at Bonhard Computing

    I’ve also just finished developing “Folder Snapshot Utility” which represents a way of doing this but with a clicky-clicky GUI instead of using the command line.
    I’ll try to leave a link to it, here:
    http://bonhardcomputing.com/folder-snapshot-utility/
    Or maybe this will work…
    Folder Snapshot Utility

  • Andy

    Hi Hay, Thank you for sharing a great comprehensive article on rsync. I have been trying all possible operators in my rsync command but I have failed to sync my MBA with External Hard Drive exFat. The file Created Date changes to the date I run the script. Weirdly, the files Modified Date and Last Open Date don’t change.

    Script Editor command below:

    tell application “Terminal”
    activate
    do script “rsync -a –update -raz –progress /Users/me/Documents/ /Volumes/TT1/documents” in front window
    end tell

    Is this to do with rsync not handling permissions on exfat?
    Thank you in advance.

    Cheers, A.

  • JACK REACHER

    Vagrant glosses over these issues, although the variety of shared folder implementations hints at the problem.

    Native
    The native shared folders feature in VirtualBox is notoriously bad. VMware is better, but not ideal.
    NFS
    Linux/Max only.
    Need NFS installed on host and client.
    Alters host NFS configuration.
    Effects networking setup on VirtualBox
    Can not alter user/group on client.
    Rsync
    Need Rsync installed on host and client.
    One way — changes on the client by default are overwritten.
    SMB
    Windows only.
    Can not alter user/group on client.
    Must manually clean up.

  • Baretto James

    Better than time-machine. Lol. Catchy title though. Dude I was searching for an alternative to rsync on windows, too many came up. Tried them, useless they were. My friend told me to use GS Richcopy 360. Man, that one suggestion solved everything. This Richcopy 360 is pretty dope!

  • TimeMachine cool and i tell you why

    What you are comparing here is a filebased backup via rsync with a full system backup with TimeMachine. But that’s a unfair comparison for both programms.

    TimeMachine not only produces a (what you didn’t mention your article) a bootable drive, with a recovery system, but it saves your data incrementally, like rsync does.

    I have a 1TB drive (internal) as a backup drive and a system drive 1TB (500GB used). 10 backups on my backup drive could only mean, that TimeMachine don’t simply makes an 1:1 image of your drive. Thats cool, and theres place for 10 more…

    1.) TimeMachine backups every day, every hour, if i want that, even when i forgot to make a backup, TimeMachine does it. Cool!

    2.) You can restore your complete system with your TimeMachine backup and even can choose, which backup do you want to restore. Cool!

    3.) It backups while you are working with your Mac, transparently and nearly unnoticable. Cool!

    4.) As you see now, you can use a internal drive also, no problem with that, it’s much faster that way. Cool!

    I really don’t understand the arguments, that your are writing in you article. Your way of backup doesn’t produce a bootable, full backup, so it is absolutely not usable, when your hard disk crashes and you want to reproduce the working system again.

    Your arguments, my answers:

    * You need to get a seperate external hard drive that can only be used for Time Machine: Wrong, you can use it like any other drive, i copy my mp3 on my backup drive and TimeMachine does’t have a problem with it

    * That drive has to be formatted in HFS+, hence, without any (commercial) third-party plugins it’s not readable on Windows or Linux systems: Of couse you have to… This is the same under Windows with NTFS. By the way, Linux can read and write HFS+ out of the box

    * You have to leave your drive on all the time to make sure Time Machine makes backups: Of couse… Can you make a rsync backup without a drive? But with TimeMachine you can also just start a backup whenever you want and disconnect your drive after that, and connect it for the next.

    * You can’t make a list of things you want to have backed up, you can only exclude folders from your complete hard disk.Time Machine makes an exact copy of your hard drive: Yes, that’s the reason, why so many of use TimeMachine, to have a working copy of the hole system, that you can restore completely, if your harddisk fails.

    What you suggest here is a simple file backup, not a system backup. And that’s obvisiously not the same.

    rsync is cool, i use it too. But TimeMachine has a clear purpose in Mac OsX, and is cool too. Just use both, for both and different use cases.

  • natxo garai

    just awesome !!! Thank you very much

  • Siegfried Leonard

    I found your article quite helpful on how to use rsync on OS X. However, I disagree with you about Time Machine. First, when you delete files from the MacBook the files aren’t actually “deleted” on the Time Machine disk, but merely hardcopies of them. And although you can much around in there, that’s not how the way you use time machine.

    You use the “back in time” interface. I know it sucks a bit and it’s slow, but it has improved a little over the years. It’s differently the thing that they need to improve the most on or change it altogether. Although for users like my mom and dad it works wonderfully (?).

    The problem with rsync is that is that it’s really easy to make a mistake. Manage large files you need deleting with. And with no snapshot support you’ll basically have to run rsync yourself. And that violates ones of the rules of backup, you want an automated system that backups on its own, and still have files you deleted X days/weeks ago.

    I use ZFS myself on FreeNAS for all my file needs. Built a cheap little $300 machine that can fit more hard drives and run more plugins than any other $600 NAS units. I run Time Machine on it, as it has space for all machines. So no more external drives. I think I saved money overall. :)

  • shrirang

    Super Helpful and nice explanation ! Thanks a lot for awesome post.

  • Anonymous

    the guidance is pretty good

Remote file copy (Synchronize file trees)

Quick basic example: backup the desktop to the mybackups folder on an external hard drive:

Options

Additional details about the options above can be found on the rsync options and Exit Values page.

In many cases the Source and Destination will be a directory path, however either the Source or the Destination can be on a remote host:

Description

rsync is a program that behaves in much the same way that rcp does, but has many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file already exists.
The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network link, using an efficient checksum-search algorithm described in the technical report that accompanies this package.

Some of the additional features of rsync are:
# support for copying links, devices, owners, groups and permissions
# exclude and exclude-from options are similar to GNU tar
# a CVS exclude mode for ignoring the same files that CVS would ignore
# can use any transparent remote shell, including rsh or ssh
# does not require root privileges
# pipelining of file transfers to minimize latency costs
# support for anonymous or authenticated rsync servers (ideal for mirroring)

General

There are six different ways of using rsync. They are:
# for copying local files. This is invoked when neither source nor destination path contains a : separator
# for copying from the local machine to a remote machine using a remote shell program as the transport (such as rsh or ssh).
This is invoked when the destination path contains a single : separator.
# for copying from a remote machine to the local machine using a remote shell program. This is invoked when the source contains a : separator.
# for copying from a remote rsync server to the local machine. This is invoked when the source path contains a :: separator or a rsync:// URL.
# for copying from the local machine to a remote rsync server. This is invoked when the destination path contains a :: separator.
# for listing files on a remote machine. This is done the same way as rsync transfers except that you leave off the local destination.
Note that in all cases (other than listing) at least one of the source and destination paths must be local.

Usage

You use rsync in the same way you use rcp. You must specify a source and a destination, one of which can be remote.
Perhaps the best way to explain the syntax is some examples:

This would transfer all files matching the pattern *.c from the current directory to the directory Source on the machine foo.
If any of the files already exist on the remote system then the rsync remote-update protocol is used to update the file by sending only the differences.
See the tech report for details.

this would recursively transfer all files from the directory Source/bar on the machine foo into the /data/tmp/bar directory on the local machine.
The files are transferred in 'archive' mode, which ensures that symbolic links, devices, attributes, permissions, ownerships etc are preserved in the transfer. Additionally, compression will be used to reduce the size of data portions of the transfer.

a trailing slash on the source changes this behavior to transfer all files from the directory Source/bar on the machine foo into the /data/tmp/.
A trailing / on a source name means 'copy the contents of this directory'. Without a trailing slash it means 'copy the directory'.
This difference becomes particularly important when using the --delete option.
You can also use rsync in local-only mode, where both the source and destination don't have a ':' in the name. In this case it behaves like an improved copy command.

this would list all the anonymous rsync modules available on the host somehost.mydomain.com. (See the following section for more details.)

Connecting to an Rsync Server

It is also possible to use rsync without using rsh or ssh as the transport. In this case you will connect to a remote rsync server running on TCP port 873.
You can establish the connection via a web proxy by setting the environment variable RSYNC_PROXY to a hostname:port pair pointing to your web proxy. Note that your web proxy's configuration must allow proxying to port 873.
Using rsync in this way is the same as using it with rsh or ssh except that:

  • you use a double colon :: instead of a single colon to separate the hostname from the path.
  • the remote server might print a message of the day when you connect.
  • if you specify no path name on the remote server then the list of accessible paths on the server will be shown.
  • if you specify no local destination then a listing of the specified files on the remote server is provided.

Some paths on the remote server will require authentication. If so then you will receive a password prompt when you connect.
You can avoid the password prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be useful when scripting rsync.
WARNING: On some systems environment variables are visible to all users. On those systems using --password-file is recommended.

Running an Rsync Server

An rsync server is configured using a config file which by default is
called /etc/rsyncd.conf. Please see the rsyncd.conf(5) man page for more information.

Examples
To Backup the home directory using a cron job:

Run the above over a PPP link to a duplicate directory on machine 'server64'.
To synchronize samba source trees use the following Makefile targets:

this allows me to sync with a CVS directory at the other end of the link. I then do cvs operations on the remote machine, which saves a lot of time
as the remote cvs protocol isn't very efficient.
I mirror a directory between my 'old' and 'new' ftp sites with the command

Mac

this is launched from cron every few hours.

Exclude Patterns

The exclude and include patterns specified to rsync allow for flexible selection of which files to transfer and which files to skip.
rsync builds an ordered list of include/exclude options as specified on the command line. When a filename is encountered, rsync checks the name against each exclude/include pattern in turn. The first matching pattern is acted on.
If it is an exclude pattern, then that file is skipped.
If it is an include pattern then that filename is not skipped.
If no matching include/exclude pattern is found then the filename is not skipped.
Note that when used with -r (which is implied by -a), every subcomponent of every path is visited from top down, so include/exclude patterns get applied
recursively to each subcomponent.
Note also that the --include and --exclude options take one pattern each. To add multiple patterns use the --include-from and --exclude-from options
or multiple --include and --exclude options.
The patterns can take several forms. The rules are:

  • if the pattern starts with a / then it is matched against the start of the filename, otherwise it is matched against the end of the filename. Thus '/foo' would match a file called 'foo' at the base of the tree. On the other hand, 'foo' would match any file called 'foo' anywhere in the tree
    because the algorithm is applied recursively from top down; it behaves as if each path component gets a turn at being the end of the file name.
  • if the pattern ends with a / then it will only match a directory, not a file, link or device.
  • if the pattern contains a wildcard character from the set *?[ then expression matching is applied using the shell filename matching rules. Otherwise a simple string match is used.
  • if the pattern includes a double asterisk '**' then all wildcards in the pattern will match slashes, otherwise they will stop at slashes.
  • if the pattern contains a / (not counting a trailing /) then it is matched against the full filename, including any leading directory.
    If the pattern doesn't contain a / then it is matched only against the final component of the filename. Again, remember that the algorithm is applied recursively so 'full filename' can actually be any portion of a path.
  • if the pattern starts with '+ ' (a plus followed by a space) then it is always considered an include pattern, even if specified as part of an exclude option.
    The '+ ' part is discarded before matching.
  • if the pattern starts with '- ' (a minus followed by a space) then it is always considered an exclude pattern, even if specified as part of an include option. The '- ' part is discarded before matching.
  • if the pattern is a single exclamation mark ! then the current include/exclude list is reset, removing all previously defined patterns.

The +/- rules are most useful in exclude lists, allowing you to have a single exclude list that contains both include and exclude options.
If you end an exclude list with --exclude '*', note that since the algorithm is applied recursively that unless you explicitly include parent directories of files
you want to include then the algorithm will stop at the parent directories and never see the files below them.
To include all directories, use --include '*/' before the --exclude '*'.
Here are some exclude/include examples:
# --exclude '*.o' would exclude all filenames matching *.o
# --exclude '/foo' would exclude a file in the base directory called foo
# --exclude 'foo/' would exclude any directory called foo.
# --exclude '/foo/*/bar' would exclude any file called bar two levels below a base directory called foo.
# --exclude '/foo/**/bar' would exclude any file called bar two or more levels below a base directory called foo.
# --include '*/' --include '*.c' --exclude '*' would include all directories and C source files
# --include 'foo/' --include 'foo/bar.c' --exclude '*'
would include only foo/bar.c (the foo/ directory must be explicitly included or it would be excluded by the '*')

Batch Mode

The following call generates 4 files that encapsulate the information for synchronizing the contents of target_dir with the updates found in Source_dir
$ rsync -F [other rsync options here] /somewhere/Source_dir /somewhere/target_dir
The generated files are labeled with a common timestamp:
# rsync_argvs. command-line arguments
# rsync_flist. rsync internal file metadata
# rsync_csums. rsync checksums
# rsync_delta. data blocks for file update & change

Symbolic Links

Rsync For Mac Os

Three basic behaviours are possible when rsync encounters a symbolic link in the source directory.
By default, symbolic links are not transferred at all. A message 'skipping non-regular' file is emitted for any symlinks that exist.
If --links is specified, then symlinks are recreated with the same target on the destination. Note that --archive implies --links.
If --copy-links is specified, then symlinks are 'collapsed' by copying their referent, rather than the symlink.
rsync also distinguishes 'safe' and 'unsafe' symbolic links.
An example where this might be used is a web site mirror that wishes ensure the rsync module they copy does not include symbolic links to /etc/passwd in the public section of the site. Using --copy-unsafe-links will cause any links to be copied as the file they point to on the destination.
Using --safe-links will cause unsafe links to be ommitted altogether.

Diagnostics

rsync occasionally produces error messages that may seem a little cryptic.
The one that seems to cause the most confusion is 'protocol version mismatch - is your shell clean?'.
This message is usually caused by your startup scripts or remote shell facility producing unwanted garbage on the stream that rsync is using for its transport. The way to diagnose this problem is to run your remote shell like this:

Then look at out.dat. If everything is working correctly then out.dat should be a zero length file. If you are getting the above error from rsync then you will
probably find that out.dat contains some text or data. Look at the contents and try to work out what is producing it.
The most common cause is incorrectly configured shell startup scripts (such as .cshrc or .profile) that contain output statements for non-interactive logins.
If you are having trouble debugging include and exclude patterns, then try specifying the -vv option. At this level of verbosity rsync will show why each individual file is included or excluded.

Setup

See the file README for installation instructions.
Once installed you can use rsync to any machine that you can use rsh to. rsync uses rsh for its communications, unless both the source and destination are local.
You can also specify an alternative to rsh, either by using the -e command line option, or by setting the RSYNC_RSH environment variable.
One common substitute is to use ssh, which offers a high degree of security. Note that rsync must be installed on both the source and destination machines.

Environment Variables

FILES

“I was the only kid in the audience who didn’t understand why Dorothy would ever want to go home. It was a mystery to me. To that awful black and white farm, with that aunt who was dressed badly, with smelly farm animals around. When she could live with winged monkeys and magic shoes and gay lions. I didn’t get it” ~ John Waters

Related macOS commands:

rsync.samba.org - Download latest version (plus docs).
cp - Copy files.
install - Copy files and set attributes.
rcp - Remote file copy.
rsnapshot - Save multiple backups with rsync.
Grsync - GUI for rsync.
youtube-dl - Download video.
wikipedia entry for rsync

Rsync For Macos

Copyright © 1999-2020 SS64.com
Some rights reserved




Coments are closed