Linux Shell Script To Backup To Tape Drive

in Categories Backup last updated September 1, 2009
# A simple shell script to backup dirs to tape drive.
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# -------------------------------------------------------------------------
# What to backup. 
SOURCE_DIRS="/data /home /etc /root /www"
# Where to backup to.
# log message
$LOGGER "Backing $SOURCE_DIRS to $TAPE @ $(date)"
# Rewind the tape
$MT -f $TAPE rewind
# Backup the files
# Rewind and eject the tape
$MT -f $TAPE rewoffl
# log message 
$LOGGER "Backup finished @ $(date)"

Share this on:

8 comment

  1. You should not use gzip in backups single bit error and the entire stream is losts. Bzip2 is different and using pbzip2 -1 -c you can get quite speedy.

  2. What is the easiest possible solution to transfer 1TB of audio content from one datacenter to the other. The date cant be transferred physically, It can only be transferred through connection.

    1. You probably have this done by now, but…
      It depends on the platform that you are on. But if you don’t have a physical way to transfer the data then I hope you have a fat backbone.

      I find that the easiest way is to use either scp, or rsync on any Linux or Unix OS. Both of these the SSH protocol to encrypt the data as it’s being transferred. I prefer rsync over scp just because it’s made for syncing up directories and the like, while scp is more like FTP, but through SSH.

      Here’s how I would normally run rsync to sync two directories and make them exactly the same:

      rsync -rlt –progress –update –delete /path/to/local/directory/ user@host:/path/to/remote/directory/ (the trailing slashes do make a difference).

      Anyway, that’s just an opinion from a nobody.

    Have a question? Post it on our forum!