Author Topic: <SOLVED>Restore root partition with rsync--naming problem  (Read 786 times)

Offline barryc

  • Sr. Member
  • ****
  • Posts: 321
<SOLVED>Restore root partition with rsync--naming problem
« on: June 07, 2012, 11:24:15 AM »
Now that I got my hard drives sorted, I followed Old-Polack's beautiful
instructions from another post for backing up my system using rsync.
Here are O-P's crystal-clear directions:
Quote
You would want to do the copying from either a root login, or from the liveCD, logged in as root. I recommend the latter. If you have a separate /home partition, you need to know beforehand which partition that is, and also the partition on which you wish to store the copied directory. It is always best to have the backup partition formatted with an ext3 or ext4 filesystem (whichever is the same as the /home partition) so that permissions for all the files and directories are properly preserved.

Example:

Assuming the /home partition to be /dev/sda5 and the backup partition to be /dev/sdb1, if done from a liveCD, the first things you would need are mount point directories. I like /here and /there as they are short, and only exist in memory as part of the liveCD directory tree anyway. We use the mkdir command for this. (make directory)

[root@localhost ~]# mkdir /here /there                <Enter>

Now we mount the /home partition on /here and the backup partition on /there.

[root@localhost ~]# mount /dev/sda5 /here             <Enter>

[root@localhost ~]# mount /dev/sdb1 /there             <Enter>

To check the mounts;

[root@localhost ~]# ls -l /here             <Enter>

[root@localhost ~]# ls -l /there             <Enter>

The first command should show your ray directory, and the second command whatever is already on the backup partition, if anything.

To copy the entire ray directory as well as all its contents;

[root@localhost ~]# rsync -av /here/ray /there             <Enter>

You will see a lot of text lines describing what is being copied, as it happens. When the process is complete you will be returned to the root prompt.

To check the copy;

[root@localhost ~]# ls -la /there/ray             <Enter>

You could also navigate to the /there/ray directory with Dolphin, or whatever file manager is on the liveCD, and look around to see if everything looks normal and complete. If all looks good, you have your backup.
   Report to moderator   Logged
Old-Polack

In my case, I first backed up my home partition (same device mounts as above).

[root@localhost ~]# rsync -av /here/barry /there             <Enter>

This saved my home partition onto my sdb1 drive in a directory named barry

Sweet!
Next, I mounted my root partition:

[root@localhost ~]# mount /dev/sda1 /here             <Enter>

I next did the same operation to back up my root folder with the following command:

[root@localhost ~]# rsync -av /here /there      <Enter>

This created a directory named 'here' on my sdb1 drive and saved all the root folder files to that directory.
I now have two new folders on my sdb1 drive -- 'barry' (home) and 'here' (root dir).

Now, I'm getting confused about how to handle the reverse operation to restore the files
if the system gets borked.  Not sure whether I'm 'here' or 'there'.   :)

Should I have named the root partition in the rsync command to /here/root or /here/root/ as the source?

Is renaming the 'here' directory on my sdb1 drive to 'root' a good idea to avoid confusion?  With, or
without a trailing slash?  And what would be the proper parsing of the rsync command for the root
folder?

As far as the actual backups, they worked flawlessly and super fast, error-free.

What is your suggestion for the restore operation using rsync?







« Last Edit: June 07, 2012, 05:15:49 PM by barryc »
You gotta have balls to play golf.

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11528
  • ----IOFLU----
Re: Restore root partition with rsync--naming problem
« Reply #1 on: June 07, 2012, 01:58:41 PM »
Now that I got my hard drives sorted, I followed Old-Polack's beautiful
instructions from another post for backing up my system using rsync.
Here are O-P's crystal-clear directions:
Quote
You would want to do the copying from either a root login, or from the liveCD, logged in as root. I recommend the latter. If you have a separate /home partition, you need to know beforehand which partition that is, and also the partition on which you wish to store the copied directory. It is always best to have the backup partition formatted with an ext3 or ext4 filesystem (whichever is the same as the /home partition) so that permissions for all the files and directories are properly preserved.

