Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Let The Music Play: Join EFF Today

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents
Up to --> Linux Tutorial

· Working with the System
· Backing-up and Restoring Files
· Interacting with the System
· Logging In
· Logging Out
· When Things Go Wrong
· Accessing Disks

Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
Copyright Info
Terms of Use
Privacy Info
Masthead / Impressum
Your Account

Private Messages

News Archive
Submit News
User Articles
Web Links


The Web

Who's Online
There are currently, 82 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

Linux Tutorial - Working with the System - Backing-up and Restoring Files
  Working with the System ---- Interacting with the System  

Backing-up and Restoring Files

If you're using Linux in your company, the system administrator probably does regular backups (assuming he wants to keep his job). However, if you are administering your own Linux system (i.e. it's your home workstation), then it is up to you to ensure that your data and important system files are safe.

The computer boom of the 1990's put a PC in everyone's house, but it did not provide them with the same awareness and knowledge that computer users of the 1970's and 80's had. With point-n-click and plug-n-play computers became a "black box" where the insides are an unknown. You turn on your computer and it just works. When you turn on your computer and it doesn't work, people don't know what to do. It's possible that the computer can be repaired, but if the hard disk is damaged, the data may be unrecoverable.

If all you use your computer for it to surf the internet, then there may not be any valuable data on your system. However, if you write letters, manage your bank accounts or many other things on your computer, you may have files you want to keep. Although you may think it is safe, it is extremely important how quickly even a small defect can make the data inaccessible. Therefore, you need to be able to store that data on an external medium to keep it safe.

The data stored on an external medium like a floppy or CD ROM is called a backup. The process of storing the data (or making the copy) is called "making a backup". Sometimes, I will copy files onto a different hard disk. If the first one crashes, I still have access. Even if you don't have a different drive, you can still protect your data to a limited extent by copying it onto a different partition or even a different directory. If the drive develops a problem at the exact spot where your data is, it might be safe some place else. However, if the whole drive dies, your data is gone.

One advantage of storing it on an external device, is that if the computer completely crashes the data is completely safe. In many cases, companies will actually store the data at a different location in case the building burns down or there is some other disaster (no kidding!).

Linux provides a number of different useful tools to help you backup your system. Perhaps the most commonly used tool is tar, probably because of its simplicity. For example let's say you wanted to make a backup copy of the entire directory /data, the command might look like this:

tar cvf data.backup /data

Where data.backup is the name of the file in which you want to store the backups of your files. When tar completes, you have a single file which contains a copy of everything in the /data directory. One thing that we discussed in another section, is that Linux treats hardware just like regular files. Therefore instead of using a filename you could use the name of a device file, like this:

tar cvf /dev/tape /data

Assuming you had a tape drive on your system, and you had named it /dev/tape, this command would backup your data to your tape drive.

Note that there are tools available for Linux which allow you to recover files which you have removed from your system. This goes into too much depth for now, but there is a how-to.

There are other options which you can use with tar that are very useful:

-z compresses - This compresses the file using gzip after it has made the archive. This should not be done telling tar to use different compression programs. See the tar man-page for details.

-T, --files-from=FILENAME - Here you can specify a file which contains a list of files you want to archive. This is useful for system configuration files spread out across your system. Although you could copy all of your system files into one directory prior to making a backup, this method is much more efficient.

Typically when files are removed on Linux they're gone for good. You can create your own "trash can" by creating a shell function that actually moves the file into a different directory for example:

function rm() {
mv $1 /home/jimmo/trashcan

Then when you want to clear out the trash, you would use the full path to the rm command: /bin/rm.

Keep in mind that simply being able to backup files is not enough. Often you do not have enough space on your tapes to do a complete backup of your system every day. Sometimes, doing a complete backup takes so long that even if you start right as people go home, there is not enough time to finish before they come back to work. Further, when trying to restore a complete backup of your system, it will take longer to find the files you need and thus will takes longer to get people back to work. Therefore, you need a backup strategy, which we discuss in the section on problem solving.

 Previous Page
Working with the System
  Back to Top
Table of Contents
Next Page 
Interacting with the System


Test Your Knowledge

User Comments:

Posted by hrosen on November 09, 2005 02:59pm:

Change "it" in this sentence: If all you use your computer for it to surf the internet, to "is" so that it is correct. Howard Rosen

Posted by hrosen on November 09, 2005 03:00pm:

Change "it" in this sentence: If all you use your computer for it to surf the internet, to "is" so that it is correct. as in: If all you use your computer for is to surf the internet, Howard Rosen

You can only add comments if you are logged in.

Copyright 2002-2009 by James Mohr. Licensed under modified GNU Free Documentation License (Portions of this material originally published by Prentice Hall, Pearson Education, Inc). See here for details. All rights reserved.
Show your Support for the Linux Tutorial

Purchase one of the products from our new online shop. For each product you purchase, the Linux Tutorial gets a portion of the proceeds to help keep us going.



Security Code
Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!

Amazon Wish List

Did You Know?
You can choose larger fonts by selecting a different themes.


Tell a Friend About Us

Bookmark and Share

Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.07 Seconds