rsync preserve attributes, permissions/ownership and times without being root non-root user

One of the purposes of rsync is to backup whole filesystems and archive them but how can you do that properly and restore things to normal if all permissions and ownerships are not preserved from your root filesystem?

It's not desirable to have everything running as root, especially not just for an rsync.

The Easy rsync preserve permission solution for non-root users

sudo is the answer and all you have to do is edit /etc/sudoers

At the end of the file add a line like below (on both source and all target rsync systems).

*Replace "username" with your actual username of course

username  ALL = NOPASSWD: /usr/bin/rsync

The "NOPASSWD" part does as you'd expect, it allows you to sudo to the rsync command without requiring any password, otherwise it would be impossible to script this process and would make rsync useless for automated backups.

Make sure you add the following when running your rsync backup:

--rsync-path="sudo rsync"

That flag ensures that the ownership and permissions can be preserved even as root on the target system for your non-root user.

Also remember on the source systems to always run rsync with sudo

Eg.

sudo rsync -Pha --rsync-path="sudo rsync" --ignore-errors --exclude=/media  --exclude=/proc/* --exclude=/sys/* / user@destination:/location/
 


Tags:

rsync, preserve, attributes, permissions, ownership, userone, purposes, filesystems, archive, restore, ownerships, preserved, filesystem, desirable, users, sudo, edit, etc, sudoers, quot, username, nopasswd, usr, bin, allows, requiring, password, automated, backups, ensures, user, eg, pha, errors, exclude, proc, sys, destination,

Latest Articles

  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution
  • Ubuntu Linux Mint Debian Redhat Youtube Cannot Play HD or 4K videos, dropped frames or high CPU usage with Nvidia or AMD Driver
  • hostapd example configuration for high speed AC on 5GHz using WPA2
  • hostapd how to enable and use WPS to connect wireless devices like printers
  • Dell Server Workstation iDRAC Dead after Firmware Update Solution R720, R320, R730
  • Cloned VM/Server/Computer in Linux won't boot and goes to initramfs busybox Solution
  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm
  • docker swarm silly issues
  • isc-dhcp-server dhcpd how to get longer lease
  • nvidia cannot resume from sleep Comm: nvidia-sleep.sh Tainted: Linux Ubuntu Mint Debian
  • zfs and LUKS how to recover in Linux
  • [error] (28)No space left on device: Cannot create SSLMutex Apache Solution Linux CentOS Ubuntu Debian Mint