Example:

Assuming the /home partition to be /dev/sda5 and the backup partition to be /dev/sdb1, if done from a liveCD, the first things you would need are mount point directories. I like /here and /there as they are short, and only exist in memory as part of the liveCD directory tree anyway. We use the mkdir command for this. (make directory)

[root@localhost ~]# mkdir /here /there                <Enter>

Now we mount the /home partition on /here and the backup partition on /there.

[root@localhost ~]# mount /dev/sda5 /here             <Enter>

[root@localhost ~]# mount /dev/sdb1 /there             <Enter>

To check the mounts;

[root@localhost ~]# ls -l /here             <Enter>

[root@localhost ~]# ls -l /there             <Enter>

The first command should show your ray directory, and the second command whatever is already on the backup partition, if anything.

To copy the entire ray directory as well as all its contents;

[root@localhost ~]# rsync -av /here/ray /there             <Enter>

You will see a lot of text lines describing what is being copied, as it happens. When the process is complete you will be returned to the root prompt.

To check the copy;

[root@localhost ~]# ls -la /there/ray             <Enter>

You could also navigate to the /there/ray directory with Dolphin, or whatever file manager is on the liveCD, and look around to see if everything looks normal and complete. If all looks good, you have your backup.
   Report to moderator   Logged
Old-Polack

In my case, I first backed up my home partition (same device mounts as above).

[root@localhost ~]# rsync -av /here/barry /there             <Enter>

This saved my home partition onto my sdb1 drive in a directory named barry

Sweet!
Next, I mounted my root partition:

[root@localhost ~]# mount /dev/sda1 /here             <Enter>

I next did the same operation to back up my root folder with the following command:

[root@localhost ~]# rsync -av /here /there      <Enter>

This created a directory named 'here' on my sdb1 drive and saved all the root folder files to that directory.
I now have two new folders on my sdb1 drive -- 'barry' (home) and 'here' (root dir).

Now, I'm getting confused about how to handle the reverse operation to restore the files
if the system gets borked.  Not sure whether I'm 'here' or 'there'.   :)

Should I have named the root partition in the rsync command to /here/root or /here/root/ as the source?

Is renaming the 'here' directory on my sdb1 drive to 'root' a good idea to avoid confusion?  With, or
without a trailing slash?  And what would be the proper parsing of the rsync command for the root
folder?

As far as the actual backups, they worked flawlessly and super fast, error-free.

What is your suggestion for the restore operation using rsync?


When I backup, because I have many different installations, I use a directory named for the actual installation as the receiving directory. This installation has the / partition LABEL test64, so that would be the name used for the receiving directory.

[root@fatman ~]# blkid |grep sdc5
/dev/sdc5: LABEL="test64" UUID="262d9c60-a7d8-414d-9c68-bc91fe029a58" TYPE="ext4"

The backup command, with the / partition being backed up mounted on /here, and the backup partition mounted on /there, would be;

[root@localhost ~]# rsync -av /here/ /there/test64                             <Enter>

When using the backup to restore, I would mount the backup partition on /here and the receiving partition on /there, then the command would use the trailing / to copy just the contents of the test64 directory, and not the directory itself.

[root@localhost ~]# rsync -av /here/test64/ /there                             <Enter>

You could rename your here directory, on the backup partition, to root or anything else that would tell you exactly what it contained, when referenced later. Use the trailing / when restoring, as shown above.
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline barryc

  • Sr. Member
  • ****
  • Posts: 321
Re: Restore root partition with rsync--naming problem
« Reply #2 on: June 07, 2012, 03:45:32 PM »
O-P
Thanks for the quick response.  Still not sure if I understand clearly.
Let me walk through it and see if this makes sense.

Quote
When I backup, because I have many different installations, I use a directory named for the actual installation as the receiving directory. This installation has the / partition LABEL test64, so that would be the name used for the receiving directory.

Okay.  My real root directory is /dev/sda1 mounted on /  LABEL=pclinuxos
My backup partition is /dev/sdb1 LABEL=archives.

