Difference between revisions of "Mt"

From Christoph's Personal Wiki
Jump to: navigation, search
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{lowercase|mt}}
 
 
'''mt''' is a [[:Category:Linux Command Line Tools|command]] used to control and backup data onto magnetic tapes.
 
'''mt''' is a [[:Category:Linux Command Line Tools|command]] used to control and backup data onto magnetic tapes.
  
== Example usage ==
+
Consult the man pages for <tt>mt</tt> and <tt>st</tt> for extended information. Also, make sure the modules for <tt>st</tt> have been loaded with <tt>lsmod</tt>.
 +
 
 +
==Example usage==
 
''Note: The default device name should be <code>/dev/st0</code> (i.e. first SCSI tape device).''
 
''Note: The default device name should be <code>/dev/st0</code> (i.e. first SCSI tape device).''
  
 
* Rewind tape drive:
 
* Rewind tape drive:
  % mt -f /dev/st0 rewind
+
  $ mt -f /dev/st0 rewind
  
* Backup directory /data and /home with [[Tar (command)|tar]] command (z - compressed):
+
* Backup directory /data and /home with [[Tar (command)|tar]] command (z - compressed; note the <code>/dev/nst0</code>; '<code>nst0</code>' ''not'' '<code>st0</code>'):
  % tar -czf /dev/st0 /data /home
+
  $ tar -czf /dev/st0 /data /home
 +
$ #~OR~
 +
$ tar --index-file=foo.log -jcvf /dev/nst0 /data /home
 +
$ #~OR~
 +
$ tar -jcvf /dev/nst0 /data /home 1>stdout 2>stderr  # Using Bash shell
 +
$ #~OR~
 +
$ tar -jcvf /dev/nst0 --label="Backup - `date '+%Y-%m-%d'` - /home" /home 1>stdout 2>stderr
  
 
* Return ("tell") current block:
 
* Return ("tell") current block:
  % mt -f /dev/st0 tell
+
  $ mt -f /dev/st0 tell
  
 
* Display list of files on tape drive:
 
* Display list of files on tape drive:
  % tar -tzf /dev/st0
+
  $ tar -tzf /dev/st0
 +
$ #~OR~
 +
$ tar -tvf /dev/st0
  
 
* Restore /data directory:
 
* Restore /data directory:
  % cd /
+
  $ cd /
  % mt -f /dev/st0 rewind
+
  $ mt -f /dev/st0 rewind
  % tar -xzf /dev/st0 data
+
  $ tar -xzf /dev/st0 data
  
 
* Unload (i.e. enable eject) the tape:
 
* Unload (i.e. enable eject) the tape:
  % mt -f /dev/st0 offline
+
  $ mt -f /dev/st0 offline
  
 
* Display status information about the tape unit:
 
* Display status information about the tape unit:
  % mt -f /dev/st0 status
+
  $ mt -f /dev/st0 status
  
 
* Erase the tape:
 
* Erase the tape:
  % mt -f /dev/st0 erase
+
  $ mt -f /dev/st0 erase
  
 
* Go to end of data:
 
* Go to end of data:
  % mt -f /dev/nst0 eod
+
  $ mt -f /dev/nst0 eod
  
 
* Goto previous record:
 
* Goto previous record:
  % mt -f /dev/nst0 bsfm 1
+
  $ mt -f /dev/nst0 bsfm 1
  
 
* Forward record:
 
* Forward record:
  % mt -f /dev/nst0 fsf 1
+
  $ mt -f /dev/nst0 fsf 1
  
=== Backup via ssh ===
+
===Hardware compression===
  % tar zcvf - /data | ssh root@www.example.com "cat > /backup/data.tar.gz"
+
* Turn on hardware compression:
 +
$ mt -f /dev/st0 compression 1
 +
 
 +
* Turn on a number of other options that can speed up the tape drive (see the man page for mt for more details):
 +
$ mt -f /dev/st0 stoptions buffer-writes read-ahead async-writes scsi2logical can-bsr auto-lock
 +
 
 +
* Turn on buffered operation for the drive:
 +
$ mt -f /dev/st0 drvbuffer 1
 +
 
 +
===Backup via ssh===
 +
  $ tar zcvf - /data | ssh root@www.example.com "cat > /backup/data.tar.gz"
  
 
* Or, using the [[Dd (command)|dd]] command:
 
* Or, using the [[Dd (command)|dd]] command:
  % tar cvzf - /data | ssh root@www.example.com "dd of=/backup/data.tar.gz"
+
  $ tar cvzf - /data | ssh root@www.example.com "dd of=/backup/data.tar.gz"
  
 
* Or, backup to a remote tape device:
 
* Or, backup to a remote tape device:
  % tar cvzf - /data | ssh root@www.example.com "cat > /dev/nst0"
+
  $ tar cvzf - /data | ssh root@www.example.com "cat > /dev/nst0"
  
 
* Also, using the <tt>mt</tt> command to rewind the tape and then dump to it:
 
* Also, using the <tt>mt</tt> command to rewind the tape and then dump to it:
  % tar cvzf - /data | ssh root@www.example.com $(mt -f /dev/nst0 rewind; cat > /dev/nst0)$
+
  $ tar cvzf - /data | ssh root@www.example.com $(mt -f /dev/nst0 rewind; cat > /dev/nst0)$
  
 
* Finally, restore the data over a ssh session:
 
* Finally, restore the data over a ssh session:
  % ssh root@www.example.com "cat /backup/data.tar.gz" | tar zxvf -
+
  $ ssh root@www.example.com "cat /backup/data.tar.gz" | tar zxvf -
  
=== Miscellaneous commands ===
+
===Miscellaneous commands===
 
* Eject the tape (or CDROM, DVD, etc):
 
* Eject the tape (or CDROM, DVD, etc):
  % eject /media/cdrom
+
  $ eject /media/cdrom
  
 
* Close the tray:
 
* Close the tray:
  % eject -t /media/cdrom
+
  $ eject -t /media/cdrom
  
 
* Exclude certain files from a tar archive:
 
* Exclude certain files from a tar archive:
  % tar -zcvf /home/backup.tar.gz --exclude='foo' --exclude='bar' /home/bob
+
  $ tar -zcvf /home/backup.tar.gz --exclude='foo' --exclude='bar' /home/bob
  
 
* Or, list files to exclude in a file (one filename per line):
 
* Or, list files to exclude in a file (one filename per line):
  % tar -zcvf /home/backup.tar.gz -X exclude.txt /home/bob
+
  $ tar -zcvf /home/backup.tar.gz -X exclude.txt /home/bob
 +
 
 +
==Backup script (example)==
 +
''Note: Taken from http://wiki.novell.com/index.php/Nbackup''
 +
<pre>
 +
#!/bin/bash
 +
rm /var/log/nightly-backup.*
 +
echo "@Backup Begins ====================" > /var/log/nightly-backup.log
 +
date >> /var/log/nightly-backup.log
 +
date > /var/log/nightly-backup.errors
 +
mt -f /dev/nst0 rewind >> /var/log/nightly-backup.log 2>> /var/log/nightly-backup.errors
 +
echo "-- System backup" >> /var/log/nightly-backup.log
 +
tar cvf /dev/nst0 --label="System Backup - `date '+%d-%B-%Y'`" \
 +
    --totals -X /etc/backup.excludes / \
 +
    >> /var/log/nightly-backup.log 2>> /var/log/nightly-backup.errors
 +
echo "-- NSS Backup" >> /var/log/nightly-backup.log
 +
/opt/novell/sms/bin/nbackup -cvf /dev/nst0 \
 +
    --label="NSS Backup - `date '+%d-%B-%Y'`" \
 +
    -U local-linux-admin-user \
 +
    -P password /media/nss/MOUNTPOINT/ \
 +
    >> /var/log/nightly-backup.log \
 +
    2>> /var/log/nightly-backup.nss
 +
echo "-- Rewinding and Ejecting Tape" >> /var/log/nightly-backup.log
 +
mt -f /dev/nst0 rewoff >> /var/log/nightly-backup.log 2>> /var/log/nightly-backup.errors
 +
date >> /var/log/nightly-backup.log
 +
echo "@Backup Ends ====================" >> /var/log/nightly-backup.log
 +
</pre>
  
== Linux tape drives naming conventions ==
+
==Linux tape drives naming conventions==
=== SCSI tape device names ===
+
===SCSI tape device names===
 
The <code>st</code> driver provides the interface to a variety of SCSI tape devices under Linux.
 
The <code>st</code> driver provides the interface to a variety of SCSI tape devices under Linux.
  
* First (auto rewind) SCSI tape device name: /dev/st0
+
*First (auto rewind) SCSI tape device name: /dev/st0
* Second (auto rewind) SCSI tape device name: /dev/st1
+
*Second (auto rewind) SCSI tape device name: /dev/st1
* First the non-rewind SCSI tape devices: /dev/nst0
+
*First the non-rewind SCSI tape devices: /dev/nst0
* Second the non-rewind SCSI tape devices: /dev/nst1
+
*Second the non-rewind SCSI tape devices: /dev/nst1
  
=== IDE tape device names ===
+
===IDE tape device names===
 
The <code>ht</code> driver provides the interface to a variety of IDE tape devices under Linux.
 
The <code>ht</code> driver provides the interface to a variety of IDE tape devices under Linux.
  
* First (auto rewind) IDE tape device name: /dev/ht0
+
*First (auto rewind) IDE tape device name: /dev/ht0
* Second (auto rewind) IDE tape device name: /dev/ht1
+
*Second (auto rewind) IDE tape device name: /dev/ht1
* First the non-rewind IDE tape devices: /dev/nht0
+
*First the non-rewind IDE tape devices: /dev/nht0
* Second the non-rewind IDE tape devices: /dev/nht1
+
*Second the non-rewind IDE tape devices: /dev/nht1
  
=== Main tape types ===
+
===Main tape types===
* Digital Data Storage (DDS);
+
*Digital Data Storage (DDS);
* Digital Audio Tape (DAT); and
+
*Digital Audio Tape (DAT); and
* Digital Linear Tape (DLT)
+
*Digital Linear Tape (DLT)
  
== See also ==
+
==See also==
* [[Tar (command)|tar]]
+
*[[tar]]
 +
*[[rsync]]
  
== External links ==
+
==External links==
* [http://www.cyberciti.biz/faq/linux-tape-backup-with-mt-and-tar-command-howto/ Linux tape backup with mt and tar command - howto]
+
*{{man|1|tar|The GNU version of the tar archiving utility}}
* [http://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/ Howto: Use tar command through network over ssh session]
+
===Tutorials===
* [http://www.cyberciti.biz/faq/tape-drives-naming-convention-under-linux/ Tape drives naming convention under Linux]
+
*[http://www.cyberciti.biz/faq/linux-tape-backup-with-mt-and-tar-command-howto/ Linux tape backup with mt and tar command - howto]
* [http://nixcraft.com/setting-up-raid-1-mirroring-on-a-running-remote-linux-system-vt472.html Howto: Setting up RAID 1 mirroring on a running remote Linux system over ssh connection]
+
*[http://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/ Howto: Use tar command through network over ssh session]
* [http://www.cyberciti.biz/faq/how-do-i-rotate-log-files/ How do I rotate log files?]
+
*[http://www.cyberciti.biz/faq/tape-drives-naming-convention-under-linux/ Tape drives naming convention under Linux]
* [http://bash.cyberciti.biz/backup/encryptftpupload.bash.php Backup shell script to backup selected directories and upload securely (gpg) to FTP server]
+
*[http://nixcraft.com/setting-up-raid-1-mirroring-on-a-running-remote-linux-system-vt472.html Howto: Setting up RAID 1 mirroring on a running remote Linux system over ssh connection]
* [http://bash.cyberciti.biz/backup/mybackup.php http://bash.cyberciti.biz/backup/mybackup.php]
+
*[http://www.cyberciti.biz/faq/how-do-i-rotate-log-files/ How do I rotate log files?]
 +
*[http://bash.cyberciti.biz/backup/encryptftpupload.bash.php Backup shell script to backup selected directories and upload securely (gpg) to FTP server]
 +
*[http://bash.cyberciti.biz/backup/mybackup.php Shell script to backup directories & files from your home directory and email them as .tar.gz file]
 +
*[http://www.cyberciti.biz/faq/how-do-i-use-cpio-command-under-linux/ How do I use cpio command under Linux?]
 +
*[http://www.howtoforge.com/linux_rdiff_backup Automated Backups With rdiff-backup]
 +
*[http://wiki.novell.com/index.php/Nbackup Backup / Restore Using NBACKUP and TAR]
 +
*[http://www.dbaoncall.net/references/ht_tar.html How to use TAR]
 +
*[http://en.wikipedia.org/wiki/TAR_file_format TAR file format]
 +
*[http://www.ociw.edu/lco/computer_info/DAT.html How to Write a DAT Tape on Linux]
 +
*[http://www.linuxdevcenter.com/pub/a/linux/lpt/13_01.html Using Standard Input and Output]
  
 
{{linux commands}}
 
{{linux commands}}
  
 
[[Category:Linux Command Line Tools]]
 
[[Category:Linux Command Line Tools]]

Latest revision as of 08:58, 17 February 2016

mt is a command used to control and backup data onto magnetic tapes.

Consult the man pages for mt and st for extended information. Also, make sure the modules for st have been loaded with lsmod.

Example usage

Note: The default device name should be /dev/st0 (i.e. first SCSI tape device).

  • Rewind tape drive:
$ mt -f /dev/st0 rewind
  • Backup directory /data and /home with tar command (z - compressed; note the /dev/nst0; 'nst0' not 'st0'):
$ tar -czf /dev/st0 /data /home
$ #~OR~
$ tar --index-file=foo.log -jcvf /dev/nst0 /data /home
$ #~OR~
$ tar -jcvf /dev/nst0 /data /home 1>stdout 2>stderr  # Using Bash shell
$ #~OR~
$ tar -jcvf /dev/nst0 --label="Backup - `date '+%Y-%m-%d'` - /home" /home 1>stdout 2>stderr
  • Return ("tell") current block:
$ mt -f /dev/st0 tell
  • Display list of files on tape drive:
$ tar -tzf /dev/st0
$ #~OR~
$ tar -tvf /dev/st0
  • Restore /data directory:
$ cd /
$ mt -f /dev/st0 rewind
$ tar -xzf /dev/st0 data
  • Unload (i.e. enable eject) the tape:
$ mt -f /dev/st0 offline
  • Display status information about the tape unit:
$ mt -f /dev/st0 status
  • Erase the tape:
$ mt -f /dev/st0 erase
  • Go to end of data:
$ mt -f /dev/nst0 eod
  • Goto previous record:
$ mt -f /dev/nst0 bsfm 1
  • Forward record:
$ mt -f /dev/nst0 fsf 1

Hardware compression

  • Turn on hardware compression:
$ mt -f /dev/st0 compression 1
  • Turn on a number of other options that can speed up the tape drive (see the man page for mt for more details):
$ mt -f /dev/st0 stoptions buffer-writes read-ahead async-writes scsi2logical can-bsr auto-lock
  • Turn on buffered operation for the drive:
$ mt -f /dev/st0 drvbuffer 1

Backup via ssh

$ tar zcvf - /data | ssh root@www.example.com "cat > /backup/data.tar.gz"
  • Or, using the dd command:
$ tar cvzf - /data | ssh root@www.example.com "dd of=/backup/data.tar.gz"
  • Or, backup to a remote tape device:
$ tar cvzf - /data | ssh root@www.example.com "cat > /dev/nst0"
  • Also, using the mt command to rewind the tape and then dump to it:
$ tar cvzf - /data | ssh root@www.example.com $(mt -f /dev/nst0 rewind; cat > /dev/nst0)$
  • Finally, restore the data over a ssh session:
$ ssh root@www.example.com "cat /backup/data.tar.gz" | tar zxvf -

Miscellaneous commands

  • Eject the tape (or CDROM, DVD, etc):
$ eject /media/cdrom
  • Close the tray:
$ eject -t /media/cdrom
  • Exclude certain files from a tar archive:
$ tar -zcvf /home/backup.tar.gz --exclude='foo' --exclude='bar' /home/bob
  • Or, list files to exclude in a file (one filename per line):
$ tar -zcvf /home/backup.tar.gz -X exclude.txt /home/bob

Backup script (example)

Note: Taken from http://wiki.novell.com/index.php/Nbackup

#!/bin/bash
rm /var/log/nightly-backup.*
echo "@Backup Begins ====================" > /var/log/nightly-backup.log
date >> /var/log/nightly-backup.log
date > /var/log/nightly-backup.errors
mt -f /dev/nst0 rewind >> /var/log/nightly-backup.log 2>> /var/log/nightly-backup.errors
echo "-- System backup" >> /var/log/nightly-backup.log
tar cvf /dev/nst0 --label="System Backup - `date '+%d-%B-%Y'`" \
     --totals -X /etc/backup.excludes / \
     >> /var/log/nightly-backup.log 2>> /var/log/nightly-backup.errors
echo "-- NSS Backup" >> /var/log/nightly-backup.log
/opt/novell/sms/bin/nbackup -cvf /dev/nst0 \
     --label="NSS Backup - `date '+%d-%B-%Y'`" \
     -U local-linux-admin-user \
     -P password /media/nss/MOUNTPOINT/ \
     >> /var/log/nightly-backup.log \
     2>> /var/log/nightly-backup.nss
echo "-- Rewinding and Ejecting Tape" >> /var/log/nightly-backup.log
mt -f /dev/nst0 rewoff >> /var/log/nightly-backup.log 2>> /var/log/nightly-backup.errors
date >> /var/log/nightly-backup.log
echo "@Backup Ends ====================" >> /var/log/nightly-backup.log

Linux tape drives naming conventions

SCSI tape device names

The st driver provides the interface to a variety of SCSI tape devices under Linux.

  • First (auto rewind) SCSI tape device name: /dev/st0
  • Second (auto rewind) SCSI tape device name: /dev/st1
  • First the non-rewind SCSI tape devices: /dev/nst0
  • Second the non-rewind SCSI tape devices: /dev/nst1

IDE tape device names

The ht driver provides the interface to a variety of IDE tape devices under Linux.

  • First (auto rewind) IDE tape device name: /dev/ht0
  • Second (auto rewind) IDE tape device name: /dev/ht1
  • First the non-rewind IDE tape devices: /dev/nht0
  • Second the non-rewind IDE tape devices: /dev/nht1

Main tape types

  • Digital Data Storage (DDS);
  • Digital Audio Tape (DAT); and
  • Digital Linear Tape (DLT)

See also

External links

Tutorials

Linux command line programs
File and file system management: cat | cd | chmod | chown | chgrp | umask | cp | du | df | file | fsck | ln | ls | lsof | mkdir | more | mount | mv | pwd | rcp | rm | rmdir | split | touch | tree
Process management: anacron | at | chroot | cron/crontab | kill | nice | ps | sleep | screen | time | timex | top | nice/renice | wait
User Management/Environment: env | finger | id | locale | mesg | passwd | su | sudo | uname | uptime | w | wall | who | write
Text processing: awk | cut | diff | ex | head | tac | tee | iconv | join | less | more | paste | sed | sort | tail | tr | uniq | wc | xargs | perl
Shell programming: echo | expr | unset Printing: lp
Communications:
inetd | netstat | ping | rlogin | traceroute
Searching:

find | grep/egrep/fgrep | strings

Miscellaneous:

banner | bc | cal | man | yes