Ubuntu – Best Way to Clone a Running System with Rsync

bootrsyncUbuntuubuntu 12.04

I have a system running as a server that has a failing harddrive. While all important data is on a RAID and backed up and all that, I don't have an image of the system itself. There is no specific need as I can do the install of course, but I still want to try to do a hotcopy first before just going down the restore path. I know there are some downsides to this as a process, but there I don't think there are much downsides to trying it as a first resort.

  • OS: Ubuntu 12.04.4 LTS
  • Headless
  • I'm not hoping to install too much new software as the disk is allready failing 🙂
  • The system is running. I'm scared stopping it increases the chance of the disk not comming back up. This means dd might be out?
  • The new disk is not the same size (it's twice as big) as the old one further complicating the dd issue.

My idea was to

  • hotplug the new drive in the system
  • make a filesystem
  • mount it in /mnt/somedir
  • rsync the files
  • some fstab magic
  • some booting magic

The questions I still have are:

What would be a good rsync command?
I was planning on:

rsync -aAXx  / /mnt/somedir/ 
   --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}

(I'm skipping some more dir's, e.g. my mounted raid's etc)

Where the options are:

-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
-A, --acls                  preserve ACLs (implies -p)
-X, --xattrs                preserve extended attributes
-x, --one-file-system       don't cross filesystem boundaries

I'm specifically skipping -H, -v and –progress to speed up the process.
Would that work for Ubuntu? I'm not sure if Ubuntu uses any hardlinks, but I don't think I need the option, do I ?

After this run I could reboot (maybe with a live usb drive) and re-run the rsync if the old disk still starts. This would fix any non-readable/changed files because the system was running I suppose.


How to fix booting?
Then my plan would be to change the UUID for / in my fstab (still have to google how to find the uuid), and do some magic so the system actually boots from the new disk

Have I forgotten something or have I planned something specifically stupid?

Best Answer

You can grab the UUID for all block devices with the blkid command. (You want the one that just says UUID, not PARTUUID)

The rsync options I use are -avhPHAXx.

I don't think -v or --progress will speed anything up unless you're on a very slow console/tty.

Using -x eliminates the need for all of your exclusions assuming they are all on different filesystems (on my system, all except lost+found are).

The only frequently used program that I know of that uses hard links (at least on my system) is git, so that's why I add the -H option. The only problem I think you would have by not using -H is that it will take up a little more space.

As for the bootloader, if you are using GRUB2 with MBR, then the command I use is grub-install /dev/sda (replace sda with the correct drive for you). That should make the new drive bootable. If you're using a different bootloader or UEFI, then I would check google for how to get the new drive booting properly. Just remember that /boot on the new drive will need to be on the same partition as it currently is (assuming you're not using a UUID for /boot also), otherwise you will need to modify fstab accordingly.

Related Question