So, to follow your routine, to backup my root directory, I would first mount /dev/sda1 on /here.
I would then mount /dev/sdb1 on /there.

check mounts and then backup the root drive to the archives partition with the following command:

[root@localhost ~]# rsync -av /here /there/pclinuxos      <Enter>

To restore the root directory from my backup I would first mount /dev/sdb1 to /here
And mount /dev/sda1 to /there

Check mounts.

Then restore with the following command:

[root@localhost ~]# rsync -av /here/pclinuxos/ /there      <Enter>  (note trailing / after pclinuxos)

I think that makes sense but I just wanted to make sure I clearly understood.
Assuming this is correct, when I update the archives with rsync, it will back up the files incrementally and skip the files where there are no changes.

Thanks for your patience.


You gotta have balls to play golf.

Offline kjpetrie

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3979
Re: Restore root partition with rsync--naming problem
« Reply #3 on: June 07, 2012, 04:07:05 PM »
You're missing the trailing '/' (see O-P's colour coding). Without it, rsync treats the directory as a file and copies it and its contents. With it, rsync treats it as a directory and just copies its contents. The trailing '/' also matters on the receiving directory. Experiment is the best way to find out about this.
« Last Edit: June 07, 2012, 04:08:42 PM by kjpetrie »
-----------
KJP
-----------------------------------------------------------
PClos64 RC1 on Intel D945GCLF2 motherboard (Atom 330), 2GB DDR2 RAM, Maxtor STM325031, HL-DT-ST DVDRAM GSA-H42N, Amilo LSL 3220T monitor. Also Acer 5810TG (with custom kernel) and Asus eeePC 2G surf

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11528
  • ----IOFLU----
Re: Restore root partition with rsync--naming problem
« Reply #4 on: June 07, 2012, 04:24:00 PM »
O-P
Thanks for the quick response.  Still not sure if I understand clearly.
Let me walk through it and see if this makes sense.

Quote
When I backup, because I have many different installations, I use a directory named for the actual installation as the receiving directory. This installation has the / partition LABEL test64, so that would be the name used for the receiving directory.

Okay.  My real root directory is /dev/sda1 mounted on /  LABEL=pclinuxos
My backup partition is /dev/sdb1 LABEL=archives.

So, to follow your routine, to backup my root directory, I would first mount /dev/sda1 on /here.
I would then mount /dev/sdb1 on /there.

check mounts and then backup the root drive to the archives partition with the following command:

[root@localhost ~]# rsync -av /here /there/pclinuxos      <Enter>

To restore the root directory from my backup I would first mount /dev/sdb1 to /here
And mount /dev/sda1 to /there

Check mounts.

Then restore with the following command:

[root@localhost ~]# rsync -av /here/pclinuxos/ /there      <Enter>  (note trailing / after pclinuxos)

I think that makes sense but I just wanted to make sure I clearly understood.
Assuming this is correct, when I update the archives with rsync, it will back up the files incrementally and skip the files where there are no changes.

Thanks for your patience.


This line;

[root@localhost ~]# rsync -av /here /there/pclinuxos      <Enter>

...is lacking the trailing / after /here, so would end up with a directory named here inside the /there/pclinuxos directory. (/there/pclinuxos/here/<contents of here>)
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline barryc

  • Sr. Member
  • ****
  • Posts: 321
Re: Restore root partition with rsync--naming problem
« Reply #5 on: June 07, 2012, 05:14:54 PM »
Thanks guys.  I knew I'd miss a slash somewhere.
It's sinking in, I think.  Here's the correct parsing for backing up:

[root@localhost ~]# rsync -av /here/ /there/pclinuxos      <Enter>
(note trailing / after /here)


and.. the command for restoring the root files:

[root@localhost ~]# rsync -av /here/pclinuxos/ /there      <Enter>  (note trailing / after pclinuxos)

I will definitely save this and print it so I can keep the slashes straight.
Thanks again and I will mark this one <SOLVED>
You gotta have balls to play golf.