%--------------------------------------------------------------------
\chapter{Backups} \label{chap:backups}
%--------------------------------------------------------------------

	\begin{raggedleft}
	\it
	Hardware is indeterministically reliable.  \\
	Software is deterministically unreliable.  \\
	People are indeterministically unreliable.  \\
	Nature is deterministically reliable. \\
	\end{raggedleft}
	\vspace{2em}

	\noindent
	This chapter explains about why, how, and when to make
	backups, and how to restore things from backups.

	\meta backup strategies, horror stories, what media should be
	used, always verify, compressed vs uncompressed, discuss
	everything vs only the ``important'' stuff, automatic backups,
	off-site backups

\section{Why backup?}

	Your data is valuable.  It will cost you time and effort, and
	therefore money or at least personal grief and tears, to re-create
	it; sometimes it can't even be
	re-created, e.g., if it is the results of some measurements.
	Since it is an investment, you should protect it and take steps
	to avoid losing it.

	There are basically four reasons why you might lose data:
	hardware failures, software bugs, human action, or natural
	disasters.  Although modern hardware tends to be quite reliable,
	it can still break seemingly spontaneously.  The most critical
	piece of hardware for storing data is the hard disk, which relies
	on tiny magnetic fields remaining intact in a world filled with
	electromagnetic noise.  Modern software doesn't even tend to
	be reliable; a rock solid program is an exception, not a rule.
	Humans are quite unreliable, they will either
	make a mistake, or they will be malicious and destroy data on
	purpose.  Nature might not be evil, but it can wreak havoc even
	when being good.  All in all, it is a small miracle that anything
	works at all.

	Backups are a way to protect the investment in data.
	By having several copies of the data, it does not matter as much
	if one is destroyed (the cost is only that of the restoration of
	the lost data from the backup).

\section{Things to ponder}

	\meta Considerations for backups: safety, speed, convenience,
	portability, rate of change, what to backup, 

	The purpose of backups is to enable you to rebuild the system
	if necessary.  You must weigh all decisions about backups with
	this in mind.  You should consider at least the following points
	(note that they influence each other to some degree):
		%
	\begin{quote}
	\begin{itemize}
	\item How paranoid to be?

		How much do you trust your system?
		Can you get the software (operating system,
		applications) from elsewhere quickly and reliably
		enough, or should you keep local copies?  Can you get
		compatible versions?  Will you be able to use the same
		hardware and software to restore?  What disasters do
		expect?  Do you care about unexpected disasters?

	\item What to backup?  

		Can you get compatible copies of the software from elsewhere,
		whenever you need them, or should you keep local copies?
		Will it be easy to re-install, or should you backup your
		complete system?

		Important things to remember are non-files, such as the
		partition table, boot sectors, hardware setups, and
		well-hidden files, such as many configuration files.

	\item How often?

		How much and how often does your data change?  The more
		often it changes, the more often you will need to back up.

	\item How many backup generations to save?

		Backup generations can allow restoring a file that was
		deleted a long time ago, or restoring a very old version
		of a file.

	\item What media to use?

		A good backup media is reliable (it won't fail) and portable
		(it will work on other machines as well).  

	\item What tools to use?

		A good tool is reliable (will detect and correct errors
		in the backup medium) and portable.  It should also be
		convenient and efficient to use.

	\item How to verify?

		How much do you trust your backup medium?  It's hardware,
		it too can fail.  The backup tools might not work correctly,
		or you might be making a silly mistake using them,
		so you'll have to verify your backups, i.e., check that
		they work correctly.

	\item How to automate?

		Backing up can be quite tedious, and that makes them
		unpleasant to do.  If you can automate the process as
		much as possible, it will be much more reliable and,
		most importantly, it will be done.
	
	\end{itemize}
	\end{quote}

\section{Backup levels}

	\meta "backup volumes", rotation, backup levels, when to backup
	and how much each time, don't keep all backup media in one place

	The simplest approach to backups is to make a full one
	at suitable times.  That is, every time you make a backup,
	you make a copy of all files.  This is usually tiresome;
	it takes too much time.  It will also be too expensive to 
	keep generations of backups.

	A refinement is to make a full backup once, and then back up
	all files that have been modified since the last backup.  These
	kinds of backups are called \defin{incremental backups}.  They
	will reduce the media use (since most files are modified rarely),
	and allow generations of backups.  Unfortunately, it will still be
	expensive to keep this up for very long.  It will usually take
	only relatively few incremental ones to use as much media as
	is needed for a full backup, making it impossible to keep doing
	incremental backups for very long.  The backup history will therefore
	be rather short.

	\defin{Backup levels} are a way to increase the length of the
	backup history, by sacrificing many of the versions that can
	be restored.  Instead of having only two backup levels,
	full and incremental, you have several.  Level 0 is a full
	backup, higher levels are incremental ones.  When doing a
	backup on one level, you back up everything that has been
	modified since the previous backup on a lower level.  By
	carefully choosing when to use each backup level, you can
	extend the backup history quite far back in the future, but
	still keep frequent backups for the near past.

	A backup scheme could do a level 0 backup on the first
	day of every month, a level 1 backup every Friday, and a level
	2 backup all other working days.  If tapes are used as the backup
	media, there will be one for level 0, four for level 1, and 
	five for level 2.  Thus, it will be possible to restore any
	backed up version of any file during the past week, and the
	versions that existed Fridays for the past month.

	Figure~\ref{fig:backup-history-timeline} which backup level
	is used each day, and which backups can be restored from
	at the end of the month.

		\begin{figure}[htb]
		\begin{center}\input{backup-timeline.tex}\end{center}
		\caption{A sample backup schedule.  The arrows indicate
		still restorable backups.}
		\label{fig:backup-history-timeline}
		\end{figure}

\section{Backup media}

	\meta backup media: floppies, tapes, worm, mo disks, network disks,
	removable hard disks, other hard disks

\section{Various tools}

	\meta an overview of the tools: tar, cpio, afio, tbackup (+newer
	version), dump, GNU's shell scripts, other shell scripts

\section{A sample plan for a small system}

	\meta a sample plan for a very simple system

\section{A more demanding backup plan}

	\meta how I do my backups
