Backing Up
To get started, please open up a terminal, in Ubuntu this can be done by Applications Menu -> Accessories -> Terminal. Some directories require root or superuser permissions to read and write (needed for backup), for an explanation on why see FilePermissions. To gain temporary root permission, simply preface any command you want to issue with sudo, as explained in RootSudo.
For this example, we will change directories to root. This is where the backup will be made. This is an arbitrary decision, you should create the backup elsewhere. For instance to a mounted external hard drive, another partition or disk connected internally, even a folder in your home directory could be used. In all cases, ensure the location your saving the archive to has enough space. Simply use the cd command to navigate there.
cd /The following is an exemplary command of how to archive your system.
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /To understand what is going on, we will dissect each part of the command.
tar - is the command that creates the archive. It is modified by each letter immediately following, each is explained bellow.
c - create a new backup archive.
v - verbose mode, tar will print what it's doing to the screen.
p - preserves the permissions of the files put in the archive for restoration later.
z - compress the backup file with 'gzip' to make it smaller.
f <filename> - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.
--exclude=/example/path - The options following this model instruct tar what directories NOT to backup. We don't want to backup everything since some directories aren't very useful to include. The first exclusion rule directs tar not to back itself up, this is important to avoid errors during the operation. After, we proceed to exclude the /proc, /lost+found, /sys, /mnt, /media and /dev directories in root. /proc and /sys are virtual filesystems that provide windows into variables of the running kernel, so you do not want to try and backup or restore them. /dev is a tmpfs whose contents are created and deleted dynamically by udev, so you also do not want to backup or restore it.
It is important to note that these exclusions are recursive. This means that all folders located within the one excluded will be ignored as well. In the example, excluding the /media folder excludes all mounted drives and media there.
If there are certain partitions you wish to backup located in /media, simply remove the exclusion and write a new one excluding the partitions you don't want backed up stored within it. For example:
--exclude=/media/unwanted_partition/ - After all options is the directory to backup. Since we want to backup everything on the system we use / for the root directory. Like exclusions, this recursively includes every folder below root not listed in the exclusions or other options.
See tips before operation for additional information.
Once satisfied with the command, execute it and wait until it has completed. The duration of the operation depends on the amount of files and compression choses. Once completed, check the directory you set to find the archive. In our example, backup.tar.gz would be located in the / directory once completed. This archive can then be moved to any other directory for long term storage.
Note: At the end of the process you might get a message along the lines of 'tar: Error exit delayed from previous errors' or something, but in most cases you can just ignore that.
Additional Tips
- To keep good records, you should include the date and a description of backup in the filename.
Another option would be to use bzip2 to compress your backup instead of gzip. Bzip2 provides a higher compression ratio at the expense of speed. If compression is important to you, just substitute the z in the command with j, and change the file name to .tar.bz2. The rest of this guides examples use gzip, make the subsequent changes to the examples before using them.
If you want to exclude all other mounts other than the current - by this I mean partitions mounted to directories - then use the --one-file-system option appended before the exclusion rules. This has the effect of stopping tar from crossing into any other mounts in any directory including /mnt or /media. For instance, many users create a separate mount for /home to keep user folders separate from root, adding this option to our original example would exclude home's contents entirely.
from http://web.media.mit.edu/~jorkin/aibooks.html:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|