How to Write a Shell Script to Perform the Nightly System Backup

How to Write a Shell Script to Perform the Nightly System Backup thumbnail
How to Write a Shell Script to Perform the Nightly System Backup

Although it is preferable to run backup software instead of a Unix shell script to perform the nightly system backup, writing the shell script will work in a pinch and is not difficult. The shell script will use one of a number of backup utilities that already exist on all Unix systems. As long as the hardware used for backup is available to the Unix operating system, the shell script can be written in a few minutes.

Things You'll Need

  • Hardware for backup data (tape drive, hard drive, network storage)
Show More

Instructions

    • 1

      Make sure the hardware where the backup is going to be saved is accessible to the Unix operating system. If you are using a disk, mount it read-write. If you are using a tape drive, make sure it can be accessed via the "mt" command and that there is a tape already inserted.

    • 2

      Decide which Unix utility will perform the backup. Dump or ufsdump is used to back up a filesystem including special device files. Tar or gnutar is used to back up files. Dd is used to back up the entire disk, including special block-based partitions and any unused partitions.

    • 3

      Begin writing the nightly system backup shell script. For a disk-based backup, the first task for the shell script will be to copy files from the previous day's backup to some other location. If it is a tape-based backup, have the shell script run the "mt" command to make sure a tape has already been inserted. If not, have the shell script send an email to personnel requesting that a tape be inserted.

    • 4

      Next, have the shell script execute the Unix utility chosen earlier to run the backup. No matter which backup utility is chosen, make sure no files, filesystems or partitions are missed. In many cases, the shell script will need to run the backup utility multiple times until all of the data has been backed up. The backup utility must redirect the data being backed up to the tape drive or the filesystem dedicated for backups.

    • 5

      Once the backup has been completed, have the shell script eject the tape if it is a tape-based backup. Save the shell script once all commands have been written.

    • 6

      Test and debug the system backup shell script until it works correctly.

    • 7

      Run the backup script from cron. Enter cron's edit mode with the "cron-e" command as root. Configure cron to run the system backup shell script nightly.

Related Searches:
  • Photo Credit garytamin

Comments

You May Also Like

Related Ads

Featured