Tuesday, May 20, 2014

Linux Shell Script To Backup To Tape Drive

  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)"

0 comments: