Professional Documents
Culture Documents
Partners
Support
Community
Ubuntu.com
Page History
Login to edit
Search
BackupYourSystem/TAR
Improper usage of any archival program can cause unintended data loss.
Read the entire tutorial before proceeding and understand what you are
doing.
If you are not worried about the security concerns, this step is
not necessary. Many users explicitly want backups of their email
and browser settings.
Unmount any external drives and remove any optical media such as CDs or
DVDs that you do not want to include in the backup.
This will reduce the amount of exclusions you need to type later in
the process.
Go through the contents of your user folder in /home and delete all
unwanted files in the subdirectories, often people download files and
forget about them for instance.
1 de 6 05/02/17 00:36
BackupYourSystem/TAR - Community Help Wiki https://help.ubuntu.com/community/Backup...
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 /
To understand what is going on, we will dissect each part of the command.
v - verbose mode, tar will print what it's doing to the screen.
2 de 6 05/02/17 00:36
BackupYourSystem/TAR - Community Help Wiki https://help.ubuntu.com/community/Backup...
the partitions you don't want backed up stored within it. For
example:
--exclude=/media/unwanted_partition
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.
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.
Archive Splitting
If you want to burn the archive to discs, or transfer them to a filesystem
with a limited max filesize (say FAT32 with a limit of 4GB per file) then
you will have to split the file either during or after archive creation. A
simple means is to use the split command. Below are examples of both
scenarios. More information than conveyed here can be found in the man
pages of split, use man split in a terminal to read. Ensure you keep these
archives all together in a directory you label for extraction at a later
date. Once the archives are split to a desirable size, they can be burned
one at a time to disc.
The first half until the pipe (|) is identical to our earlier example,
except for the omission of the f option. Without this, tar will output
the archive to standard output, this is then piped to the split
command.
3 de 6 05/02/17 00:36
BackupYourSystem/TAR - Community Help Wiki https://help.ubuntu.com/community/Backup...
-b - This option designates the size to split at, in this example I've
made it 3900mB to fit into a FAT32 partition.
The use of * as a wild card before and after tar.gz tells cat to start
with first matching file and add every other that matches, a process
known as catenation, how the command got its name.
Afterwards, it simply passes all that through standard output to tar to
be extracted into root in this example.
Netcat
The command nc is designed to be a general purpose networking tool. It sets
up a simple connection between two networked machines. This connection
survives until the user manually disconnects it, unlike normal connections
such as tcp which terminate upon completion of a file.
Receiving Computer
On the receiving end you'll setup netcat to write the backup file as in the
following example. This command will setup a machine to receive standard
input from network to port 1024 then write it to the file backup.tar.gz.
The choice of port is entirely up to the user, as long as it is 1024 or
larger. A simple example:
nc -l 1024 > backup.tar.gz
Sending Computer
On the machine to be backed up, the tar command will be piped to nc which
will then send the backup over the network to the port in question to be
written in the file. Take note, where it says <receiving host> replace with
the name of the computer on the network. The f option was omitted since we
are not writing to a local file, but moving the archive through standard
output. The following is an example:
4 de 6 05/02/17 00:36
BackupYourSystem/TAR - Community Help Wiki https://help.ubuntu.com/community/Backup...
tar -cvpz <all those other options like above> / | nc -q 0 <receiving host> 1024
If all goes well the backup will be piped through the network without
touching the file system being read.
SSH
You can also use SSH. For a complete explanation of its proper use see SSH.
The command below is an example of what is possible.
tar -cvpz <all those other options like above> / | ssh <backuphost> "( cat > ssh_backup.tar.gz )"
In the example:
The tar half of the command is the same as above, with the omission of
the f option to pipe the archive via standard output to ssh and onto
the networked computer.
Restoring
You will want to restore from a Live CD. If needed, first partition and
format the drive. You can do this with gparted. Then simply mount the
partition you are going to restore somewhere. If you open the drive in
nautilus, it will be auto mounted somewhere under /media. Take a look to
find out where with:
ls /media
A brief explanation:
This will overwrite every single file and directory on the designated
mount with the one in the archive. Any file created after the archive, will
have no equivalent stored in the archive and thus will remain untouched
5 de 6 05/02/17 00:36
BackupYourSystem/TAR - Community Help Wiki https://help.ubuntu.com/community/Backup...
Restoring GRUB
For the system to boot, you will need to restore grub. To do this, you will
need to reconfigure it in a chroot:
sudo -s
for f in dev dev/pts proc ; do mount --bind /$f /media/whatever/$f ; done
chroot /media/whatever
dpkg-reconfigure grub-pc
You will get a menu asking you what drive(s) grub should be installed on.
Choose whatever drive(s) the computer will be booting from.
Receiving Computer
Ensure the disk has been mounted and use the following command to accept
input over the network that will then be extracted to the path indicated.
In this example, the directory /mnt/disk will be extracted to.
nc -l 1024 | sudo tar -xvpzf - -C /media/whatever
Sending Computer
On the computer with the archive to send, use the following command:
cat backup.tar.gz | nc -q 0 <receiving host> 1024
A few comments:
The - character in the first command will tell tar to accept input from
standard input rather than a file. In this case, input comes from the
pipe.
The backup file will be expanded without being saved on the disk of
receiving computer, the same as when the backup was made.
Additional Resources
"Backing Up Ubuntu"
CategoryBackupRecovery CategoryCommandLine
6 de 6 05/02/17 00:36