86

If I want to make a backup of my entire OS (including but not just my home directory), how do I go about this?

Is it as simple as backing up everything in / and then when if I suffer a crash, just copying the files back over?
Will this cover grub, and how do I actually do this when the system is inoperable?

  • you may want to take a look at this question for backup tools askubuntu.com/q/2596 – Decio Lira Oct 17 '10 at 1:03
  • May I ask why you want to do this? In most cases it is your files you will want to backup - the rest of the system is for most people easy to reinstall from the Ubuntu CD. – 8128 Oct 17 '10 at 7:59
  • 10
    Because i hate reinstalling all my apps and PPAs, icons and themes. My HD crashes the installer sometime and I just generally hate installing everything from scratch. – Will Oct 17 '10 at 23:10

17 Answers 17

81

FILES

Refer to this howto: http://ubuntuforums.org/showthread.php?t=35087

In simple terms, the backup command is: sudo tar czf /backup.tar.gz --exclude=/backup.tar.gz --exclude=/dev --exclude=/mnt --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/lost+found /. Add more --exclude= parameters if you need to.

It will create an archive of all your files at /backup.tar.gz, which you can then copy over to another computer/drive and restore your files if the install goes pear-shaped. You can do it from a LiveCD, by mounting the "bad" system under /media or /mnt and running tar xf /path/to/drive/with/backup.tar.gz -C /mnt (substitute for the actual path to the "bad" system).

GRUB

This will not cover GRUB, however you can easily reinstall it by following this guide here. You only need to do steps Three and Four.

  • Great post! Thanks a lot that pretty much answers all my questions – Will Oct 16 '10 at 22:32
  • I am experimenting your command with external NTFS here askubuntu.com/q/788272/25388 but with failures. – Léo Léopold Hertz 준영 Jun 17 '16 at 17:42
  • 2
    How big is the tar file usually? For example I have 90GB of data in "/". But the backing up process (making the backup.tar.gz) stopped because of lack of space.. Is there a way to create the backup.tar.gz file in an external drive? – Arkya Chatterjee May 1 '17 at 13:17
  • 1
    The OP explicitely says "including (...) my home directory" but you are excluding the home directories of all users (--exclude=/home). Am I missing something here? – Mephisto Feb 15 '18 at 8:25
  • 1
    The quoted command has a missing space prior to --exclude=/dev – Johnny Utahh Aug 25 '18 at 3:26
15

Noone noticed clonezilla. It makes a complete image of your hard drive, so it backups absolutely everything. It's as easy as burning an iso or creating a bootable flash drive.

The actual backup takes a while, but is the most reliable.

9

To clone your system to another system. Or make a backup. In terminal type:

dpkg --get-selections | grep -v deinstall > ubuntu-files

This command makes a file list of all installed packages in your system (and stores it in present working directory). Backup this file in hdd, email, etc...(this file is very small).

In the freshly installed ubuntu system run:

sudo dpkg --set-selections <./ubuntu-files (will set it up and)

apt-get -y update
apt-get dselect-upgrade

This will install only those packages you had installed (with apt-get) in the old system.

                                    (OR)

You could back up all the .deb packages from /var/cache/apt/archives/ and install them manually using:

dpkg -i *.deb

And after that running an update cycle later.

  • This indeed an interesting strategy. how to go about the second way under (OR) you proposed. Back them up by copying them? – Mohammed Joraid Jul 10 '17 at 21:48
7

You can use Remastersys to create a bootable live CD/DVD image. This will install like a normal Ubuntu CD.

To install Remastersys, you first need to add a repository:

deb http://www.geekconnection.org/remastersys/repository karmic/

You can then install it from the Software Centre as usual.

Once installed, use it to make a 'dist' backup. This means that user data will be excluded from the ISO image.

remastersys UI

This is often used to create custom distributions but is still useful for the backup task you have in mind. One caveat is that it may fail if the contents of / (minus user data in /home) takes up too much memory because the ISO file format can only hold ~4GB data. Remastersys uses a file system called squashfs to compress your data so you should be OK with up to ~8GB.

  • 1
    I tried this but last time it got too big so taring / excluding the directories im not interested in is better for me, then when i backup i dont have to wait for the CD as my HD will be quicker thanks for the advice though – Will Oct 16 '10 at 22:47
6

Try Remastersys.
With that program you can do liveCD (just the same as Ubuntu installation iso file) of your system with ability to install it on hard drive. Works pretty simple (if you know how to burn iso to USB/CD/DVD).
Works perfectly on my 11.10 and 11.04, and older ones as well.

Installation:
edit file /etc/apt/sources.list
add: # Remastersys
deb http://www.geekconnection.org/remastersys/repository karmic/ and save
Then run in terminal:
sudo apt-get update
sudo apt-get install remastersys

