dd Syntax
Here is a quick tip on how
to use the
dd command. (Other quick tips can be found
here.)
More detailed information about dd can be found in Chapter 3 of
Unix
Backup and Recovery.
Using dd and rsh/ssh as a conduit
between systems
Most other backup commands can
only read or write from stdin, whereas dd can do both at the same
time. This makes dd very versatile, and the only native backup
utility that can be used to pass a stream of data from one command to another,
or from one system to a device on another system, using rsh or ssh.
This can work either way.
Reading a backup on a remote
device
The restore, GNU tar,
and GNU
cpio commands can read the remote device by simply giving
it remote_host:remote_device
as the device name. However,
the native versions of tar and cpio do not support such an
option. Therefore, you need some way to do this with these commands.
You simply rsh a dd command to the remote system and read
its data stream on the local system:
# rsh remote_host
“dd
if=device ibs=blocksize”| tar xvBf –
Again, when reading a tape
volume using
dd, you normally have to specify a block size.
If you do not, it uses a block size of 512, which generates an I/O error
unless the tape volume was written with that block size. Also notice
the quotes around the remote dd command. In this command,
the quotes are actually not necessary, since the pipe is executed on the
local system. In other, more complicated commands, such as one where there
is a pipe to be executed on the remote system, quotes such as this around
the remote command make things work properly. (In this instance,
it merely makes it more readable.)
Writing a backup to a remote
device
This one is a bit trickier.
You may have to create a subshell with embedded rsh and dd commands,
and pipe the output of the local backup command to that:
# tar cvf - . | (rsh
remote_system
dd
of=device
obs=block_size)
Putting parentheses around
the remote command creates the subshell. Notice that you must specify
the remote block size, and you need to be careful when doing so.
If you want to create a volume that can be read by tar, make sure
you use a block size that tar can understand, such as 10240.
(This is usually the biggest block size
tar can read or write, and
this is done by specifying a blocking factor of 20 in tar.)
If you are not able to use rsh
If you are not able to use rsh,
you may look into use ssh as a drop-in replacement for rsh.
The ssh command uses a much more secure authentication mechanism,
and allows you to do the same type of commands as rsh does without
the security holes that rsh
brings. However, using the remote
device feature of GNU tar, GNU cpio, or dump assumes
the use of rsh. If you are not allowed to use rsh,
but can use ssh, you can use commands like the following to integrate
dump,
tar,
and
cpio with ssh.
To read tapes on remote hosts
# ssh remote_host
“dd
if=device bs=blocksize”| tar xvBf –
# ssh remote_host
“dd if=device bs=blocksize”| restore rvf -
# ssh remote_host
“dd if=device bs=blocksize”| cpio -itv
To create backup tapes on
remote hosts:
# dump 0bdsf 64 100000
100000 - | ssh
remote_host “dd of=device bs=64k”
# tar cvf - | ssh
remote_host
“dd
of=device
bs=10k”
# cpio -oacvB | ssh
remote_host
“dd of=device
bs=5k”
|