1

I am quite new to using rsync and I'm wondering if it is possible to rsync files across multiple user accounts on a single PC?

For the computers I want to apply the rsync command to, each user has to individually log in to their own user account.For example, if there are 20 users, there are 20 user accounts on that one PC. Is there a way to use rsync from the root account to access the directories and files of each user? I would only like to grab files in .csv format.

Thanks!

kennycodes
  • 111
  • 1

2 Answers2

1

Is there a way to use rsync from the root account to access the directories and files of each user? I would only like to grab files in .csv format.

This command will backup everything in /home and save it to the remote host under /path/to/backup. It will retain users' ownerships and permissions provided the remote filesystem is capable of doing so

rsync -av /home remoteHost:/path/to/backup/

If you don't have root access on the remote system you should add the -M--fake-super option to backup file metadata (ownerships and permissions) in a way that doesn't need root access. Make sure that if you use this flag, you also use it for restores.

The second part of your question is a duplicate of Rsync filter: copying one pattern only. To limit the copy just to .csv files you can use this

rsync -av --prune-empty-dirs --include='*/' --include='*.csv' --exclude='*' /home remoteHost:/path/to/backup/
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
0

In general, yes. The problem you're going to run into is authentication. You can, for instance, run an rsync script from cron. Make yourself a shell script. If the source and destination are on the local computer, root works.

If the source or destination is remote, it's a much harder task. The easiest way is to bypass the issue --- use NFS to mount the remote disk on the local computer. You can also lookup ssh authentication... that's a rabbit hole for you to research

OK. Assume /root/backupuserlist is a list of users, one per line and /backupdrive is where you're backing them up.

#!/bin/bash
# backup /root/backupuserlist to /backupdrive

BK_USERS=cat /root/backupuserlist BK_DRIVE=/backupdrive

for user in $BK_USERS; do rsync -av ~$user/ $BK_DRIVE/$user/ done

crate /root/backuserlist, and then run this as root... or put it in root's crontab or /etc/crontab ... you get the drift.

zBeeble
  • 166