Philipp Michael
Philipp Michael

Reputation: 954

How to change owner or group when syncing with rsync in vagrant box?

Currently I'm struggling with permission issues in my Drupal installation on a Drupal-VM (Vagrant + Virtual Box on Windows). I'm syncing with rsync which leads to owner and group vagrant of synced files and folders. Because apache is running with user www-data files cannot be written in in the public temp folder sites/default/files, which is owned by vagrant:vagrant. That's why I'm trying to change the group of synced files to www-data. How do I accomplish this?

My Environment

Vagrant 1.9.1
VirtualBox 5.1.14 r112924

My OS

Microsoft Windows [Version 10.0.14393]

Summary

I've already tried the following settings in config.yml:

vagrant_synced_folders: - local_path: C:\#\myproject destination: /var/www/myproject.dev type: rsync create: true options_override: group: www-data

or

vagrant_synced_folders: - local_path: C:\#\myproject destination: /var/www/myproject.dev type: rsync create: true group: www-data

These don't take effect after vagrant reload. When I check .vagrant/machines/mydrupalvmbox/virtualbox/syncedfolders group is still vagrant. Changing the group in this temp file and doing a vagrant rsync results the correct group for rsynced files and directories. But after vagrant reload those temp settings are gone and group vagrant is back again.

I've also tried to change the group via rsync_args with no success:

vagrant_synced_folders: - local_path: C:\#\myproject destination: /var/www/myproject.dev type: rsync create: true options_override: rsync__args: [ "--verbose", "--archive", "--delete", "--chmod=gu=rwX,o=rX", "--group", # required for the following command "--groupmap=*:www-data" ]

I get an error: Error: rsync: --groupmap=*:www-data: unknown option.

So what's the right setting?

Upvotes: 0

Views: 2460

Answers (2)

Philipp Michael
Philipp Michael

Reputation: 954

In Drupal VM you have to use rsync__group inside of options_override:

vagrant_synced_folders:
  - local_path: C:\#\myproject
  // [...]
  options_override:
    rsync__group: www-data

See related issue: https://github.com/geerlingguy/drupal-vm/issues/1199

This might work in other vagrant boxes too.

Upvotes: 0

Frederic Henri
Frederic Henri

Reputation: 53713

which version of rsync are you running ?

The groupmap option has been included in version 3.1.0 (see https://rsync.samba.org/ftp/rsync/src/rsync-3.1.0-NEWS)

- Added the --usermap/--groupmap/--chown options for manipulating file
  ownership during the copy.

upgrade your rsync version (if you're using cygwing, upgrade cygwin/rsync) and make sure you get an up-to-date version

rsync --version

Upvotes: 1

Related Questions