Ubuntu – How to restore filesystem-backup made by rsync

backuprestorersyncserver

Running version 12.04, with Virtualmin/Webmin.

I tried to remove all unnecessary linux-image files today, since the /boot partition was full. I followed a guide from Ask Ubuntu, but that resulted in a broken Grub, or something, probably because the command in the suggested guide removed more than it should have.

After several hours I finally managed to install a new kernel image, and created a new Grub, but then I found out that all files in the directory /run were deleted and probably several other files/directories, that were related to those packages in that directory. I don't know how that could've happened, but I knew there was something strange already when I booted into the Recovery Mode, since I couldn't find any link to the symlink /etc/resolv.conf --> /run/resolvconf/resolv.conf.

Anyway: I have a complete backup of my filesystem, that was made today with the rsync command (sudo rsync -ahe ssh ..., options: --delete --exclude=.gvfs --exclude=/proc --exclude=/dev --exclude=/sys) .

I tried to restore just the /run directory, without any luck.

My question is then: can I just replace all files on my server, with the files on my backup-location, with the same rsync command? (Yes, I know I have to swap "source" and "destination" in the command)

In case that it is possible, is there anything else I should do afterwards?

Best Answer

First, my compliments on having a current backup -- you've hit the 90th percentile of diligence right there. Now to proceed, I would do this:

  1. Boot from the install CD into the Live Ubuntu envrironment (or if using a server CD, choose the Repair option.)
  2. Open a shell window
  3. Mount the root drive to /mnt, e.g.

    sudo mount /dev/sda1 /mnt
    
  4. Create a second mountpoint, /mnt2 and mount the backup drive to that.

    sudo mkdir /mnt2
    sudo mount /dev/sdb1 /mnt2
    
  5. Now restore like this

    for DIR in bin boot etc home lib lib64 opt root run sbin usr var; do
      sudo rsync -aH --delete /mnt2/$DIR /mnt
    done
    

    All of the directories I skipped, dev, sysfs, tmp, etc. should basically be empty.

  6. Once the restore completes, try chrooting to /mnt and updating grub.

    for DIR in dev proc sys; do
       sudo mount --bind /$DIR /mnt/$DIR
    done
    sudo chroot /mnt
    update-grub
    
  7. Restart

If this doesn't work, then it's time to reinstall and just restore your /home directory & any data files you want.

Related Question