If you have an extra hard drive installed in your system, here's how you can use it to back up important directories and such.
First, keep the hard drive unmounted during normal use, as this entry from /etc/fstab shows:
/dev/sdc1 /backup ext3 noauto 1 2
Next, add an extra script to the shutdown process just after killall. For instance, whereas the contents of a stock red hat / fedora core system look like this for /etc/rc.d/rc0.d,
... lrwxrwxrwx 1 root root 19 Jun 20 2005 K99readahead -> ../init.d/readahead lrwxrwxrwx 1 root root 25 Jun 20 2005 K99readahead_early -> ../init.d/readahead_early lrwxrwxrwx 1 root root 17 Jun 20 2005 S00killall -> ../init.d/killall lrwxrwxrwx 1 root root 14 Jun 20 2005 S01halt -> ../init.d/halt lrwxrwxrwx 1 root root 17 Jul 6 2004 S18rpcgssd -> ../init.d/rpcgssd lrwxrwxrwx 1 root root 19 Jul 6 2004 S19rpcidmapd -> ../init.d/rpcidmapd lrwxrwxrwx 1 root root 20 Jul 6 2004 S19rpcsvcgssd -> ../init.d/rpcsvcgssd
you want to make your backup happen just after the killall and before the halt, like so:
lrwxrwxrwx 1 root root 19 Jun 20 2005 K99readahead -> ../init.d/readahead lrwxrwxrwx 1 root root 25 Jun 20 2005 K99readahead_early -> ../init.d/readahead_early lrwxrwxrwx 1 root root 17 Jun 20 2005 S00killall -> ../init.d/killall lrwxrwxrwx 1 root root 17 Jun 20 2005 S01backup -> ../init.d/backup lrwxrwxrwx 1 root root 14 Jun 20 2005 S01halt -> ../init.d/halt lrwxrwxrwx 1 root root 17 Jul 6 2004 S18rpcgssd -> ../init.d/rpcgssd lrwxrwxrwx 1 root root 19 Jul 6 2004 S19rpcidmapd -> ../init.d/rpcidmapd lrwxrwxrwx 1 root root 20 Jul 6 2004 S19rpcsvcgssd -> ../init.d/rpcsvcgssd
You could put the symlink in both the /etc/rc.d/rc0.d (shutdown) and /etc/rc.d/rc6.d (reboot) directories, but I just leave it in the shutdown directory because this operation takes a while.
We have not yet seen the shell script named /etc/rc.d/init.d/backup. Here it is:
#!/bin/bash # added by Manni; backs up certain working directories to /backup drive. mount /backup cp -a -v /etc /backup cp -a -v /root /backup cp -a -v /home /backup # anything else in here, like perhaps the directory where # your postgres database is kept umount /backup