Saturday, May 24, 2008

shell script a program to backup some important files and directories

#!/bin/sh
# backupWork-a program to backup some important files and directories
# Version 1, Aug 2006 # # Get the current date in a special format
# On Sept 27, 2006 at 9:05 pm,
# this would look like 2006.09.27.09:05:00
TIMESTAMP='date +%Y.%m.%d.%T'
# Create the new backup directory
# Could look like ~/Backups/Backup.2006.09.27.09:05:00 BACKUPDIR="~/Backups/Backup.$TIMESTAMP"
mkdir $BACKUPDIR
# Copy files to new directory
cp -r ~/Work/Project $BACKUPDIR
cp -r ~/Mail $BACKUPDIR
cp −/important $BACKUPDIR
# Send mail to confirm that backup was done
echo "Backup to $BACKUPDIR completed." | mail $LOGNAME

No comments: