#!/bin/sh
# Backup all files under home directory to a single # floppy
# Display message with option to cancel
dialog –title “Backup” –msgbox “Time for backup \ of home directory. \
Insert formatted 3-1/2\” floppy and press \ to start backup or \
to cancel.” 10 50
# Return status of non-zero indicates cancel
if [ “$?” != “0? ]
then
dialog –title “Backup” –msgbox “Backup was \ canceled at your
request.” 10 50
else
dialog –title “Backup” –infobox “Backup in \ process…” 10 50
cd ~
# Backup using tar; redirect any errors to a
# temporary file
# For multi-disk support, you can use the
# -M option to tar
tar -czf /dev/fd1 . >|/tmp/ERRORS$$ 2>&1
# zero status indicates backup was successful
if [ “$?” = “0? ]
then
dialog –title “Backup” –msgbox “Backup \
completed successfully.” 10 50
# Mark script with current date and time
touch ~/.backup
else
# Backup failed, display error log
dialog –title “Backup” –msgbox “Backup failed \ — Press
to see error log.” 10 50
dialog –title “Error Log” –textbox /tmp/ERRORS$$ 22 72
fi
fi
rm -f /tmp/ERRORS$$
clear
To run this automatically, I put these lines in my .profile file to call the backup script on login if more than 3 days has elapsed since the last backup was made:
# do a backup if enough time has elapsed
find ~/.backup -mtime +3 -exec ~/.backup \;