How to back up my entire system?
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?
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.
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.
21 Answers 21
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=/media \ --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 should be copied to another computer or drive.
To restore your files when the system goes pear-shaped, use a Live CD. Mount the bad system under /media or /mnt and then run tar xf /path/to/drive/with/backup.tar.gz -C /mnt (or /media ).
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.
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?
@ArkyaChatterjee: Or course. just mount your external drive and change /backup.tar.gz to whatever is your mount point, like /media/backup//backup.tar.gz
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?
tar -cvpzf /backup.tar.gz —exclude=/backup.tar.gz —one-file-system / will do what you want without needing to add all those other —exclude directories
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.
Can not recommend clonezilla. I just tried it and got this error: sourceforge.net/p/clonezilla/discussion/Clonezilla_live/thread/… and seems like nothing is being done about it
Clonezilla is really great! It’s use-case is a bit different tho. I used it to clone my harddrive to an external. However, it is a full clone of the whole disk, including empty space. It is an exact mirror, which is great, but a different use-case for backups.
Clonezilla does not clone empty space. It’s a great tool with the only downside being that you have to boot into it.
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:
This will install only those packages you had installed (with apt-get ) in the old system.
Alternatively, you could back up all the .deb packages from /var/cache/apt/archives/ and install them manually using:
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?
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.
Introduction
Backup and recovery is essential. Failure to have verified backup and recovery procedures puts your data at risk of loss. Users often only learn this lesson after critical information they require is permanently lost. Attempting to recover from data loss can be both time consuming and extremely difficult. So learn from others mistakes, and ensure beforehand that you have a system in place that protects your data and suits your needs.
- Why? — Why are you protecting yourself against disaster? Does it matter if you lose data? What losses will you suffer ($$$)?
- What? — What are you going to backup? Your entire hard drive or just some of the data?
- When? — When is the best time to backup your system? How often will you perform a backup? When will you use full backups and incremental backups.
- Where? — Where will the backups be stored? On-site? Off-Site? Cloud?
- Medium? — Attached storage (usb stick, usb hard drive, tape drive), backup server?
Backup
Types of Backup
- Recovery time objective (RTO): How fast should data be recovered? Can you continue to operate if data recovery is not recovered for a day, a week, etc?
- Recovery point objective (RPO): How much data can be lost. Can you lose two hours, two days or two weeks of data?
example: if you can withstand losing one week of data then a weekly backup would be sufficient, but if you can only withstand losing one day then you would need to employ a nightly backup (or a variation)
This document will cover three basic types of backup; Full, Incremental, and Differential.
Full: A full backup backs up all the files in the back up target.
Incremental: An incremental backup backs up all the files that have changed since the last backup.
Differential: A differential backup backs up all the files that have changed since the last full backup.
Backup Methods
- manual — Manual backup would be initiated on a schedule by the user and is the most common method for home users to backup their files. This method is also the least reliable.
- local automated — Automated backups that target a hard drive or tape drive attached to the physical box being backed up fall into this category. Advanced home users and small businesses will often use this method.
- remote automated — Automated backups that target a hard drive, tape drive or virtual tape library (VTL) over the network fall into this backup. This type of backup is often used by businesses that have money they can dedicate to the process of backup. As the organization becomes more mature they may even stage the backup on multiple mediums and increase the distance between backup and production systems.
mtime, atime and ctime
- mtime — modification time; this value is changed when the contents of the file is changed.
note: file system backups change atime while raw device backups will not. If you are implementing incremental or differential backups this is important
Recovery
note: many people consider only the backup part of this process and do nothing to verify that the backup can be restored. It is very important to test that your backup process is working and that data can be recovered.
- Restore many single files
- Restore an older version of a file
- Restore an entire folder
- Restore an entire drive and compare the checksum
If you do not test you may find out that nothing was being backed up when you need to restore the files in reality.