Issue. Backing up remote files, directories from a cloud VPS via rsync
over SSH was not maintaining remote owner:group
ownerships on local host.
Solution.
- Create users on local host for files (directories, etc.) rsync'd from remote host.
- Run local host
rsync
command as root
/ sudo
.
- Will have to manually provide root password, SSH passphrase.
# create local host system user(s) for those on remote host; see:
# https://wiki.archlinux.org/title/Users_and_groups#Example_adding_a_system_user
sudo rsync -aqP -e "ssh -p 4321 \ ## SSH port
-i /home/victoria/.ssh/my-vps/id_rsa" \ ## SSH credentials
root@vps1234.my_isp.com:/etc/default/solr.in.sh ## rsync SRC (remote host)
/<my home path>/backups/solr.in.sh \ ## rsync DEST (local host)
Tests.
# -----------------------------------------------------------------------------
# REMOTE HOST (cloud VPS):
[me@vps1234]$ ls -l /etc/default/
...
-rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh ## ownership: root:solr
...
[me@vps1234]$
# -----------------------------------------------------------------------------
# LOCAL HOST:
The basic command for testing (with variations, following) is:
```bash
rm -f solr.in.sh; \
rsync -aqP \
--rsync-path="sudo /bin/rsync" \
-e "ssh -p 4321 \
-i /home/victoria/.ssh/my-vps/id_rsa" \
root@vps1234.my_isp.com:/etc/default/solr.in.sh
/<my home path>/backups/solr.in.sh; \
ls -l solr.in.sh
# -----------------------------------------------------------------------------
# [TEST 1] rsync --rsync-path...
[victoria]$ rm -f solr.in.sh; \
rsync -aqP --rsync-path="sudo /bin/rsync" \
-e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa" \
root@vps1234.my_isp.com:/etc/default/solr.in.sh \
/<my home path>/backups/solr.in.sh; \
ls -l solr.in.sh
-rw-r----- 1 victoria victoria 15079 Aug 12 20:35 solr.in.sh
## victoria victoria [incorrect]
[victoria]$
# -----------------------------------------------------------------------------
# [TEST 2] sudo rsync --rsync-path ; user "solr" not on local host so remote files
# in group "solr" renamed "git" on local host; tried rsync -og options: no effect
[victoria]$ rm -f solr.in.sh; \
sudo rsync -aqP --rsync-path="/usr/bin/rsync" \
-e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa" \
root@vps1234.my_isp.com:/etc/default/solr.in.sh \
/<my home path>/backups/solr.in.sh; \
ls -l solr.in.sh
[sudo] password for victoria:
Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa':
-rw-r----- 1 root git 15079 Aug 12 20:35 solr.in.sh
## root:git [incorrect]
[victoria]$
# -----------------------------------------------------------------------------
# [CONFIGURE USERS]
# local host:
[victoria]$ cat /etc/passwd | grep solr ## no such user
[victoria]$
# Create local host system user, for user on remote host:
[victoria@victoria backups]$ sudo useradd -r -s /usr/bin/nologin solr
[sudo] password for victoria:
[victoria]$ cat /etc/passwd | grep solr
solr:x:980:980::/home/solr:/usr/bin/nologin
[victoria]$ ls -l /home/ ## check: useradd did not create /home/solr/
total 52
drwx------ 2 root root 16384 Mar 6 2015 lost+found
drwxrwxr-x 178 victoria victoria 36864 Aug 13 10:09 victoria
[victoria]$
# -----------------------------------------------------------------------------
# [TEST 3: works] sudo --rsync-path...
[victoria]$ rm -f solr.in.sh; \
sudo rsync -aqP --rsync-path="/bin/rsync" \
-e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa" \
root@vps1234.my_isp.com:/etc/default/solr.in.sh \
/<my home path>/backups/solr.in.sh; \
ls -l solr.in.sh
[sudo] password for victoria:
Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa':
-rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh
## root:solr [correct]
[victoria]$
# -----------------------------------------------------------------------------
# [TEST 4: works] No need for --rsync-path option:
[victoria@victoria backups]$ rm -f solr.in.sh; \
sudo rsync -aqP -e \
"ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa" \
root@vps1234.my_isp.com:/etc/default/solr.in.sh \
/<my home path>/backups/solr.in.sh; \
ls -l solr.in.sh
[sudo] password for victoria:
Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa':
-rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh
## root:solr [correct]
[victoria@victoria backups]$
# -----------------------------------------------------------------------------