6ba07a017c369c9725567811396a129c5e812d2d
[ikiwiki.git] / docs / handbook / handbook-backup-basics.mdwn
1 \r
2 \r
3 ## 12.10 Backup Basics \r
4 \r
5 The three major backup programs are [dump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#dump&section8), [tar(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=tar&section=1), and [cpio(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=cpio&section=1).\r
6 \r
7 ### 12.10.1 Dump and Restore \r
8 \r
9 The traditional UNIX® backup programs are `dump` and `restore`. They operate on the drive as a collection of disk blocks, below the abstractions of files, links and directories that are created by the file systems. `dump` backs up an entire file system on a device. It is unable to backup only part of a file system or a directory tree that spans more than one file system. `dump` does not write files and directories to tape, but rather writes the raw data blocks that comprise files and directories.\r
10 \r
11  **Note:** If you use `dump` on your root directory, you would not back up `/home`, `/usr` or many other directories since these are typically mount points for other file systems or symbolic links into those file systems.\r
12 \r
13 `dump` has quirks that remain from its early days in Version 6 of AT&T UNIX (circa 1975). The default parameters are suitable for 9-track tapes (6250 bpi), not the high-density media available today (up to 62,182 ftpi). These defaults must be overridden on the command line to utilize the capacity of current tape drives.\r
14 \r
15 It is also possible to backup data across the network to a tape drive attached to another computer with `rdump` and `rrestore`. Both programs rely upon `rcmd` and `ruserok` to access the remote tape drive. Therefore, the user performing the backup must be listed in the `.rhosts` file on the remote computer. The arguments to `rdump` and `rrestore` must be suitable to use on the remote computer. When `rdump`ing from a DragonFly computer to an Exabyte tape drive connected to a Sun called `komodo`, use:\r
16 \r
17     \r
18     # /sbin/rdump 0dsbfu 54000 13000 126 komodo:/dev/nsa8 /dev/da0a 2>&1\r
19 \r
20 \r
21 Beware: there are security implications to allowing `.rhosts` authentication. Evaluate your situation carefully.\r
22 \r
23 It is also possible to use `dump` and `restore` in a more secure fashion over `ssh`.\r
24 \r
25  **Example 12-1. Using `dump` over** ssh **** \r
26 \r
27     \r
28     # /sbin/dump -0uan -f - /usr | gzip -2 | ssh1 -c blowfish \\r
29               targetuser@targetmachine.example.com dd of=/mybigfiles/dump-usr-l0.gz\r
30 \r
31 \r
32 Or using `dump`'s built-in method, setting the enviroment variable `RSH`:\r
33 \r
34  **Example 12-2. Using `dump` over** ssh ** with `RSH` set** \r
35 \r
36     \r
37     # RSH=/usr/bin/ssh /sbin/dump -0uan -f targetuser@targetmachine.example.com:/dev/sa0\r
38 \r
39 \r
40 ### 12.10.2 `tar` \r
41 \r
42 [tar(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#tar&section1) also dates back to Version 6 of AT&T UNIX (circa 1975). `tar` operates in cooperation with the file system; `tar` writes files and directories to tape. `tar` does not support the full range of options that are available from [cpio(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=cpio&section=1), but `tar` does not require the unusual command pipeline that `cpio` uses.\r
43 \r
44 Most versions of `tar` do not support backups across the network. The GNU version of `tar`, which DragonFly utilizes, supports remote devices using the same syntax as `rdump`. To `tar` to an Exabyte tape drive connected to a Sun called `komodo`, use:\r
45 \r
46     \r
47     # /usr/bin/tar cf komodo:/dev/nsa8 . 2>&1\r
48 \r
49 \r
50 For versions without remote device support, you can use a pipeline and `rsh` to send the data to a remote tape drive.\r
51 \r
52     \r
53     # tar cf - . | rsh `***hostname***` dd of#`***tape-device***` obs20b\r
54 \r
55 \r
56 If you are worried about the security of backing up over a network you should use the `ssh` command instead of `rsh`.\r
57 \r
58 ### 12.10.3 `cpio` \r
59 \r
60 [cpio(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#cpio&section1) is the original UNIX file interchange tape program for magnetic media. `cpio` has options (among many others) to perform byte-swapping, write a number of different archive formats, and pipe the data to other programs. This last feature makes `cpio` an excellent choice for installation media. `cpio` does not know how to walk the directory tree and a list of files must be provided through `stdin`.\r
61 \r
62 `cpio` does not support backups across the network. You can use a pipeline and `rsh` to send the data to a remote tape drive.\r
63 \r
64     \r
65     # for f in `***directory_list; do***`\r
66     find $f >> backup.list\r
67     done\r
68     # cpio -v -o --format=newc < backup.list | ssh `***user***`@`***host***` "cat > `***backup_device***`"\r
69 \r
70 \r
71 Where `***directory_list***` is the list of directories you want to back up, `***user***`@`***host***` is the user/hostname combination that will be performing the backups, and `***backup_device***` is where the backups should be written to (e.g., `/dev/nsa0`).\r
72 \r
73 ### 12.10.4 `pax` \r
74 \r
75 [pax(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#pax&section1) is IEEE/POSIX®'s answer to `tar` and `cpio`. Over the years the various versions of `tar` and `cpio` have gotten slightly incompatible. So rather than fight it out to fully standardize them, POSIX created a new archive utility. `pax` attempts to read and write many of the various `cpio` and `tar` formats, plus new formats of its own. Its command set more resembles `cpio` than `tar`.\r
76 \r
77 ### 12.10.5  **Amanda**  \r
78 \r
79  **Amanda**  (Advanced Maryland Network Disk Archiver) is a client/server backup system, rather than a single program. An  **Amanda**  server will backup to a single tape drive any number of computers that have  **Amanda**  clients and a network connection to the  **Amanda**  server. A common problem at sites with a number of large disks is that the length of time required to backup to data directly to tape exceeds the amount of time available for the task.  **Amanda**  solves this problem.  **Amanda**  can use a ***holding disk*** to backup several file systems at the same time.  **Amanda**  creates ***archive sets***: a group of tapes used over a period of time to create full backups of all the file systems listed in  **Amanda** 's configuration file. The ***archive set*** also contains nightly incremental (or differential) backups of all the file systems. Restoring a damaged file system requires the most recent full backup and the incremental backups.\r
80 \r
81 The configuration file provides fine control of backups and the network traffic that  **Amanda**  generates.  **Amanda**  will use any of the above backup programs to write the data to tape.  **Amanda**  is available as either a port or a package, it is not installed by default.\r
82 \r
83 ### 12.10.6 Do Nothing \r
84 \r
85 ***Do nothing*** is not a computer program, but it is the most widely used backup strategy. There are no initial costs. There is no backup schedule to follow. Just say no. If something happens to your data, grin and bear it!\r
86 \r
87 If your time and your data is worth little to nothing, then ***Do nothing*** is the most suitable backup program for your computer. But beware, UNIX is a useful tool, you may find that within six months you have a collection of files that are valuable to you.\r
88 \r
89 ***Do nothing*** is the correct backup method for `/usr/obj` and other directory trees that can be exactly recreated by your computer. An example is the files that comprise the HTML or PostScript® version of this Handbook. These document formats have been created from SGML input files. Creating backups of the HTML or PostScript files is not necessary. The SGML files are backed up regularly.\r
90 \r
91 ### 12.10.7 Which Backup Program Is Best? \r
92 \r
93 [dump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#dump&section8) ***Period.*** Elizabeth D. Zwicky torture tested all the backup programs discussed here. The clear choice for preserving all your data and all the peculiarities of UNIX file systems is `dump`. Elizabeth created file systems containing a large variety of unusual conditions (and some not so unusual ones) and tested each program by doing a backup and restore of those file systems. The peculiarities included: files with holes, files with holes and a block of nulls, files with funny characters in their names, unreadable and unwritable files, devices, files that change size during the backup, files that are created/deleted during the backup and more. She presented the results at LISA V in Oct. 1991. Read the [***Torture-testing Backup and Archive Programs***](http://berdmann.dyndns.org/zwicky/testdump.doc.html) study for more information.\r
94 \r
95 ### 12.10.8 Emergency Restore Procedure \r
96 \r
97 #### 12.10.8.1 Before the Disaster \r
98 \r
99 There are only four steps that you need to perform in preparation for any disaster that may occur.\r
100 \r
101 First, print the disklabel from each of your disks (e.g. `disklabel da0 | lpr`), your file system table (`/etc/fstab`) and all boot messages, two copies of each.\r
102 \r
103 Second, determine that the boot and fix-it floppies (`boot.flp` and `fixit.flp`) have all your devices. The easiest way to check is to reboot your machine with the boot floppy in the floppy drive and check the boot messages. If all your devices are listed and functional, skip on to step three.\r
104 \r
105 Otherwise, you have to create two custom bootable floppies which have a kernel that can mount all of your disks and access your tape drive. These floppies must contain: `fdisk`, `disklabel`, `newfs`, `mount`, and whichever backup program you use. These programs must be statically linked. If you use `dump`, the floppy must contain `restore`.\r
106 \r
107 Third, create backup tapes regularly. Any changes that you make after your last backup may be irretrievably lost. Write-protect the backup tapes.\r
108 \r
109 Fourth, test the floppies (either `boot.flp` and `fixit.flp` or the two custom bootable floppies you made in step two.) and backup tapes. Make notes of the procedure. Store these notes with the bootable floppy, the printouts and the backup tapes. You will be so distraught when restoring that the notes may prevent you from destroying your backup tapes (How? In place of `tar xvf /dev/sa0`, you might accidentally type `tar cvf /dev/sa0` and over-write your backup tape).\r
110 \r
111 For an added measure of security, make bootable floppies and two backup tapes each time. Store one of each at a remote location. A remote location is NOT the basement of the same office building. A number of firms in the World Trade Center learned this lesson the hard way. A remote location should be physically separated from your computers and disk drives by a significant distance.\r
112 \r
113 ***'Example 12-3. A Script for Creating a Bootable Floppy***'\r
114 \r
115     \r
116     #!/bin/sh\r
117     #\r
118     # create a restore floppy\r
119     #\r
120     # format the floppy\r
121     #\r
122     PATH=/bin:/sbin:/usr/sbin:/usr/bin\r
123     \r
124     fdformat -q fd0\r
125     if [ $? -ne 0 ]\r
126     then\r
127          echo "Bad floppy, please use a new one"\r
128          exit 1\r
129     fi\r
130     \r
131     # place boot blocks on the floppy\r
132     #\r
133     disklabel -w -B /dev/fd0c fd1440\r
134     \r
135     #\r
136     # newfs the one and only partition\r
137     #\r
138     newfs -t 2 -u 18 -l 1 -c 40 -i 5120 -m 5 -o space /dev/fd0a\r
139     \r
140     #\r
141     # mount the new floppy\r
142     #\r
143     mount /dev/fd0a /mnt\r
144     \r
145     #\r
146     # create required directories\r
147     #\r
148     mkdir /mnt/dev\r
149     mkdir /mnt/bin\r
150     mkdir /mnt/sbin\r
151     mkdir /mnt/etc\r
152     mkdir /mnt/root\r
153     mkdir /mnt/mnt                      # for the root partition\r
154     mkdir /mnt/tmp\r
155     mkdir /mnt/var\r
156     \r
157     #\r
158     # populate the directories\r
159     #\r
160     if [ ! -x /sys/compile/MINI/kernel ]\r
161     then\r
162          cat << EOM\r
163     The MINI kernel does not exist, please create one.\r
164     Here is an example config file:\r
165     #\r
166     # MINI -- A kernel to get &os; onto a disk.\r
167     #\r
168     machine         "i386"\r
169     cpu             "I486_CPU"\r
170     ident           MINI\r
171     maxusers        5\r
172     \r
173     options         INET                    # needed for _tcp _icmpstat _ipstat\r
174                                             #            _udpstat _tcpstat _udb\r
175     options         FFS                     #Berkeley Fast File System\r
176     options         FAT_CURSOR              #block cursor in syscons or pccons\r
177     options         SCSI_DELAY=15           #Be pessimistic about Joe SCSI device\r
178     options         NCONS=2                 #1 virtual consoles\r
179     options         USERCONFIG              #Allow user configuration with -c XXX\r
180     \r
181     config          kernel      root on da0 swap on da0 and da1 dumps on da0\r
182     \r
183     device          isa0\r
184     device          pci0\r
185     \r
186     device          fdc0        at isa? port "IO_FD1" bio irq 6 drq 2 vector fdintr\r
187     device          fd0 at fdc0 drive 0\r
188     \r
189     device          ncr0\r
190     \r
191     device          scbus0\r
192     \r
193     device          sc0 at isa? port "IO_KBD" tty irq 1 vector scintr\r
194     device          npx0        at isa? port "IO_NPX" irq 13 vector npxintr\r
195     \r
196     device          da0\r
197     device          da1\r
198     device          da2\r
199     \r
200     device          sa0\r
201     \r
202     pseudo-device   loop            # required by INET\r
203     pseudo-device   gzip            # Exec gzipped a.out's\r
204     EOM\r
205          exit 1\r
206     fi\r
207     \r
208     cp -f /sys/compile/MINI/kernel /mnt\r
209     \r
210     gzip -c -best /sbin/init > /mnt/sbin/init\r
211     gzip -c -best /sbin/fsck > /mnt/sbin/fsck\r
212     gzip -c -best /sbin/mount > /mnt/sbin/mount\r
213     gzip -c -best /sbin/halt > /mnt/sbin/halt\r
214     gzip -c -best /sbin/restore > /mnt/sbin/restore\r
215     \r
216     gzip -c -best /bin/sh > /mnt/bin/sh\r
217     gzip -c -best /bin/sync > /mnt/bin/sync\r
218     \r
219     cp /root/.profile /mnt/root\r
220     \r
221     cp -f /dev/MAKEDEV /mnt/dev\r
222     chmod 755 /mnt/dev/MAKEDEV\r
223     \r
224     chmod 500 /mnt/sbin/init\r
225     chmod 555 /mnt/sbin/fsck /mnt/sbin/mount /mnt/sbin/halt\r
226     chmod 555 /mnt/bin/sh /mnt/bin/sync\r
227     chmod 6555 /mnt/sbin/restore\r
228     \r
229     #\r
230     # create the devices nodes\r
231     #\r
232     cd /mnt/dev\r
233     ./MAKEDEV std\r
234     ./MAKEDEV da0\r
235     ./MAKEDEV da1\r
236     ./MAKEDEV da2\r
237     ./MAKEDEV sa0\r
238     ./MAKEDEV pty0\r
239     cd /\r
240     \r
241     #\r
242     # create minimum file system table\r
243     #\r
244     cat > /mnt/etc/fstab <<EOM\r
245     /dev/fd0a    /    ufs    rw  1  1\r
246     EOM\r
247     \r
248     #\r
249     # create minimum passwd file\r
250     #\r
251     cat > /mnt/etc/passwd <<EOM\r
252     root:*:0:0:Charlie &:/root:/bin/sh\r
253     EOM\r
254     \r
255     cat > /mnt/etc/master.passwd <<EOM\r
256     root::0:0::0:0:Charlie &:/root:/bin/sh\r
257     EOM\r
258     \r
259     chmod 600 /mnt/etc/master.passwd\r
260     chmod 644 /mnt/etc/passwd\r
261     /usr/sbin/pwd_mkdb -d/mnt/etc /mnt/etc/master.passwd\r
262     \r
263     #\r
264     # umount the floppy and inform the user\r
265     #\r
266     /sbin/umount /mnt\r
267     echo "The floppy has been unmounted and is now ready."\r
268 \r
269 \r
270 #### 12.10.8.2 After the Disaster \r
271 \r
272 The key question is: did your hardware survive? You have been doing regular backups so there is no need to worry about the software.\r
273 \r
274 If the hardware has been damaged, the parts should be replaced before attempting to use the computer.\r
275 \r
276 If your hardware is okay, check your floppies. If you are using a custom boot floppy, boot single-user (type `-s` at the boot: prompt). Skip the following paragraph.\r
277 \r
278 If you are using the `boot.flp` and `fixit.flp` floppies, keep reading. Insert the `boot.flp` floppy in the first floppy drive and boot the computer. The original install menu will be displayed on the screen. Select the `Fixit--Repair mode with CDROM or floppy.` option. Insert the `fixit.flp` when prompted. `restore` and the other programs that you need are located in `/mnt2/stand`.\r
279 \r
280 Recover each file system separately.\r
281 \r
282 Try to `mount` (e.g. `mount /dev/da0a /mnt`) the root partition of your first disk. If the disklabel was damaged, use `disklabel` to re-partition and label the disk to match the label that you printed and saved. Use `newfs` to re-create the file systems. Re-mount the root partition of the floppy read-write (`mount -u -o rw /mnt`). Use your backup program and backup tapes to recover the data for this file system (e.g. `restore vrf /dev/sa0`). Unmount the file system (e.g. `umount /mnt`). Repeat for each file system that was damaged.\r
283 \r
284 Once your system is running, backup your data onto new tapes. Whatever caused the crash or data loss may strike again. Another hour spent now may save you from further distress later.\r
285 \r
286 \r
287 \r
288 CategoryHandbook\r
289 CategoryHandbook-storage\r