Backup Scripts for Solaris Machines

The big picture

The backup drive is an external 18GB drive mounted as the /backup filesystem on Piemonte.

Running a backup script stores the entire contents of a machine's local filesystem into a single file on this drive. As a rule, there are two generations of backup for each computer on this drive at any one time.

Each computer has a directory, used for storing that computer's backup files and scripts. This backup directory is nsf mounted as /backup from each machine. Thus, for example, /backup/monviso on piemonte is accessed as /backup from monviso.

A description of the remote mounting is in the nfs file sharing section.

Each machine's backup directory is manually mounted as needed. This is a kind of protection from accidentally clobbering your backup files, and it reduces the temptation to store miscellaneous non-backup-related files on the backup disk.

Backing up

To run backups on Mac machine--oreglia, log in as root and type the following:

# tar -cvf orelgia031204.tar /Luxin /users/vj
# gzip -c oreglia031204.tar > oreglia031204.tar.gz

In this example, oreglia031204.tar means this is the backup file at Mar.12,2004, and we backup the these directories: /Luxin, /users/vj. If we need backup some other folders, just add the absolute path into the command.

To run backups on one Unix machine, log in as root and type the following:

# mount /backup
# cd /backup
# df -k (to verify that there is space)
# nice ./bkup & (it should run for several hours)
# ls -al (to verify that the backup file is there)
# tail *.log (to see the log file)
# cd / (needed before you can umount)
# umount /backup

The ./bkup script tars and gzips the local filesystems into a single file. The results should be named something like:

monviso-020405.tar.gz
monviso.log

Where "020405" means 2002 April 5th (yymmdd).
The tail end of the log file should contain time-stamped notations for the beginning and end of the backup.

The df -k command produces the space usage for mounted filesystems. Thus you need to run it after mounting /backup. (On piemonte, the backup disk is permanently mounted.) If you do not understand how to read the result, check the managing diskspace page.

Generally 2-3 GB is needed for backing up one machine.

Typing

nice ./bkup &
instead of plain
./bkup &
lowers the execution priority somewhat, so you can continue working with less interference.

Some Important Info About the Backup File

Backup files contain a tar of all the local filesystems, starting from the root /.

Tar combines many files into a single archive file, rather like zip. You can use man to read about the tar command.

Tar does not compress, only combine files together. So the tar file is gzipped. In order to examine an old backup file, you must gunzip it first. Use df -k to make sure there is space first.

Warning: the path names in the tar file are absolute. This means that when you try to un-tar a backup file it will overwrite your existing files if you are not careful. And if you are logged into piemonte when you untar a monviso backup, then monviso files will clobber your piemonte ones. This is certainly not your intention, but the computer does not care.

See the untar backup files page for instructions.

The tar file contains all the locally mounted filesystems. Some care is needed by the backup script to avoid backing up remote-mounted file systems, any cd-rom or floppy you happen to have mounted, the /dev hierarchy, etc. (Also, you want to avoid the recursive loop caused by backing-up your backup files.)

Thus there is a file tar-exclude in each machine's /backup directory that lists these ignorable directory trees.

The Backup Script

For reference, the script looks like this. You should not need this information for running backups.

  1. #!/usr/bin/csh
  2. set tarhost=`uname -n`
  3. set tarhost=`expr $tarhost : '\([^\.]*\)' \| backup`
  4. set tarlog=$tarhost.log
  5. set tarfile=$tarhost-`date "+%y%m%d"`.tar
  6. touch $tarlog
  7. echo `date` "Starting tar | gz to" $tarfile ".gz" | tee -a $tarlog
  8. tar cXf tar-exclude - /* | gzip --stdout >$tarfile.gz
  9. echo `date` "Finished" | tee -a $tarlog

Explanations for each line follow:

  1. Runs the script using the csh shell
  2. Finds the network name of the machine from uname. Sometimes this is a full name, e.g. monviso.eecs.uic.edu, sometimes just the first part, e.g. monviso.
  3. Truncates off everything after the first dot in the host name.
  4. Produces the name of the log file.
  5. Produces the name of the backup file, using the date command.
  6. Creates an empty log file if none exists yet.
  7. Puts a starting note in the log.
  8. The tar | gzip command. Options "cXf" (no hyphen is needed) are: c=create tar file, X=name of exclude file, f=name of tar file. This is followed by the two file names in the order specified: "tar-exclude" and "-". (An output file name of "-" means standard output, so it can be piped into gzip.) Then comes the filesystem to tar: "/*", which means tar the root and everything under it, as subject to the excluded directories.
  9. Puts an ending note in the log file.

Home

Last Revised: 15 May 2002
Michael Glass