Book Image

Linux Utilities Cookbook

By : James Kent Lewis
Book Image

Linux Utilities Cookbook

By: James Kent Lewis

Overview of this book

<p>Linux is a stable, reliable and extremely powerful operating system. It has been around for many years, however, most people still don't know what it can do and the ways it is superior to other operating systems. Many people want to get started with Linux for greater control and security, but getting started can be time consuming and complicated. <br /><br />A practical, hands-on guide that provides you with a number of clear step-by-step examples to help you solve many of the questions that crop up when using an operating system you may not be familiar with.</p> <p>Presenting solutions to the most common Linux problems in a clear and concise way, this helpful guide starts with spicing up the terminal sessions by command retrieval and line editing, and shell prompt variables. We will then get to know the different desktops (GUIs) available for Linux systems and which is the best fit for you. We will then explore the world of managing files and directories, connectivity, and what to do when it goes wrong. We will also learn a range of skills, from creating and managing user accounts to securing your system, managing and limiting processes, and letting information flow from one process to another using pipes. Later, we will master disk management, working with scripts and automating tasks quickly, and finally, understand the need for a custom kernel and tips on how to build one.</p> <p><br />Based on the author's extensive experience, there is a section on best practices that every Linux user should be familiar with.</p>
Table of Contents (19 chapters)
Linux Utilities Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating, verifying, and storing backups


I cannot stress how important it is to create backups of your system(s). At a minimum, copy your personal and business data, and configuration files to a safe place. Some people backup everything, even the operating system itself. Whatever you decide to do, make a plan and stick to it. As mentioned in Chapter 8, Working with Scripts, this is a great time to design and use a script. Use crontab if desired, to automate the periodic taking of backups.

The tar command is great for backing up entire directories. Note that it will get any hidden files as well. You can exclude specific directories if desired, and do quite a few other things with tar. The following are the commands similar to the ones I use to backup my /home/guest1 directory.

Tip

tsback1 is a text file containing the number to start with.

cat tsback1
0

The following is the start of the script:

    cd /home
    NUM=`cat tsback1`        # get the next number to use
    tar -cvzf /megadrive/backups/backup$NUM.gz --exclude=Cache  --exclude=.cache --exclude=.thumbnails  guest1

Remember to include the directory to be backed up as the last thing on the line. This first changes the /home directory, because for tar, you want to be in the parent directory of the sub-directory to be backed up. The next line sets the NUM variable to the next one to use. The last line creates the tar file directly onto my USB external drive in the appropriate directory.

I attempt to be very careful while creating backups. The script I actually use to back things up does quite a few other things. For example, it checks to make sure my USB external drive is really there, and can be written to (it should also check if there is enough free space on the drive, that's a TODO of mine). If the code determines the drive is not there or some other error occurs, a really loud and obnoxious alarm goes off. And, if I have not responded to this alarm in 5 minutes, an email is sent to my cell phone. How's that for paranoid?

Making backups is great. However, if the backup is unusable, it doesn't do you much good. So, it is wise to verify your backups from time to time. How often do this is up to you and your comfort level. My script routinely copies the backup files to another machine, which then extracts them and runs a few tests. If anything doesn't look quite right, another alarm goes off. This is all done automatically in scripts.

Okay, we are now making backups and verifying them. What about storing them? Suppose you have everything just right, all your files are copied and verified, and they are all located in the same place such as your home or office. And now something unspeakable occurs, such as a fire or theft. I agree, there is a very low chance of this happening, but it still could. I, for one, do not want to try and reproduce the million lines of code I have written since 1982 and so have backups all over the place, including off-site. In some of the companies I have worked at, the files were copied to tape, CDs, and/or hard drives, and stored in a walk-in fireproof safe. Pretty good idea.