Backup
Data
Determining What to Back Up
ou
should consider backing up the following directories in your Linux file system:
• /etc
• /home
• /home
• /opt
• /root
• /root
• /var
• /srv
• /srv
Notice that this strategy doesn’t back up your Linux system
or its utilities. Instead, it only backs up your configuration files, your user
data, your log files, and your web/ftp files.
Using
tar
The
tar utility has been around for a very long time and is a very commonly used Linux
backup tool. The acronym “tar” stands for tape archive. The tar utility takes a
list of specified files and copies them into a single archive file (.tar). The
.tar file can then be compressed with the gzip utility on your Linux system,
resulting in a file with a .tar.gz extension. This is called a tarball.
tar –cvf filename directory
tar –cvf /media/usb/backup .tar /home
To restore a tar archive, simply enter tar –xvf filename. For example, to extract the archive we just created, you
would enter tar –xvf /media/usb/backup.tar.
If you want to back up to a tape drive instead of a USB
drive, you could do this by replacing the filename parameter in the tar command
to the device name for your tape drive. On most distributions, the first SCSI
tape drive in the system is referenced through /dev/st0. Therefore, you could
enter tar –cvf
/dev/st0 /home if you wanted to run the same backup as in the previous
example, but send it to a SCSI tape drive instead.
Using
cpio
The
cpio utility can also be used to make archive files just like tar. A key
difference between tar and cpio is the fact that you must provide cpio with a
list of files and directories to back up from the standard input. This can be
done using cat to display the contents of a file or by generating a listing
using find or ls.
This can be done using the find utility, discussed earlier.
You could switch to /home/ tux/myproject and then enter find . –print
–depth | cpio –ov > /media/usb/backup.cpio. The find utility will generate a listing of all
files in the current directory. Because the –print option was used, find will
print the full name of each file to the screen (the standard output). Because
the –depth option was also used, find checks the contents of each directory
before processing the directory itself.
If
there are no subdirectories in the MyProjects directory, an easier way to do
this would be to enter ls | cpio –ov > /media/usb/backup.cpio
The
key here is the fact that we’ve piped the standard output from find to the
standard input of cpio. The cpio utility uses this as a list of files and
directories to archive. The –o option tells cpio to create a new archive. The
–v option simply tells cpio to run verbosely, displaying the name of each file
and directory as it’s processed. Finally, we have to redirect the standard
output from cpio (the archive) to a file in the file system. This is done by
entering > followed by the name of the archive file.
You
can also compress a cpio archive by adding the gzip utility to the pipe[md]for
example, ls | cpio –ov | gzip > /media/usb/backup.cpio.gz.
To
restore files from a cpio archive, you run cpio from the shell prompt using the
–i option and specifying the name of the archive to process. When you do, the
archive files will be extracted into the current working directory. For
example, we could extract the archive we just created by entering cpio
–iv < /media/usb/backup.cpio
Using dd to Copy Data
The
key difference between dd and other file copy utilities is the fact that it
copies data using records. The default size for a record is
512 bytes.
Let’s
first look at how you copy a file with dd. The syntax is dd if=input_fileof=output_file.
Use the if= (input file) option to specify the file to be copied. Use the of=
(output file) option to specify the name of the new file. Here is an example:
openSUSE:/
# dd if=/home/tux/MyProject/acpidump
You can modify the default record size using the bs=block_size option.
Another useful feature of dd is the fact that it can create a
backup copy of your hard drive’s master boot record (MBR) and partition table.
The syntax is dd if=device_fileof=output_file bs=512
count=1
No comments:
Post a Comment