Backup Linux - JohnnyFoulds/firstrepo GitHub Wiki

This page describe how the backup your Linux system to Google Drive with the help of the gdrive command line utility.

Install Google Drive CLI

wget -O drive https://drive.google.com/uc?id=0B3X9GlR6EmbnMHBMVWtKaEZXdDg 
mv drive /usr/sbin/drive 
chmod 755 /usr/sbin/drive
drive

When you run the drive utility you will be provided with a URL to generate a security code you must then paste back to authenticate gdrive.

Backup the boot partition

The following command do a backup of the boot partition directly to Google Drive:

BOOTDRIVE="$(fdisk -l | grep '^/dev/[a-z]*[0-9]' | awk '$2 == "*"' | cut -d ' ' -f 1)"
sudo dd conv=sparse if=${BOOTDRIVE} | gzip -c --fast | drive upload --stdin --title bootdrive.gz

Backup the Linux Installation

cd /
sudo tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /

The --one-file-system flag ensures that files different filesystem are not included, for example files mounted to external drives or network drives.

Once the backup completes it can then be uploaded to Google Drive:

drive upload -f backup.tar.gz

Restoring

You will want to restore from a Live CD. If needed, first partition and format the drive. You can do this with gparted. Then simply mount the partition you are going to restore somewhere. If you open the drive in the file explorer, it will be auto mounted somewhere under /media. Take a look to find out where with:

ls /media

Then restore the backup with:

sudo tar -xvpzf /path/to/backup.tar.gz -C /media/[MOUNT_POINT] --numeric-owner

Restoring GRUB

For the system to boot, you will need to restore grub. To do this, you will need to reconfigure it in a chroot:

sudo -s
for f in dev dev/pts proc ; do mount --bind /$f /media/[MOUNT_POINT]/$f ; done
chroot /media/[MOUNT_POINT]
dpkg-reconfigure grub-pc

You will get a menu asking you what drive(s) grub should be installed on. Choose whatever drive(s) the computer will be booting from.

Read-Only File System

If you have a problem where the system boots but the file system is read-only perform the following steps:

  1. Reboot and hold down the Shift key to open the GRUB menu.
  2. Choose Advanced Options the e to edit the commands.
  3. Where the file system is ro change it to rw. images/GRUB.png
  4. Press F10 to boot.
  5. The system should boot normally and you can log in.
  6. See what the uuid of the boot disk is with ls -l /dev/disk/by-uuid
  7. Edit the /etc/fstab file if it is not correct.
  8. Reboot the system

Web References