5

Here is a solution I use with SquashFS. It is quite similar to TAR.GZ solution proposed earlier, but has some major benefits.

SquashFS is a compressed file system, which is completely stored in one file. This file can be mounted to an existing system and accessed in a usual way, like any other partition. The difference to TAR.GZ is that SquashFS is a full-blown file system with random access to files, while TAR is just one big concatenated file.

This means that if you want to mount some large backup of your whole file system, for TAR.GZ it would take like 5 hours (in my experience) and for SquashFS it would take just minutes/seconds. The same is true also for the compression/backup operation, SquashFS is many times faster.

UPDATE 2017-01-31: It appears that not only can you mount squashfs file, but also open it as a usual archive with familiar apps like File Roller on Linux and 7-Zip on Windows, etc.

So here is a command I use to back up my root folder:

sudo mksquashfs / /path/to/backup/hdd/root-backup.sqsh -e home media dev run mnt proc sys tmp

where "-e" switch excludes folders you want to exclude (like virtual and external Linux folders in my example).

After the backup is done, I can now mount it:

sudo mkdir /mnt/root_backup
sudo mount /path/to/backup/hdd/root-backup.sqsh /mnt/root_backup -t squashfs -o loop

Now just wait couple minutes (depending on size of the archive) and enjoy all your files at /mnt/root_backup folder.

Same can be done for /home/myname folder, e.g.

sudo mksquashfs /home/myname /path/to/backup/hdd/home-backup.sqsh -e Dropbox GoogleDrive

I exclude Dropbox and GoogleDrive here to avoid any potential problems in the future, in case I restore those folders from backup and they become messing with the actual files in the cloud.

Check more info at http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html

4

We can also do backup of system with rsync & exclude files & folders that we don't want. Here is the following command to do this :

#rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder

Using the -aAX set of options, the files are transferred in archive mode, ensuring that symbolic links, devices, permissions and ownerships, modification times, ACLs and extended attributes are preserved

The --exclude option will cause files that match the given patterns to be excluded.

REFERENCE : Full system backup with rsync

2

Here is a good tutorial using PartImage.

2

TimeShift.

TimeShift protects your system by taking incremental snapshots of the file system at regular intervals. These snapshots can be restored later to bring your system to the exact state it was in at the time when the snapshot was taken.

Open the terminal and run the following command

sudo apt-add-repository -y ppa:teejee2008/ppa
sudo apt-get update
sudo apt-get install timeshift

Screenshots

enter image description here

enter image description here

1

go to ubuntu software center find Déjà Dup backup manger install it`` run it and give path where to backup your data select files to be backup make a back up

