LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How rsync works (https://www.linuxquestions.org/questions/linux-software-2/how-rsync-works-4175480688/)

alaios 10-14-2013 03:37 AM

How rsync works
 
Hi all,
I would like to ask your help as I try to understand how rsync works.
I was syncing some files to an external hard disk ($MOUNTPOINT) with the following line (runs through crontab)


Code:

rsync -rav -e ssh lka@server:/storage/disk1/ $MOUNTPOINT
I have found one day that the hard disk on the remote server lka@server:/storage/disk1/ was unmounted so the folder /storage/disk1 was showing an empty folder.

I then checked my files on my external hard disk ($MOUNTPOINT) and all the files were still there. I was expecting (and luckily that did not happen) rsync to sync the empty folder to the external hard disk ($MOUNTPOINT). Of course that would mean "deleting" the files ...

Can someone explain me why this did not happen?

I would like to thank you in advance for your reply

Regards
Alex

pan64 10-14-2013 04:12 AM

there are a few options to rule how and when should rsync delete those files, see man page and --delete* options
(you are lucky because the default is to avoid deleting files)

zhjim 10-14-2013 04:13 AM

There is an option to rsync to also delete files (--delete). If that is not given rsync only copies files from source to destination. So if there are no source files nothing gets copied. There is also an option to reverse delete so files that are not on destination are deleted on the source side.

I'd just say you give the man page a read. Its quite long so maybe read it once for an overview and a second time for each option there is.

JJJCR 10-14-2013 05:03 AM

check out this link: https://calomel.org/rsync_tips.html

from link above:
Quote:

Using rsync instead of copy (cp)

rsync -av /usbdisk/ /localdisk/
Quote:

Using rsync over ssh instead of scp
rsync -avz /usbdisk/ calomel@somemachine:/backups/

rsync -avz --del /usbdisk/ calomel@somemachine:/backups/
Quote:

Rsync recursive copy with parent directory name
rsync -avz /usbdisk calomel@somemachine:/backups/

rsync -avz /data1 /data2 calomel@somemachine:/backups/
Quote:

Rsync pull instead of push

rsync -avz calomel@somemachine:/backups/ /usbdisk/
Quote:

Pull multiple files with rsync
rsync -avz calomel@somemachine:/remote_machine/{file1,file2,file3} /local/disk/
Quote:

Rsync when remote files or directories contain spaces
rsync -av calomel@somemachine:'/I\ Hate\ Spaces/some\ File.avi' /current_dir/
Quote:

Execute remote shell command to rsync files
rsync -avR calomel@somemachine:'`find /data/video -name "*.[avi]"`' /download/
Quote:

Pull data from a remote machine to local server using ssh
rsync -avx --timeout=30 --delete-excluded backupuser@remote_machine:/stuff/data/ /BACKUP/remote_machine/

rsync -Ravx --timeout=30 --delete-excluded backupuser@remote_machine:/stuff/data/ /BACKUP/remote_machine/
Quote:

Incremental backups using rsync
rsync --backup --backup-dir=`date +%Y.%m.%d` -a /data/working/ /BACKUP/


All times are GMT -5. The time now is 08:45 AM.