Friday, December 4, 2009

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.

No comments:

Post a Comment

Privacy policy

At http://linux4fresher.blogspot.com/, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by http://linux4fresher.blogspot.com/ and how it is used.

Log Files
Like many other Web sites, http://linux4fresher.blogspot.com/ makes use of log files. The information inside the log files includes internet protocol ( IP ) addresses, type of browser, Internet Service Provider ( ISP ), date/time stamp, referring/exit pages, and number of clicks to analyze trends, administer the site, track user’s movement around the site, and gather demographic information. IP addresses, and other such information are not linked to any information that is personally identifiable.

Cookies and Web Beacons
http://linux4fresher.blogspot.com/ does use cookies to store information about visitors preferences, record user-specific information on which pages the user access or visit, customize Web page content based on visitors browser type or other information that the visitor sends via their browser.

DoubleClick DART Cookie
Google, as a third party vendor, uses cookies to serve ads on http://linux4fresher.blogspot.com/.
Google's use of the DART cookie enables it to serve ads to users based on their visit to http://linux4fresher.blogspot.com/ and other sites on the Internet.
Users may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy at the following URL - http://www.google.com/privacy_ads.html

Some of our advertising partners may use cookies and web beacons on our site. Our advertising partners include ....
Google Adsense


These third-party ad servers or ad networks use technology to the advertisements and links that appear on http://linux4fresher.blogspot.com/ send directly to your browsers. They automatically receive your IP address when this occurs. Other technologies ( such as cookies, JavaScript, or Web Beacons ) may also be used by the third-party ad networks to measure the effectiveness of their advertisements and / or to personalize the advertising content that you see.

http://linux4fresher.blogspot.com/ has no access to or control over these cookies that are used by third-party advertisers.

You should consult the respective privacy policies of these third-party ad servers for more detailed information on their practices as well as for instructions about how to opt-out of certain practices. http://linux4fresher.blogspot.com/'s privacy policy does not apply to, and we cannot control the activities of, such other advertisers or web sites.

If you wish to disable cookies, you may do so through your individual browser options. More detailed information about cookie management with specific web browsers can be found at the browsers' respective websites.

Disclaimer :
All the pictures and material on this blog are assumed to be taken from public domain. The copyright (if any) of these pictures and articles belongs to their orginal publisher / photographer / copyright holder as the case may be. We claim no ownership to them. If anybody has reservations / objection on the use of these material/images or find any copy-righted material on this site, then please e-mail us with the details of copy right etc. In case, the objections is found to be appropriate, the offensive material / pictures will be removed from this site immediately.