The Problem: I had been backing data from my stand-alone server (Mac Pro G5 with Ubuntu Server 13.04 software) to an external USB drive on an iMac, then to a hard drive on a HP laptop with Debian OS, and finally to SkyDrive (a Microsoft cloud storage option). Duplicacy for Windows/Mac/Linux. Duplicacy is a new generation network and cloud backup tool based on the idea of Lock-Free Deduplication. Currently it supports local drives, SFTP servers, Amazon S3, Wasabi, Backblaze B2, Microsoft Azure, Google Cloud Storage, Google Drive, OneDrive, Dropbox, and Hubic. What You Need: Mac OS X Files to synchronize Some Command Line Knowledge. Simple File and Directory Synchronization. One of the simplest things you can do with rsync is to backup files.
Rsync For Windows Download
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 ServerRsync Gui
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:
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
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:
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
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 VariablesFILESRsync E Option
â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
Copyright © 1999-2020 SS64.com
Some rights reserved
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.
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:
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
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. Zosi view app. 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:
How to download python on mac.
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!
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.
Rsync App Mac Os X
Vond je dit een leuk artikel? Abonneer je dan op mijn nieuwsbrief: De Circulaire. Elke twee weken in je mailbox!
Add a comment42 commentsRsync App For Mac Catalina
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |