Linux Shell Script To Backup To Tape Drive

#!/bin/bash
# A simple shell script to backup dirs to tape drive.
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
MT=/bin/mt
TAR=/bin/tar
LOGGER=/usr/bin/logger
 
# What to backup. 
SOURCE_DIRS="/data /home /etc /root /www"
 
# Where to backup to.
TAPE="/dev/st0"
 
# log message
$LOGGER "Backing $SOURCE_DIRS to $TAPE @ $(date)"
 
# Rewind the tape
$MT -f $TAPE rewind
 
# Backup the files
$TAR czf $TAPE $SOURCE_DIRS
 
# Rewind and eject the tape
$MT -f $TAPE rewoffl
 
# log message 
$LOGGER "Backup finished @ $(date)"
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • Antti M. Jan 14, 2011 @ 20:33

    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.

  • regan Feb 8, 2010 @ 2:35

    btw, is this also applicable to solaris 10?thanks

  • regan Feb 8, 2010 @ 2:33

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

  • tdmurthy Jan 6, 2010 @ 15:16

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

  • chika.tambun Dec 12, 2009 @ 20:14

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

  • Ghyoom.com Nov 17, 2009 @ 3:25

    Nice, Thank You

  • mathguy Sep 18, 2009 @ 6:38

    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 Nov 3, 2009 @ 12:12

      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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.