1

I'm using rsync to back up a set of files in /etc. The 'source' files are on an ext4 filesystem, and the 'destination' is an ext4 partition on a USB thumb drive. My incantation is similar to this:

rsync -av --recursive --files-from=my/etcfiles /etc ./my/backup/etc/

Not unexpectedly, I get errors with this including:

rsync: failed to set times on "/my/backup/etc/somefile": Operation not permitted (1)  
rsync: mkstemp "/my/backup/etc/somefile.erGL4a" failed: Permission denied (13)  
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]  

I think this is because the a option in rsync preserves ownership (root) of the files I'm backing up, and so root privileges are required to complete rsync's operations.

This rsync operation completes successfully when run under sudo, but I need to set this up as a cron job, and using sudo in a crontab brings an issue (password storage) I'd like to avoid.

Another possibility may be changing ownership of the root-owned files (using the chown=USER:GROUP option) during the rsync backup. I've not tried that because it occurs to me that, even if it works without sudo, the ownership would have to be restored if the backups were ever needed.

I've been stewing over this for the better part of a day now, and growing weary of wrangling with rsync's myriad options. So - My question is this:

How can I avoid using sudo to make backups of files in /etc without committing an even worse bodge?

1 Answer 1

4

Set up a root cron job and then the script will run as root anyways. To access the root crontab, run sudo crontab -e.

1
  • I'm selecting this as the correct answer. I had hoped the use of sudo could be avoided entirely, but no answers have emerged to reflect that.
    – Seamus
    Feb 3, 2020 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.