How to correctly restore backup config directory with changed file permissions

Hi, I am trying to restore a backup that I created following this guide with the command
rsync -Aavx nextcloud/ nextcloud-dirbkp/ .
I had to reinstall nextcloud and now want to restore my backup with the command
rsync -Aax nextcloud-dirbkp/ nextcloud/
but the file permissions of my backup got changed in the process. Does someone know how to set them correctly? I am using an apache webserver.

I tried chown -R apache:apache /var/www/localhost/htdocs/nextcloud but that did not help.

Nextcloud version (eg, 18.0.2): 20.0.4
Operating system and version (eg, Ubuntu 20.04): 5.9.9-gentoo
Apache or nginx version (eg, Apache 2.4.25): 2.4.46-r4
PHP version (eg, 7.1): 8.0.0

Steps to replicate it:

  1. Mess up your file permissions

try www-data:www-data insetad od “apache”.

hmm I have no user www-data. But my data directory always had the permissions apache:apache and that worked fine

To find out what user/group apache is actually running on, you could use apachectl

apachectl -S | grep 'User:\|Group:'

or look at the running processes…

ps aux | egrep '(apache|httpd)'

Hi @bb77, thanks for your answer. ps aux | egrep '(apache|httpd)' gives me this:

root     12032  0.0  0.1 437384 26000 ?        Ss   Jan01   0:13 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12034  0.0  0.0  73688  5096 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12035  0.0  0.4 465652 65168 ?        S    Jan01   0:01 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12036  0.0  0.4 465448 67844 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12037  0.0  0.3 465440 63848 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12038  0.0  0.3 465440 64084 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12039  0.0  0.3 465440 64336 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12049  0.0  0.3 465448 59836 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12052  0.0  0.4 465656 65388 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12053  0.0  0.4 465656 70660 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12054  0.0  0.4 465396 65584 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   12055  0.0  0.4 465656 65724 ?        S    Jan01   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start

so I guess apache is running both under root and apache?

it’s running as apache. Root is only the initial starter of the service in order to do things like bind to reserved ports (80/443) etc… Anyways, That is definitely not the default user for apache2 on Ubuntu.

what does apachectl -S give you? For me it’s…

User: name="www-data" id=33
Group: name="www-data" id=33

…right at the end of the output.

Or you can grep it with:

apachectl -S | grep 'User:\|Group:'

command must run with root privileges.

hmm apachectl gives me “command not found”, but in my /etc/apache2/httpd.conf file I have:

User apache
Group apache

would changing the user apache is running on to www-data help me solve my issue, or solve any other issues?

nope sorry… I didn’t look right and tought you are using Ubuntu. On Gentoo the apache user is indeed apache.

okay thanks anyways for your help :slight_smile: