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?
FILES
Refer to this howto: http://ubuntuforums.org/showthread.php?t=35087
In simple terms, the backup command is:
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 runtar xf /path/to/drive/with/backup.tar.gz -C /mnt
(or/media
).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.
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.
To clone your system to another system. Or make a backup. In terminal type:
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.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.
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:
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:
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.
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
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 :
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 preservedThe
--exclude
option will cause files that match the given patterns to be excluded.REFERENCE : Full system backup with rsync
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:
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.
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.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 saveThen run in terminal:
sudo apt-get update
sudo apt-get install remastersys
I turned afrish's excellent answer into a script for myself. Thought it could be useful for those wishing to automate it. The nice thing is that since the script can live on the NAS it will only execute if it's connected.
The script (can be copied to any location - preferably the NAS itself) and will build the backups in the same folder.
Backups Script
make_backups_root_and_home.sh
Don't forget to
chmod +x make_backups_root_and_home.sh
!Linux Cronjob
To enable the cronjob:
For Sunday at 1am, append:
Testing Backups!
As with all good backups, they should be tested! Finally, we can create a script to mount the last available backup (since they are ordered by date).
mount_last_backup.sh
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
Screenshots
Here is a good tutorial using PartImage.