Chapter 10. Scripting Best Practices

This chapter explains some practices and techniques that will help the reader become a better and more efficient programmer.

In this chapter we will talk about what I consider to be scripting (or programming) best practices. Having programmed computers since 1977 I have attained quite a bit of experience in this field. I take great pleasure in teaching people about computers and hopefully my ideas will be of some benefit.

The topics covered are as follows:

  • Backups will be discussed again, including verification
  • I'll explain how to pick a text editor you are comfortable with and learn its capabilities
  • I'll cover some basic command line items such as using a good prompt, command completion, environment variables and aliases
  • I'll provide some bonus scripts

Verifying backups

I have already spoken about backups at least twice in this book and this will be the last time I promise. Create your backup scripts and make sure they run when they are supposed to. But one thing I have not talked about yet is verification of the backups. You might have 10 teraquads of backups lying around somewhere, but do they actually work? When was the last time you checked?

When using the tar command it will report at the end of the run if it encountered any issues making the archive. In general if it doesn't show anything amiss the backup is probably good. Using tar with the -t (tell) option, or actually extracting it on the local or remote machine, is also a good way to determine if the archive was made successfully.

Note

Note: A somewhat common mistake when using tar is to include a file in the backup that is currently being updated.

Here is a rather obvious example:

guest1 /home # tar cvzf guest1.gz guest1/ | tee /home/guest1/temp/mainlogs`date '+%Y%m%d'`.gz

The tar command might not consider this an error but will usually report it so be sure to check for this.

Another common backup mistake is to not copy the file to another computer or external device. If you are good at making backups but they are all on the same machine eventually the hard drive and/or controller is going to fail. You may be able to recover the data but why take the risk? Copy your files to at least one external drive and/or computer and be safe.

There is one last thing about backups I will mention. Make sure you have a backup sent to an off-site location, preferably in another city, state, continent, or planet. You really can't be too careful with your valuable data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset