1

Could you please help me on how to take ubuntu 16.04 whole backup into external hard disk? As I want to install another operating system in my laptop and if the other operating system not required,then I want to Restore ubuntu 16.04.

Please provide step by step procedure as I am new to ubuntu.

ravery
  • 6,874

3 Answers3

4

This is the solution I would recommend (unless you are willing to try Clonezilla):

Step 1: Make sure your external disk is at least as big as your internal one. You need to be able to fit everything onto your backup disk.

Step 2: Figure out which disks to use. For this, you should run the command:

sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

Which should output something like:

NAME   FSTYPE   SIZE MOUNTPOINT LABEL
sda           111.8G            
├─sda1 swap     121M [SWAP]     
└─sda2 ext4   111.7G /          
sdb             2.7T            
└─sdb1 ext4     2.7T            

You want whichever one has a partition mounted as /. Also figure out which one is your external disk using this output. BE VERY CAREFUL, YOU DO NOT WANT TO GET THIS WRONG. If your main disk (The one with Ubuntu installed on it) is /dev/sda and your external disk is /dev/sdb, then you should do the next step exactly.

Step 3: Run dd to copy everything over. Depending on the size of your disk, this may take a VERY long time, so be patient. This is the command:

sudo dd if=/dev/sda of=/dev/sdb status=progress

If your disks were different than the ones in the example, then just replace /dev/sda with your main disk and replace /dev/sdb with your external disk. and use status=progress to display the progress.

3

This is what I use for a full backup:

#!/bin/bash

# NAME: full-backup
# PATH: $HOME/bin
# DESC: Full system backup - must call with SUDO

# DATE: July 16, 2017. Modified July 26, 2017.

apt autoclean   # reduces size of /var/cache/apt/archives

cd /tmp     # tar must be created in directory not backed up.

time tar -cvpzf backup.tar.gz \
--exclude=/backup.tar.gz \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/media \
--exclude=/usr/src/linux-headers* \
--exclude=/home/rick/.cache \
--exclude=/var/log \
--exclude=/var/run/ \
--exclude=/run \
--exclude=/var/cache/apt/archives /

I've never used the backup to restore files and hope I will never have to.

Put the script into /usr/local/bin/full-backup and mark it executable using chmod a+x /usr/local/bin/full-backup. The backup will be a compressed file but still requires about 6 GB on my system

When you call full-backup script the backup archive will be created in the /tmp directory. Then you will need to copy it to a USB flash drive.

derHugo
  • 3,356
  • 5
  • 31
  • 51
  • 2
    You should test it out to make sure your backup actually worked. – FelicianoTech Dec 04 '19 at 04:15
  • 2
    @FelicianoTech Since this answer I've been doing daily backups to my gmail account. I have restored from those backups and they do work.Also I have a script that does a full backup to a bootable grub menu option where I can test system upgrades on the full backup. – WinEunuuchs2Unix Dec 04 '19 at 11:26
  • @WinEunuuchs2Unix can you share commands to restore from this backup? – domis86 Nov 23 '20 at 21:10
  • @domis86 If you have files you need to restore, that is a separate question altogether. – WinEunuuchs2Unix Nov 25 '20 at 11:28
  • @WinEunuuchs2Unix indeed - but if you would be so kind to also share the "restoration procedure" then it would be helpful. I mean: is it as simple as just extracting this archive on newly installed Ubuntu? Or one needs to do other things? (like setting some tricky permissions somewhere, updating some system config etc) – domis86 Nov 25 '20 at 15:12
  • 1
    @domis86 From my point of view your request requires me to make partition, install Ubuntu, create files, backup everything, destroy stuff, boot into different partition, mount partition with destroyed stuff, mount backup, compare two mounts for differences and decide which files to restore. Each of the steps above could potentially be a separate question in Ask Ubuntu. As I tried to point out if you have a problem restoring files you need to ask a question. If you want to know all the problems that can be encountered restoring files it is too broad a question. – WinEunuuchs2Unix Nov 28 '20 at 04:01
0

// backup an ubuntu computer

I am in directory /home/bob>,

  • --one-file-system: will exclude the operating system files that should not be restored
  • --exclude: will exclude the current backup file
  • -p: will keep the permissions
  • -z: will do a better compression
    sudo tar -cvpzf filename.tar.gz --exclude=/home/bob/filename.tar.gz --one-file-system /

// restore an ubuntu computer

sudo tar -xvpzf filename.tar.gz -C / --numeric-owner

have fun