<div class="gmail_quote">On 7 December 2010 23:09, William Muriithi <span dir="ltr"><<a href="mailto:william.muriithi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">william.muriithi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">><br>
> On Tue, Dec 7, 2010 at 3:02 PM, teddy mills <<a href="mailto:teddymills-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">teddymills-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>> wrote:<br>
>><br>
>> I rsync from /home/teddy/ to an external USB hard disk. It works fine.<br>
>><br>
>> rsync -avz --delete --exclude-from '/home/teddy/rsync-exclude' /home/teddy<br>
>> /media/backup<br>
<br>
</div>The --delete flag is really dangerous.  If it was not for the -v flag,<br>
you would have lost all your data.<br></blockquote><div><br>The --delete flag is not that dangerous and in this case it was doing exactly what it was told to do.  There is an undocumented feature, if you will, of rsync for the source and destination paths having a trailing slash or not.  For the destination path, the presence or not of a trailing slash is completely ignored and does not affect rsync in any way.  It's on the source that matters.  If the source doesn't have the trailing slash, the directory is copied along with it's contents to the destination.  For example, if your source is /home/jason and your destination is /mnt/backups then after running rsync you will have /mnt/backups/jason.  <br>
<br>If you run rsync with a trailing slash on the source path, however, then rsync will copy only the <b>contents</b> of the source directory to the destination.  So in our above example, the contents of /home/jason would be copied to /mnt/backups.<br>
<br>The reason rsync started deleting everything is because you told it to copy the contents of /home/teddy to /media/backup.  Since previous rsyncs have been without a trailing slash on /home/teddy, what you have on your external disks is /media/backup/teddy like William Park said earlier in the thread.  When you added the trailing slash on /home/teddy/, rsync looked at /media/backup, saw that there was no teddy folder in your source, and deleted it from the destination.  If you had let rsync complete it would have recopied the contents of /home/teddy back onto the external drive, into the /media/backup folder, without the teddy subfolder.  Basically a move.<br>
<br>It's kind of funny, I was just writing a bash script today at work to backup a subversion repository, and have been reading up on rsync.  Check out <a href="http://www.mikerubel.org/computers/rsync_snapshots/">http://www.mikerubel.org/computers/rsync_snapshots/</a> for some interesting ways of using rsync for hourly/daily/weekly/etc. backups.<br>
<br><br>Oh, this is my first post to the list.  Hi!<br><br><br>Cheers,<br>Jason Chris Nicolaides<br></div></div><br>