Linux Shell Script To Backup To Tape Drive

by on September 1, 2009 · 8 comments

  1. #!/bin/bash
  2. # A simple shell script to backup dirs to tape drive.
  3. # -------------------------------------------------------------------------
  4. # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
  5. # This script is licensed under GNU GPL version 2.0 or above
  6. # -------------------------------------------------------------------------
  7. # This script is part of nixCraft shell script collection (NSSC)
  8. # Visit http://bash.cyberciti.biz/ for more information.
  9. # -------------------------------------------------------------------------
  10. MT=/bin/mt
  11. TAR=/bin/tar
  12. LOGGER=/usr/bin/logger
  13.  
  14. # What to backup.
  15. SOURCE_DIRS="/data /home /etc /root /www"
  16.  
  17. # Where to backup to.
  18. TAPE="/dev/st0"
  19.  
  20. # log message
  21. $LOGGER "Backing $SOURCE_DIRS to $TAPE @ $(date)"
  22.  
  23. # Rewind the tape
  24. $MT -f $TAPE rewind
  25.  
  26. # Backup the files
  27. $TAR czf $TAPE $SOURCE_DIRS
  28.  
  29. # Rewind and eject the tape
  30. $MT -f $TAPE rewoffl
  31.  
  32. # log message
  33. $LOGGER "Backup finished @ $(date)"


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • mathguy

    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.

  • somed000d

    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.

  • Ghyoom.com

    Nice, Thank You

  • chika.tambun

    how to backup automatically after the file created 6 month ago, without crontab?!

  • tdmurthy

    How to take incremental & differential backup in linux with crontab?

  • regan

    hi how can i view the logs using your script here? thanks

  • regan

    btw, is this also applicable to solaris 10?thanks

  • Antti M.

    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.

Previous Script:

Next Script: