0

My first post on here.

I am trying to backup all data files from one server to another. The data can be owned by several users or by reserved nologin users.

I am trying to create a remote mirror of all users files. Ready for restoring at a later date.

I have searched on here and lots of googling but all the solutions involve changing ownership of the file or other fiddles.

I have samba and nfs(export) shares.

The system is 2 raspberry PIs each with several multibay usb drives, so raspbian/debian based.

My best solution so far is:

cat /etc/scripts/backup_data4.sh

if [ -e /mnt/data4_B/B4 ]; then
    printf "There is a B4 marker\n"
    sudo rsync -avz -e ssh /mnt/data4/git /mnt/data4_B/
    sudo rsync -avz -e ssh /mnt/data4/stacking2 /mnt/data4_B/

else
    printf "B4 does not exist\n"
fi

where /mnt/data4_B is a mounted exported drive on backup server.

/etc/exports

/mnt/data1/      192.168.0.160(rw,sync,no_subtree_check)
/mnt/data2/      192.168.0.160(rw,sync,no_subtree_check)
/mnt/data3/      192.168.0.160(rw,sync,no_subtree_check)
/mnt/data4/      192.168.0.160(rw,sync,no_subtree_check)


/mnt/data5/      192.168.0.160(rw,sync,no_subtree_check)
/mnt/data6/      192.168.0.160(rw,sync,no_subtree_check)
/mnt/data7/      192.168.0.160(rw,sync,no_subtree_check)
/mnt/data8/      192.168.0.160(rw,sync,no_subtree_check)

This script does work to a point but I have lots of issues with ownership and permissions on the backup server.

Any suggestions welcome. Thanks.

Extra Added.

user names, UID and GID are identical on both systems.

I can't find any way to use:

 rsync -av fromdir user@server:todir

that can handle multiple users files.

6
  • 1
    What problems have you encountered with ownership and permissions? Note that the user accounts are probably not duplicates on the backup server of the source computer.
    – harrymc
    Commented Jul 5, 2023 at 15:30
  • 1
    Using rsync over nfs is highly not recommended. All your ownership and permission problems caused by this. rsync has its own rsync protocol which is also much-much faster than crawling over nfs. Commented Jul 5, 2023 at 15:35
  • "What problems have you encountered with ownership and permissions? Note that the user accounts are probably not duplicates on the backup server of the source computer. " The file ownership and permissions can be different to the original server. The user names UID and GID are identical on both servers.
    – nobody
    Commented Jul 5, 2023 at 17:09
  • 1
    "Using rsync over nfs is highly not recommended. All your ownership and permission problems caused by this. rsync has its own rsync protocol which is also much-much faster than crawling over nfs." Good point but I can't find any way to use rsync -av fromdir user@server:todir that can handle multiple users files.
    – nobody
    Commented Jul 5, 2023 at 17:15
  • Sorry for comment layout, still looking for quote option.
    – nobody
    Commented Jul 5, 2023 at 17:15

3 Answers 3

0

If data4_B is a mounted NFS share root can just copy everything preserving ownership and attributes, only root can do that for other users:
sudo cp -a /mnt/data4/git /mnt/data4_B/

rsync can do that as well using only ssh without mounted shares but you first need to make sure root can log in via ssh on the remote machine. So fist do a ssh-copy-id from the one root account to the other. Then your rsync -av fromdir user@server:todir will work if user can log in.

The -e you wrote about is used like so:
sudo rsync -e "ssh -p 22 -l root" -av /mnt/data4/git "host.example.com:/mnt/data4_B"

1
  • Your command can be simplified to omit the -e part: sudo rsync -av /mnt/data4/git [email protected]:/mnt/data4_B Commented Aug 27, 2023 at 14:18
0

The main one you may be missing is -A or --acls to include file ACLs, which rsync excludes by default. I use the flags below for backing up with permissions.

# copy data over, ignoring mount points, sparse files, etc:
# -A should include --acls (check it though)
# [optional] -S sparse, -H hard-links, -x don't follow mounts, -v verbose
# -a (archive) includes -r/l/p/t/g/o/D 

rsync -SHAxa /mnt/some/folder/ /mnt/backups/

Additionally, you should not need to use -e ssh when /mnt/data4/git and /mnt/data4_B/ are both "local" paths

2
  • Yes -e ssh as in the question means log in to localhost via ssh. Then the receiving rsync is not run via sudo as root but as the normal user. And it takes longer because the network stack is involved.
    – xenoson
    Commented Jul 5, 2023 at 18:22
  • No it doesn't, @xenoson; it tells the rsync command to use ssh IF you specify a remote host path as source or destination. You don't, so the option is ignored Commented Aug 27, 2023 at 14:16
0

Thanks for all the suggestions, they led me to a solution.

The issue was that only the file owner can set/change the ownership of the nfs file or directory.

I still don't understand why root can't change ownership of the mounted remote drive.

I also had a samba mis-configuration that caused many files to have the wrong user. I removed all use of admin user from the config file.

My final solution was to run the backup script on the backup server pulling the files from the master server.

sudo rsync -avx /mnt/data4_A/git /mnt/data4/

where data4_A is the remote nfs drive on server A and data4 is the local disk in the backup server B.

Thank for all your help.

1
  • Root cannot change the ownership of an NFS-mounted file by design. This can be overridden with the no_root_squash option (or even no_all_squash) in the /etc/exports file on the NFS Server. (The feature comes from a time when users would typically have root access on their own workstation, and you wouldn't want users to be able to override other people's permissions and ownerships on an NFS-shared filesystem.) Commented Aug 27, 2023 at 14:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .