18 Backup strategy “He who does not plan for failure, plans to fail ”
18.1.4 Backup solutions
Apart from taper (taper T file f backupfile.tar), a number of packaged backup solutions exist. More than simply making a copy of your data, these tools may provide management of the backup process as well as tracking tapes with a database to make it easy to determine which tape has the latest version of a certain file.
Amanda
The Advanced Maryland Automatic Network Disk Archiver is a sophisticated backup management tool. Amanda is free software and makes use of the dump command to perform the actual backups. Arkeia Arkeia is a commercial backup solution from Knox software. Arkeia has a pleasant easy to use Java client to manage the server which actually performs the tapebackups. Arkeia is designed to work with tapes in a large system environment. mkcdrec This tool creates a complete image of your filesystem onto CDs. This is useful for a full backup, especially if it can be contained on a single CD. The image that mkcdrec creates is a bootable system that can reinstall the system as it was.
18.1.5 Partition and filesystem recovery tools
If you have a corrupted system, it is not always necessary to resort to backups (although it is by far preferable to have a backup available). badblocks badblocks finds bad (unreliable) blocks on a specified partition. It is normally used like this:The “badblocklist” file is then passed to an appropriate filesystem tool (e.g. mkfs). Usually, however, badblocks is not run directly, but is invoked with the correct block size by the c
option to fsck.
fsck – file system check
fsck is a file system integrity scanner and repair tool. There is a version of fsck for each disk filesystem that Linux supports. fsck is run on every file system that has a nonzero entry in the sixth field of /etc/fstab at boot time. If the filesystem was not unmounted cleanly or a certain time period has passed since the last time fsck will check the filesystem thoroughly. If a fault is detected which requires intervention, the file system will be mounted readonly15 and the user forced to login as root and run fsck manually. fsck is normally used as follows: fsck /dev/hda1 Useful options include a Check all filesystems, and automatically repair without asking questions. This option is used at boot time. Note some errors cannot be repaired automatically, since they involve questions about what to do with apparently corrupted data.
A Use /etc/fstab to determine what to check. This option is used at startup. s Serialise This option is used when you wish to run fsck manually on a number of file systems. dumpe2fs – display “valuable” information dumpe2fs displays information about the structure of the e2fs file system. This information is useful if the superblock is overwritten or corrupted.
foo:~ # dumpe2fs /dev/hda3 | head
dumpe2fs 1.27 (8-Mar-2002) Filesystem volume name: HOME
Last mounted on: <not available>
Filesystem UUID: ad6b0e85-3d19-4162-a078-8e40856e4e5a Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal filetype needs_recovery sparse_super
Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 515072
There’s more information than that – including the location of alternative superblocks. 15 It is a Bad IdeaTM to fsck a filesystem which is mounted readwrite.
18 Backup strategy LPI 102 Course Notes 117 Using a rescue disk If a file system or disk boot record is somehow damaged such that the system will not boot, a rescue disk is needed. This disk will boot up a minimal file system with the root partition being a RAM disk. You will then be able to perform whatever maintenance tasks are needed on the file system, if it is still there. Most distributions have a rescue disk image available on the installation media. sfdisk – partition table manipulator
sfdisk is similar to fdisk, but can act in an automated way. sfdisk provides method of saving and restoring partition table information. The option that does this is d (dump the partitions of a device in a format useful as input to sfdisk).
For example, the following commands will write and read the partition table from a file on a floppy disk.
sfdisk -d /dev/hda > /media/floppy/hda.out sfdisk /dev/hda < /media/floppy/hda.out
Of course, using sfdisk on a system which has already been partitioned can be fatal.
gpart – guess partitions
gpart is a tool to try and restore a damaged partition table. It does this by making fake partitions and then attempting to mount these partitions as filesystems. If you overwrote your partition table with sfdisk by following the text above, you will need to use gpart to recover your original partition table.
# gpart /dev/hda
18.2 Review
Quiz questions
1. What are the differences between cpio, dd, dump/restore and tar? 2. What is the syntax for the dd command?
3. Under what circumstance should you use cpio in preference to tar? 4. Which files configure the behaviour of dump? 5. Which commands are capable of backing up a filesystem to tape. 6. What will the following command do? tar cjvf file / Assignment Make a minimal backup of your system. Test whether this backup works by wiping your system clean and then restoring from the backup. Is your backup practical? How can it be improved?
Answers to quiz questions
1. cpio takes a list of files from standard input, while tar takes its list of files as command line parameters. dd reads any form of data, while dump reads only a filesystem. You can also compare the number of letters in each command (2 for dd, 3 for tar, 4 for cpio and dump
and 7 for restore).
2. dd if=inputfile of=outputfile (and more)
3. You would use cpio to read a cpio archive (duh). cpio has a copypass function that you may like to use for copying. For certain types of media errors, cpio can be more robust. 4. /etc/fstab (and /etc/dumpdate, to a small extent)
5. tar, cpio, dd, dump
6. Create a bzip2 compressed tar archive named './file' containing all files in the filesystem (including /proc). It will print file names as it proceeds.
19 System time LPI 102 Course Notes 119
19 System time
time flies you cannot they pass by at such irregular intervals – a punctuation puzzleLPIC topic 1.111.6 — Maintain system time [4]
Weight: 4 Objective Candidate should be able to properly maintain the system time and synchronize the clock over NTP. Tasks include setting the system date and time, setting the BIOS clock to the correct time in UTC, configuring the correct timezone for the system and configuring the system to correct clock drift to match NTP clock. Key files, terms, and utilities include date Show or set the system software clock hwclock Manipulate the hardware clock ntpd Network Time Protocol Daemon ntpdate Set clock via NTP protocol /usr/share/zoneinfo Time zone definition files /etc/timezone Text version of current timezone on some distributions /etc/localtime Local time zone selection /etc/ntp.conf ntpd configuration file /etc/ntp.drift The rate at which your clock drifts from the real time19.1 Setting the clock
When Linux boots up, it obtains the current system time from the battery backedup hardware clock, and sets the system clock, which is maintained by the CPU. The system clock is used as the time reference for all applications. dateThe program date is used to access the system clock, and it can also be used to set it.
bar:~ $ date
Wed Jun 18 15:51:09 SAST 2003
The date command will also display the date in a particular format – the format is described in a parameter starting “+”.
bar:~ $ date '+%D %T'
06/18/03 15:51:20
bar:~ $ date '+%H:%M:%S %Y/%m/%d'
15:51:44 2003/06/18
You can display a different date to the current date
foo:~ $ date -d 'yesterday'
foo:~ $ date -d '2 months ago'
Fri Apr 18 15:53:52 SAST 2003 foo:~ $ date -d '16 jun 2001'
Sat Jun 16 00:00:00 SAST 2001
foo:~ $ date -d '16 jun 2001 12:55:01'
Sat Jun 16 12:55:01 SAST 2001
foo:~ $ date -d '16 jun 1965 12:55:01'
date: invalid date `16 jun 1965 12:55:1' foo:~ $ date -u -d '1 jan 2039'
date: invalid date `1 jan 2039'
You may wonder why date can't display dates before 1960, or much after 18 January 2038 or so (your implementation's limits may vary). The reason for this is that the beginning of time, according to many Linux applications, was 00h00, 1 January 1970 (GMT). The internal representation of time in these applications is the number of seconds that have passed since then (since Unix time began), and only 32 significant bits are allowed.
date can display the date of a particular file too.
foo:~ $ date -r /lib/ld.so
Mon Oct 30 13:52:51 SAST 2000 hwclock
The hwclock command manipulates the hardware clock – the same clock that the BIOS setup program will allow you to adjust. When you change the system clock using date the hardware clock is not affected.
foo:~ # hwclock
Fri 27 Jun 2003 14:01:24 SAST -0.462635 seconds foo:~ # hwclock --help
hwclock - query and set the hardware clock (RTC) Usage: hwclock [function] [options...]
Functions:
--set set the rtc to the time given with --date --hctosys set the system time from the hardware clock
--systohc set the hardware clock to the current system time --adjust adjust the rtc to account for systematic drift since the clock was last set or adjusted
Options:
--utc the hardware clock is kept in coordinated universal time
--localtime the hardware clock is kept in local time
--directisa access the ISA bus directly instead of /dev/rtc --date specifies the time to which to set the hardware
clock
--noadjfile do not access /etc/adjtime. Requires the use of either --utc or –localtime
There are two ways to use the hardware clock. The hardware clock can either be set to local time in your current time zone, or it can be set to UTC. It is preferable to set the hardware clock to UTC, since this means that when you visit another timezone, you only configure your
19 System time LPI 102 Course Notes 121
time zone, and not your system clock too.
When you boot your system, the value of the hardware clock is copied to the system clock using one of the following commands:
hwclock --hctosys --utc # BIOS clock is UTC
hwclock --hctosys --localtime # BIOS clock is local time
To configure your distribution to use the correct one of these you will need to modify one of the following files to set the system time with the appropriate offset (depending on which distribution it is)
/etc/sysconfig/clock # Redhat, newer SuSE – HWCLOCK value /etc/rc.config # SuSE – GMT value
/etc/defaults/rcS # Debian – UTC value