1. Making smart backup
2. Restoring from smart backup
1.1. Data backup
This is the most important backup you can make. It contains your IT life. If you lose your data, by a disk failure (can happen, believe me), by accidentally removing something (can also happen, believe me more!), and you had not a backup, the data are forever lost!
Make internal daily backups + regularly also external backups.
1.1.1. Internal backup
With internal backup I mean a backup which is stored inside your PC and which the system has access.
Such a backup shall be done automatically each day. Since the system has write access to the backup, don't forget there is a very very little possibility (but it exist) that you will lose your backup!
A friend of mine, for example, trying the debian-installer, didn't see that he had choosen automatic disc partitioning. As result, all his data + his backups where destroyed!!!
There are a lot of nice and simple tools to do such a job. Take a look here http://www.planamente.ch/emidio/pages/linux_tools_description.php#Backup.
1.1.2. External backup
With external backup I mean a backup which is stored outside your PC and which the system has NOT access.
Such a backup shall be done manually every x month. Less important are your data, bigger can be x!
There are probably a lot of nice tools to do such a job, but the easiest way if you have a DVD burner is to copy your data one to one (preserving owner, group, permissions and symlinks !) to the DVD.
1.1.3. My backups
Since my data are very important for me, I make daily backups automatically with emirdiff-backup and every 6 month I make a backup on DVD.
The daily backup is made on a different harddisk, because it is dangerous to have it on the same disk where the data are stored. If there is a disk failure, both data and backup are lost!
The half-yearly backup is made on 2 copies. Why? Because one copy is stored in my home, the other in them of my parents. Am I exaggerate? Maybe. But what happens if my home burns? All my IT life will also burn!
1.1.4. Where to keep the backup
If you know the Murphy's law, you should consider always the worst case. Therefore consider the following things.
Take care about how do you save your backup. It should be easily accessible.
Take care about where do you put your backup. The tool chest is not the best place!
Take care about the temperature where do you put your backup. Too hot places are not really the best choice (same for too cold).
If you encrypt your backup, be sure you can read its content if the system break.
Finally remember: electronic doesn't like water!
Here a nice story:
Think your boss has given you an important task that shall be delivered tomorrow. You could work at home (nice, eh?) and you worked on your laptop. Your work is now finished. You are testing it a little bit more and suddenly, the system hangs up. You try a reboot but the harddisk is broken. You have lost system, data and internal backup in one shoot!
Since you are a cautious person, for such an important task, you have made every day an external backup on a USB memory stick. Where is the stick? You don't remember. You search and search until finally you find it in the kitchen, between the electric stove and the washbasin. Why is it here? Ah, yes. You have made the backup during the breakfast.
The case is a little bit wet, but the content seems to be ok. Ok, you dry it with the hair drier. Ops, too hot. The case has burned out a little bit.
Go to the desktop PC, hoping the stick is not damaged. Fortunately, UDEV recognises the stick and a nice icon appears on the desktop. You double click it to see the content. Argh, you have encrypted it for more security.
No problem. You have just to install the required tool also on your desktop PC. You don't remember the name of the package. Go fast in internet and after a quick search you find it: cryptdisk. Ok, go with the installation and now ...
... passphrase. What passphrase have you used yesterday. It was the 14th day of the month therefore it must be something containing the name of an ex girlfriend plus the 14. Or 41 (since do you switch the number for more security!)? Good luck!
This is just a story where a lot of things goes wrong, but it is not so far from the reality. I know a lot of people who have lost their data because they didn't make backups. You have been warned!
1.2. System backup
This backup is important because you have invested a lot of time on installing and configuring your linux box. Isn't so?
1.2.1. Backup of system configuration
I make daily backups of /boot, /dev/, /etc, /var/yp (NIS) using emirdiff-backup.
1.2.2. Backup of system installation
I make daily backups of the list of installed packages using emidpkg-backup (see http://www.planamente.ch/emidio/pages/linux_download_list.php#emidpkg-backup).
This list is very useful to quickly reinstall exactly the same packages if I have to reinstall my system.
2.1. Data restore
I think this procedure doesn't need more description. Just copy your lost data from your last backup.
2.2. System restore
First at all, install the new system, by choosing just the base system. No Xwindow or further packages are necessary at this time.
2.2.1. File /etc/apt/sources.list
In order to install the same packages you had before, replace this file with your last one. Maybe, you had added some repository more:
mv sources.list sources.list.orig
cp -a /pathToYourBackup/etc/apt/sources.list .
2.2.2. Restore of system installation
Once the installation is finished, type taking care about the sign < and NOT >
dpkg --set-selections < yourLastList.dpkg
where yourLastList.dpkg is the last backup made by emidpkg-backup.
This will set exactly the same packages you had before.
Now install the just set packages:
At this point, you have installed the same packages you had before your system broke.
2.2.3. Restore of system configuration
It is time to restore the system configuration.
Just replace the new configurations with the lasts:
mv /etc /etc.old
cp -a /pathToYourBackup/etc /etc
Somebody could not agree with hard replacing the whole /etc with the last one, but I have made this a lot of time and I have never had any problem.
Alternativelly, you can test all the services and when you find one wrong configured, you can just replace its configuration files (maybe making a diff first).
The yp directory is only necessary if you had NIS (most people doesn't):
mv yp yp.old
cp -a /pathToYourBackup/yp yp
Now, it is time to reboot. If you worked fine, the system should be reinstalled and exactly configured as before the failure.
A little bit of make up
First public release
Emidio Planamente <firstname.lastname@example.org>