I seem to have a problem sending attachments to multiple lists.  Only the first
recipient on the list gets the attachment according to feedback I get.

Sooo, I'll inline the script below.

I'd appreciate any comments or suggestions regarding improvements to the script
in the attachment.

The Fbackup script:
#!/bin/sh

# Fbackup - create a full backup of a set of defined directories on the system.
#     By default, the output file is saved in /mnt/backup with a timestamped
#     filename and compressed.

## Modified from scripts in Dave Taylor's book "Wicked Cool Shell Scripts"
##    by TTT

## last modification date & time:  14 Jun 2010 @ 2353

compress="bzip2"                ## compression method to use
timestamp="$(date +'%y%...@%h%m')"      
   ## set timestamp for all current archives
   ### date format suggested by Mike Schuh [SLL]
tsfile="/home/tom/backup_$timestamp"    
   ## archive finished timestamp file location
backup_device="/mnt/backup"     
   ## where to write archives
back_dir_file="/TEST/bu_dirs"   
   ## file with directory names to backup
indir="EOF"
   ## initialize indir

#  only root can execute this script due to writing to mounted device
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

#echo "Be sure external backup device is mounted, then press ENTER"
#read input

##  make sure $backup_device exists
if [ ! -d $backup_device ]      
then mkdir $backup_device
fi
## In the above, how could I test for a mounted usb drive as $backup_device?

## make sure $backup_device is writeable
if [ ! -w $backup_device ]
        then
        echo "Directory $backup_device is not writeable - fix and try again"
        exit 1
fi

touch $tsfile           #create timestamp file (will contain list of
completed backups)

###
#  backup directories one at a time
###

while read indir; do
      if [ $indir = "EOF" ] ; then              ## until EOF reached
         break ;
      fi
         dirsize="$(du -sh $indir | awk '{print $1}')"
## du -sh = total dir size in 1024 byte human form ###
echo -e "dirsize = $dirsize"   ### remove after testing
###
      output="$backup_device$indir.backup.$timestamp.bz2"
      echo -e "full backup of $indir being performed at: $timestamp"
      tar --same-owner --preserve-permissions -Pcjf $output $indir
# add directory name, size, date, & time of completion to $tsfile
        echo -e "full backup of $indir (size = $dirsize) completed on: $(date\
+'%y_%b_...@_%h%m')" >> $tsfile done < $back_dir_file

###
# when finished and tested, set to run from /etc/cron.daily
###

exit 0
##### end of script #####

The file called "bu_dirs" contains:

/boot
/etc
/TOM
EOF


The output of the timestamp file is:

full backup of /boot (size = 169M) completed on: 2010_jun_...@_0052
full backup of /etc (size = 53M) completed on: 2010_jun_...@_0052
full backup of /TOM (size = 56K) completed on: 2010_jun_...@_0052

I've tested the script extensively and it works the way I intend, however,
there's always room for improvment.

Thanks for your time and suggestions, Tom

-- 
Tom Taylor - retired penguin
openSuSE 11.3-M7 x86_64
KDE 4.4.3, FF 3.6.4
claws-mail 3.7.6
linxt-At-comcast-DoT-net

Reply via email to