Page 1 of 3

Use RSYNC to copy changes in sda to sdb -- [*SOLVED*]

Posted: 12. Sep 2010, 05:57
by Dennola4
I have a question about using rsync. I have read the man pages, I have Googled, but I still don't feel like I get it. So here goes:

I have two identical HDD's (WD800BEVE). The first one (sda) was automatically formatted and partitioned by Salix OS during install. It is the one that is currently in my laptop. The second HDD (sdb) was blank -- I know because I wrote zeroes over the entire disk. I attached it to my laptop via enclosure, went init 3, and used the following command to make it a bootable identical copy of sda:

Code: Select all

# dd if=/dev/sda of=/dev/sdb bs=10M& pid=$!
and to watch it:

Code: Select all

# watch -n5 "kill -USR1 $pid"
So now I have two bootable, identical HDD's with Salix OS (and all of my personal files) on them. Yay. My next step was to download Grsync from the repo and try using it to back up differences between sda (source) and sdb (destination). It worked fine for /home/dennis but obviously not for any changes made to top-level directories. I guess this means I am going to have to learn to use rsync as superuser.

So now my question. Considering this:

Code: Select all

dennis[~]$ cd /
dennis[/]$ ls
bin   dev  home  lost+found  mnt  proc	sbin  sys  usr
boot  etc  lib	 media	     opt  root	srv   tmp  var
dennis[/]$ cd media/disk/
dennis[disk]$ ls
bin   dev  home  lost+found  mnt  proc	sbin  sys  usr
boot  etc  lib	 media	     opt  root	srv   tmp  var
Would running the following command result in changing the entire root directory on sdb recursively so that it both looks and operates identically to that of sda?

Code: Select all

rsync -r -t -p -o -g -v -i --progress --delete -l -H -s / /media/disk/
Thanks in advance for your thoughts on this.

:!: :!: :!:

Re: Use RSYNC to copy changes in sda (source) to sdb (dest)

Posted: 12. Sep 2010, 09:34
by Shador
I can't tell you whether it works in the way you want. But first of all you can use grsync also as root:

Code: Select all

gksu grsync
If you want to use that rsync command I recommend you set up some test directories and first try whether it behaves in the way you want it to behave with those test files. Then once you're satisfied run it on the real data and track it for some time more closely to find possibly still existent problems as early as possible.
If you want to have an identical copy I recommend you use '-a' archive mode, which is a collection of other options like -r, -t.
Don't use -H, you can't preserve hard links when the files are on two different disks or even two different partitions/filesystems.
I recommend you use also -x one filesystem to make rsync really only sync your root filesystem.

Re: Use RSYNC to copy changes in sda (source) to sdb (dest)

Posted: 12. Sep 2010, 10:12
by thenktor

Code: Select all

rsync -av / /media/disk/
But you will have problems with /dev and /proc

Re: Use RSYNC to copy changes in sda (source) to sdb (dest)

Posted: 12. Sep 2010, 12:19
by Akuna
thenktor wrote:

Code: Select all

rsync -av / /media/disk/
But you will have problems with /dev and /proc
What about something like:

Code: Select all

rsync -av --exclude=/dev --exclude=/proc / /media/disk

Re: Use RSYNC to copy changes in sda (source) to sdb (dest)

Posted: 12. Sep 2010, 13:52
by thenktor
Akuna: yep ;)

Re: Use RSYNC to copy changes in sda (source) to sdb (dest)

Posted: 12. Sep 2010, 14:37
by Dennola4
This is all very good information. I put that rsync command together by doing a dry-run of Grsync from a terminal and copying the command. I didn't realize, however, that:

1) "archive" does the same job as combining other options such as -r and -t (etc),
2) copying hard and soft links as such would result in links pointing to invalid or nonexistent targets,
3) gksu grsync runs Grsync as superuser.

So thanks for the lesson(s). I will try:

Code: Select all

rsync -av --exclude=/dev --exclude=/proc / /media/disk
Thank you Shador, theknor and akuna.

:)

Re: Use RSYNC to copy changes in sda to sdb -- [SOLVED]

Posted: 12. Sep 2010, 14:48
by Shador
thenktor wrote:But you will have problems with /dev and /proc
That's why I mentioned -x one filesystem. It would exclude a whole bunch of those problematic directories. BTW isn't /dev in fact also an in-memory filesystem?
Dennola4 wrote:2) copying hard and soft links as such would result in links pointing to invalid or nonexistent targets,
Copying soft links should usually be fine, when copying a whole system.

Soft links/ symlinks are in fact just files which contain a path. So it's up to the application to handle them.

Hard links are at filesystem level. To understand how they work you have to think about your filesystem as a book. The index of a book contains chapters, the index of the filesystem contains files. The data of the files is stored in the "pages of the book". So the entry for the file in the index is just a reference. When using hardlinks there are just two entries in the index which refer to the same "pages".
So two or more files which point at the same data. But this only works as long as the files are on the same filesystem i.e. not in a different "book".

I hope that makes it more clear.

Re: Use RSYNC to copy changes in sda to sdb -- [SOLVED]

Posted: 12. Sep 2010, 15:20
by Dennola4
Shador,

thank you for the filesystem/book analogy -- it clears things up a bit for me. Not to confuse things (since I have marked this post SOLVED already) but are you suggesting that I can or should add <-x> to the command suggested by theknor and akuna:

Code: Select all

rsync -av --exclude=/dev --exclude=/proc / /media/disk
...so that it reads:

Code: Select all

rsync -avx --exclude=/dev --exclude=/proc / /media/disk
:?: :?:

EDIT: I just realized that running rsync in archive mode (-a) automatically preserves soft links.

Re: Use RSYNC to copy changes in sda to sdb -- [SOLVED]

Posted: 12. Sep 2010, 15:30
by Shador
Dennola4 wrote:EDIT: I just realized that running rsync in archive mode (-a) automatically preserves soft links.
Yes, and that should be ok in your case.
Dennola4 wrote:but are you suggesting that I can or should add <-x> to the command suggested by theknor and akuna:
You may want to. It just tells rsync to only copy files from the filesystem mounted on / and not from other filesystems mounted below / (i.e. it only copies files from your root partition).

Re: Use RSYNC to copy changes in sda to sdb -- [SOLVED]

Posted: 12. Sep 2010, 19:54
by Dennola4
.

Excellent. Will do, and thanks again.

.