I probably don't need to say this, but periodically backing up your data is important, even with a system as stable as FreeBSD. (Hey, just because the OS is rock-solid doesn't mean your hardware, such as your hard drive, is). Obviously one of the easiest ways to back up your data is to burn it onto a CD-R or DVD-R.
A good place to start is to back up the contents of your Home directory. That's probably where you're saving text documents, pictures, music, etc. However, it is also nice to save some of your system config files, especially if you've highly customized things. Trying to remember which config files to back up can be annoying, and we're lazy, so we created a couple of backup scripts to automate the process of backing up our important data. Feel free to use our examples if you like them. Obviously you'll have to change the paths to some things and add/delete files that exist or don't exist on your system and that you may or may not want to back up.
Dan's backup script looks like this:
#!/bin/sh
a=`date "+%Y-%m-%d"`
backdir=/big/back/$a
if [ -e "$backdir".tar.gz ]
then rm -r "$backdir".tar.gz
fi
mkdir $backdir
cd /home
cp -rf xaenn /usr/big/back/
cd /usr/big/back/xaenn
rm -rf .thunderbird .mozilla .gimp-2.2 .kde Open* .gnome*
cd /usr/big/back
tar -czf "$backdir"/home.tar.gz ./xaenn
cp /etc/X11/xorg.conf "$backdir"/
cp -rf /big/conquest "$backdir"/
cp -rf /big/doc "$backdir"/
cp -rf /big/web "$backdir"/
cp -rf /big/lyric "$backdir"/
cd "$backdir"/..
tar -czf ./"$a".tar.gz ./"$a"
rm -r $backdir
rm -r /usr/big/back/xaenn
exit 0
The script creates a temporary backup directory in /big/back/{today's date, in year-month-day format}, for example /big/back/2005-09-05. It then copies Dan's home directory (/home/xaenn), then it deletes the copied (not the original!) .thunderbird, .mozilla, .gimp-2.2, .kde, and any folders beginning with "Open" or ".gnome". (These are "hidden" settings folders for various packages he has installed on his system. According to Dan, such a step would be unnecessary if rather than cluttering a user's home directory with all of these settings folders, each app put its settings folder in a /home/xaenn/etc folder that stored each individual user's settings--not a change that's likely to be implemented).
Once it has done this cleaning of unwanted settings folders, the script then copies Dan's xorg.conf, and several directories in /big. When it's done copying the desired files and directories, the script outputs a nice .tar.gz file with today's date for a name, i.e. 2005-09-05.tar.gz. It then deletes the temporary backup directory.
Pretty straightforward. At this point it is a good idea to copy the .tar.gz file to another hard drive (the iriver ihp120 would work nicely) or a network drive.
My (Kevin's) script looks like this:
#!/bin/sh
a=`date "+%Y-%m-%d"`
backdir=/home/backups/$a
if [ -e "$backdir".iso ]
then rm -r "$backdir".iso
fi
mkdir $backdir
cd /home
cp -r reinholz /home/tmp
cd /home/tmp/reinholz
rm -r .*
cp -r /home/tmp/reinholz "$backdir"/
cp .Xauthority .Xdefaults .xinitrc .zshrc "$backdir"/reinholz/
cp -r .fluxbox "$backdir"/reinholz/
cp -r .gaim "$backdir"/reinholz/
cp -r .screenrc "$backdir"/reinholz/
cp -r .thunderbird "$backdir"/reinholz/
cp -r /usr/X11R6/lib/X11/fonts/Japanese/ "$backdir"/japanese_fonts
cp -r /home/public "$backdir"/samba_share/
cp /boot/loader.conf /usr/src/sys/i386/conf/NEWKER /usr/src/sys/i386/conf/GENERIC /etc/rc.conf /usr/local/bin/backup.sh /etc/X11/xorg.conf /etc/hosts /etc/group /etc/fstab /etc/make.conf /usr/local/etc/pkgtools.conf /etc/libmap.conf /etc/ppp/ppp.conf /usr/local/etc/smb.conf "$backdir"/
cd "$backdir"/..
tar -cf "$a".tar "$backdir"
mkisofs -allow-leading-dots -R -J -V "$a backup" -iso-level 3 -o ./"$a".iso ./"$a".tar
rm -r $backdir
rm "$a".tar
rm -r /home/tmp/reinholz
exit 0
Slightly different from Dan's backup script. The basic difference between my script and Dan's (besides the temporary locations where the work is done, and the files I chose to back up) is that at the end of the process my script outputs an .iso file ready to burn to CD-R or DVD-R. Note that rather than just outputting my files to an .iso, I first placed them in a .tar archive. THIS IS VERY IMPORTANT! If you do not protect your files by putting them in a .tar archive, the permissions on all of your files will be ruined when you try to copy them from the CD/DVD backup! Like Dan's script, today's date (in year-month-day) format is the filename, i.e. 2005-09-05.iso.
With either one of these scripts, you'll obviously need to change the paths to certain files and directories, and are free to pick and choose what files and directories you deem important enough to back up. One more thing to make either of these (or your own custom script) executable, you'll need to execute the following command as root:
chmod 755 backup.sh
One other very important thing worth noting: at the top of both of our scripts, you'll see the line "#!/bin/sh". This tells the script to use sh (Bourne) shell to execute it. The advantage of specifying sh as the script shell is that virtually every *nix has this shell installed by default. To run either backup script,
backup.sh
Sit back, relax, and wait for your command prompt to return to you, indicated that the script has finished its task. Unlike Dan's script, during the mkisofs phase of my backup script, you'll get a readout in your terminal window indicating the progress of the .iso creation.
Although possible, it is inadvisable to specify another shell, such as zsh. (As denoted by the following line at the top of your script: "#!/usr/local/bin/zsh"). The biggest disadvantage of writing scripts this way is that if you uninstall this shell, you will no longer be able to execute the script! You'll have to go back and edit the script, specifying your current shell in place of /usr/local/bin/zsh. Dan and I both got bitten by this little hiccup when we switched from bash to zsh, but foolishly left all of our scripts calling bash in the first line.
One final note: unless you save your script to a directory in your path, you have to run it from within the same directory (or specify the entire path before the filename). I have my script saved to /usr/local/bin/, which allows me to execute it from anywhere. Dan on the other hand has his script in ~/bin, which is also in your path. Do take note however that if you 'su' to root from the user xaenn, /usr/home/xaenn will be in your path, and not /root. You can go either way with this. It's just a matter of personal preference.