later on you can chose backup by giving location of your external hard drive gud luck source [https://launchpad.net/deja-dup]

  • I want to backup my entire system not just my music or videos. – Alvar Nov 19 '11 at 12:27
  • @Alvar you can select the "/" or "File System" and can back that up (that is the ENTIRE SYSTEM). – jaorizabal Mar 23 '12 at 22:27
  • how do I install it? how do I backup my system with it? – Alvar Mar 23 '12 at 22:32
  • It does seem to be reliable at all. Just read some user reviews here apps.ubuntu.com/cat/applications/deja-dup – ILIV Nov 4 '16 at 9:04
  • @ILIV well yeah, the review sucks. That's good to know. Guess it's could be used for single files and music stuff maybe. – Mohammed Joraid Jul 10 '17 at 21:42
1

You can use tools like Bacula Community or Bacula Enterprise. The difference between them is that community version doesn't support bare metal restores when you don't need to re-install the system and just purely recover it after the major crash.

0

Crashplan will back up all your system files and data and allow you to recover it - either on your current PC or allow you to adopt it to another install.

You can back up to their online system, another computer or any attached hard drive.

0

If you hard-disk where Ubuntu is installed isn't too big, you can try booting from a live cd (any linux distro will do) and running:

    dd if=/dev/sda of=/path/to/external/hardisk/mybackupfile

This makes a backup of your whole hard-disk, not just Ubuntu, and it'll also do all the empty bytes, but it's the only solution I can think of. To restore the backup, use:

  dd if=/path/to/external/harddisk/mybackupfile of=/dev/sda
  • so how would I restore my Ubuntu distro from a copy om my whole HDD? Because you can't do that... – Alvar Nov 19 '11 at 13:54
  • @Alvar by storing the backup on an external/cloud drive and running it from a live CD/DVD/USB image. – MacroMan Mar 5 '18 at 11:16
0

I have found you a detailed and recent how to on using Clonezilla. Clonezilla will let you make an image of your complete system including all hard drive partitions etc and later restore it.

The tutorial is at http://geekyprojects.com/cloning/how-to-use-clonezilla-tutorial/

0

You can backup your entire Ubuntu installation to another partition with this answer:

Advantages of this technique:

  • You can continue using the system while it is being backed up. Care must be taken that you are only using web browser apps, office apps, watching videos, etc. and not database apps like accounting or SQL.
  • Virtual file systems are not backed up. They are recreated on each boot up so they are useless to backup in the first place.
  • The first backup may take an hour but daily backups do not copy files that haven't changed so they may only take a few minutes.
  • You can reboot and use the backup. This is beneficial if you want to try something dangerous that might break the system such as a Ubuntu Version upgrade untested in your environment.
  • If you totally break your production environment you can reboot into your clone and copy it back over using the same script.
  • Grub is automatically updated with proper UUID entries.
  • /etc/fstab is automatically updated with proper UUID entries.
0

This works for me on a Ubuntu 18.04 desktop, and only requires 'Disks' (gnome-disk-utility), gparted and standard grub commands.

Backup

  • Create an 8GB partition on a drive and install Ubuntu (minimal install) - call it utilities
    • Install gparted
  • Within this system ..
    • Run Disks, pick production system partition, and choose Create partition image
    • Save the image to ddMMMYYYY.img on any partition on the computer

Restore

  • Within the utilities system, run 'Disks' and click on the partition to restore to

    • choose Restore partition image, and choose the image
  • Run gparted

    • There might be unallocated space in the new partition
      • Partition -> Check (and repair), regardless
    • The UUID will be the same as the original partition, so if the original partition still exists on the computer, you need ..
      • Partition -> New UUID
    • Take note of the UUID - eg. ba5b7f3a-54d2-4325-80e5-e7a159900d3f
    • Take note of the restored partition - eg. /dev/sda6

fstab update

  • Skip to grub update below if you have not created a new UUID
  • Run Files (ie. nautilus)
    • Click + Other Locations
    • Click on the device/partition - eg./dev/sda6
  • Run ..
      df -hT
      # you will get something like ..
      /dev/sda6 xx xx /media/fred/ba5b7f3a-54d2-4325-80e5-e7a159900d3f/etc/fstab
  • paste in the last entry to produce a command like so ..
  sudo vi /media/fred/ba5b7f3a-54d2-4325-80e5-e7a159900d3f/etc/fstab
  • Change the ''/'' entry in ''fstab'' to use this UUID

grub update

  • Run the following (assuming that your master boot record is on /dev/sda) ..
  # ensure all systems are found
  sudo os-prober
  # generate /boot/grub/grub.cfg
  sudo update-grub
  # search for root=UUID and check that the new UUID is used in some of these
  # if not, try sudo grub-mkconfig, seems to get it right eventually
  less /boot/grub/grub.cfg
  # update the master boot record
  sudo grub-install /dev/sda
  • Reboot and go into the restored system
  • Check that you really are in the restored system - note the ''/'' line
df -hT | grep ext4
/dev/sda6      ext4       29G  6.1G   22G  23% /
/dev/sdb6      ext4      112G   86G   22G  81% /data
/dev/sda4      ext4      1.6T  377G  1.1T  26% /sata

final grub update from the new system

  • Run this from the new system, so that this system becomes the default in the boot menu (assuming that your master boot record is on /dev/sda) ..
  sudo os-prober
  sudo update-grub
  sudo grub-install /dev/sda
-2

I use a program called Back In Time that's similar to Apple's Time Machine.

It's easy to tell it where you want your backups to go and how often to do the backup.

Back In Time is in the Ubuntu repos.

  • That doesn't explain how to backup my system and how to restore it at all. When i can't even boot up back in time won't be able to help. If you can suggest how to use backup in time in this way I would be appreciative. Cheers – Will Oct 17 '10 at 9:11
  • Back in time uses is a frontend for rsync. You'll have to have Ubuntu installed to use it. I agree with fluteflute's comment above that it's easier to backup your files. That's what I thought you wanted. – gamerchick02 Oct 17 '10 at 16:21
  • I already backup my files ;) The amount of times i render ubuntu inoperable its easier to either reinstall or revert to a backup than fix the problem (generally i need it fixed as I have work to do in between fiddling and breaking!) – Will Oct 17 '10 at 23:11
  • Right. I tried back in time to setup an automatic backup but i get a whole bunch of errors. Most like this: (its just a small fraction, and im running in root mode) – Will Oct 18 '10 at 15:55
  • 1
    The backup commands noted above would probably work best for you. I only suggested Back in Time as a frontend for the rsync, etc. You can choose what you want to make a backup of, including all of the system files. – gamerchick02 Oct 18 '10 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.