2014-01-11 02:15:49 +00:00
|
|
|
---
|
2016-01-19 18:08:53 +00:00
|
|
|
layout: "docs"
|
2014-01-11 02:15:49 +00:00
|
|
|
page_title: "RSync - Synced Folders"
|
|
|
|
sidebar_current: "syncedfolder-rsync"
|
2016-01-19 18:08:53 +00:00
|
|
|
description: |-
|
|
|
|
Vagrant can use rsync as a mechanism to sync a folder to the guest machine.
|
|
|
|
This synced folder type is useful primarily in situations where other synced
|
|
|
|
folder mechanisms are not available, such as when NFS or VirtualBox shared
|
|
|
|
folders are not available in the guest machine.
|
2014-01-11 02:15:49 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# RSync
|
|
|
|
|
|
|
|
**Synced folder type:** `rsync`
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
Vagrant can use [rsync](https://en.wikipedia.org/wiki/Rsync) as a mechanism
|
2014-01-11 02:15:49 +00:00
|
|
|
to sync a folder to the guest machine. This synced folder type is useful
|
|
|
|
primarily in situations where other synced folder mechanisms are not available,
|
2016-01-19 18:08:53 +00:00
|
|
|
such as when NFS or VirtualBox shared folders are not available in the guest
|
2014-01-11 02:15:49 +00:00
|
|
|
machine.
|
|
|
|
|
|
|
|
The rsync synced folder does a one-time one-way sync from the machine running
|
|
|
|
to the machine being started by Vagrant.
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
The [rsync](/docs/cli/rsync.html) and [rsync-auto](/docs/cli/rsync-auto.html)
|
2014-01-14 17:34:21 +00:00
|
|
|
commands can be used to force a resync and to automatically resync when
|
|
|
|
changes occur in the filesystem. Without running these commands, Vagrant
|
|
|
|
only syncs the folders on `vagrant up` or `vagrant reload`.
|
|
|
|
|
2014-01-11 02:15:49 +00:00
|
|
|
## Prerequisites
|
|
|
|
|
|
|
|
To use the rsync synced folder type, the machine running Vagrant must have
|
|
|
|
`rsync` (or `rsync.exe`) on the path. This executable is expected to behave
|
|
|
|
like the standard rsync tool.
|
|
|
|
|
2014-01-16 05:35:43 +00:00
|
|
|
On Windows, rsync installed with Cygwin or MinGW will be detected by
|
|
|
|
Vagrant and works well.
|
|
|
|
|
2014-02-03 11:14:41 +00:00
|
|
|
The destination machine must also have rsync installed, but Vagrant
|
|
|
|
can automatically install rsync into many operating systems. If Vagrant
|
|
|
|
is unable to automatically install rsync for your operating system,
|
|
|
|
it will tell you.
|
|
|
|
|
2014-11-05 20:43:46 +00:00
|
|
|
The destination folder will be created as the user initiating the connection,
|
2018-02-06 19:20:29 +00:00
|
|
|
this is `vagrant` by default. This user requires the appropriate permissions on
|
2014-11-05 20:43:46 +00:00
|
|
|
the destination folder.
|
|
|
|
|
2014-01-11 02:15:49 +00:00
|
|
|
## Options
|
|
|
|
|
|
|
|
The rsync synced folder type accepts the following options:
|
|
|
|
|
2014-03-13 01:35:57 +00:00
|
|
|
* `rsync__args` (array of strings) - A list of arguments to supply
|
2014-12-04 15:09:04 +00:00
|
|
|
to `rsync`. By default this is `["--verbose", "--archive", "--delete", "-z", "--copy-links"]`.
|
2014-03-06 19:27:58 +00:00
|
|
|
|
2014-03-06 20:18:13 +00:00
|
|
|
* `rsync__auto` (boolean) - If false, then `rsync-auto` will not
|
|
|
|
watch and automatically sync this folder. By default, this is true.
|
|
|
|
|
2014-06-26 21:29:20 +00:00
|
|
|
* `rsync__chown` (boolean) - If false, then the
|
2016-01-19 18:08:53 +00:00
|
|
|
[`owner` and `group`](/docs/synced-folders/basic_usage.html)
|
|
|
|
options for the synced folder are ignored and Vagrant will not execute
|
2014-05-17 19:01:50 +00:00
|
|
|
a recursive `chown`. This defaults to true. This option exists because
|
2014-06-26 21:33:12 +00:00
|
|
|
the `chown` causes issues for some development environments. Note that
|
|
|
|
any `rsync__args` options for ownership **will be overridden** by
|
|
|
|
`rsync__chown`.
|
2014-05-17 19:01:50 +00:00
|
|
|
|
2014-01-11 02:15:49 +00:00
|
|
|
* `rsync__exclude` (string or array of strings) - A list of files or directories
|
|
|
|
to exclude from the sync. The values can be any acceptable rsync exclude
|
|
|
|
pattern. By default, the ".vagrant/" directory is excluded. We recommend
|
|
|
|
excluding revision control directories such as ".git/" as well.
|
|
|
|
|
2015-07-09 16:02:38 +00:00
|
|
|
* `rsync__rsync_path` (string) - The path on the remote host where rsync
|
|
|
|
is and how it is executed. This is platform specific but defaults to
|
|
|
|
"sudo rsync" for many guests.
|
|
|
|
|
2015-01-05 20:36:00 +00:00
|
|
|
* `rsync__verbose` (boolean) - If true, then the output from the rsync
|
2014-11-25 18:38:41 +00:00
|
|
|
process will be echoed to the console. The output of rsync is subject
|
2015-07-09 16:02:38 +00:00
|
|
|
to `rsync__args` of course. By default, this is false.
|
2014-11-25 18:38:41 +00:00
|
|
|
|
2014-01-11 02:15:49 +00:00
|
|
|
## Example
|
|
|
|
|
|
|
|
The following is an example of using RSync to sync a folder:
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
```ruby
|
2014-01-11 02:15:49 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.synced_folder ".", "/vagrant", type: "rsync",
|
|
|
|
rsync__exclude: ".git/"
|
|
|
|
end
|
2016-01-19 18:08:53 +00:00
|
|
|
```
|
2014-11-05 20:43:46 +00:00
|
|
|
|
|
|
|
## Rsync to a restricted folder
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
If required to copy to a destination where `vagrant` user does not have
|
2014-11-05 20:43:46 +00:00
|
|
|
permissions, use `"--rsync-path='sudo rsync'"` to run rsync with sudo on the guest
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
```ruby
|
2014-11-05 20:43:46 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.synced_folder "bin", "/usr/local/bin", type: "rsync",
|
2015-01-15 14:51:04 +00:00
|
|
|
rsync__exclude: ".git/",
|
2014-11-05 20:43:46 +00:00
|
|
|
rsync__args: ["--verbose", "--rsync-path='sudo rsync'", "--archive", "--delete", "-z"]
|
|
|
|
end
|
2016-01-19 18:08:53 +00:00
|
|
|
```
|