Need help with backup shell script
Robert Huff
roberthuff at rcn.com
Wed Nov 21 05:57:18 PST 2007
=?ISO-8859-1?Q?Andreas_Wider=F8e_Andersen?= writes:
> Does anyone use a script like this today that they can share? I'm
> not a shell scripter myself so any help is highly appreciated.
My current scripts are appended; constructive criticism is
welcome.
And the key to "<= 30 days" would involve "find".
Robert Huff
**** full_backup ****
#!/bin/sh
#set -x
#
# Set variables
#
PATH=/bin:/sbin:/usr/sbin:/bin:/usr/bin
echo "Backup started." at `date`
DUMP_DATE=`date | awk '{printf "%d.%s.%d\n", $6, $2, $3}'`
DUMP_DAY=`date | awk '{print $1}'`
DUMP_LEVEL=0
DUMP_CACHE=32
DUMP_DEVICE=/backup
DUMPDATES_FILE=/etc/dumpdates
export DUMP_DATE DUMP_DAY DUMP_LEVEL DUMP_CACHE DUMPDATES_FILE
# make the drive available
#mount /dev/da3a /backup
mount $DUMP_DEVICE
if [ $? -eq 0 ];
then
echo "/backup clean"
else
fsck -y $DUMP_DEVICE
fsck $DUMP_DEVICE
echo "/backup cleaned"
mount $DUMP_DEVICE
fi
echo "Disk mounted"
cd $DUMP_DEVICE/$DUMP_DAY
echo "Using "`pwd`
chflags -R noschg .
/etc/backup/dump_root
/etc/backup/dump_var
/etc/backup/dump_usr
# show disk usage
du -k $DUMP_DEVICE/$DUMP_DAY
# Clean up and go home
cd /tmp
sleep 5
umount $DUMP_DEVICE
echo "Disk unmounted."
echo "Backup complete." at `date`
**** dump_usr ****
#! /bin/sh
#set -x
# Set variables
PATH=/bin:/sbin:/usr/sbin:/bin:/usr/bin
#
# backup /usr
#
if [ ! -d usr ];
then mkdir usr
fi
cd usr
if [ $? -eq 0 ];
then
pwd
LINES=`ls -al /backup/$DUMP_DAY/usr | wc -l`
if [ $LINES -ne 3 ];
then
rm -r *
fi
echo "Usr"
dump $DUMP_LEVEL -D $DUMPDATES_FILE -C $DUMP_CACHE -Lau -f $DUMP_DATE.usr.dump /usr
if [ $? -eq 0 ];
then
#
# Compressing the weekly isn't worth the effort
# (takes too long relative to space reclaimed)
#
if [ $DUMP_LEVEL -ne 0 ];
then
echo "Compressing with gzip..."
gzip $DUMP_DATE.usr.dump
# echo "Compressing ..."
# tar -czf $DUMP_DATE.usr.dump.tgz $DUMP_DATE.usr.dump && \
# rm $DUMP_DATE.usr.dump
echo "done"
fi
else
echo "Dump suceeded."
fi
cd ..
fi
More information about the freebsd-questions
mailing list