On Sunday 10 Aug 2003 03:18, Renat Golubchyk wrote:
> Hi list!
>
> What is better to use for backups at home - CD-Rs, CD-RWs, another
> harddrive or something else?
>
> The standard way is to use tapes, but they are way too expensive for
> a home desktop system. Harddrives are also not that good, because I
> want to backup a harddrive in the first place, and anyway my system
> is already full so I'd have to swap harddrives or buy an external one
> for backup. And that is not really cheap also.
>
> So what do you suggest? How and how often do you make backups?
>
Hard disks are cheap.  I have a 140GB drive dedicated to backups.  It 
currently holds 13 full backups.  I run the following script nightly as 
a cron job and can forget about it until I need to restore something:

#===================================================
#! /bin/bash
# /usr/local/bin/backup
#######################
# Backup Script
#######################
# Jason Calabrese <[EMAIL PROTECTED]>
# modified by Peter Ruskin <[EMAIL PROTECTED]> 24-Jul-03

BACKUP_TO=/mnt/backup
HOST=$( hostname|cut -f1 -d. )

echo "   Backup started at `date +'%H:%M'`"
echo
echo "   Mounting boot partition..."
mount /boot
echo
echo "   Mounting backup disk..."
mount $BACKUP_TO
sleep 4
echo

# Variables and calculations before backup
FILE=$BACKUP_TO/$HOST-$( date +"%F-%H%M" ).tar
FILE_LIST=$BACKUP_TO/$HOST-$( date +"%F-%H%M" ).list
EXCLUDE='--exclude --exclude /mnt/downloads/Pan --exclude /mnt/backup 
--exclude /mnt/cdrom --exclude /mnt/floppy --exclude /mnt/KROH-LIESE 
--exclude /mnt/KROH-PETER --exclude /mnt/PENGUIN --exclude /proc 
--exclude /usr/portage/distfiles --exclude /mdk90 --exclude 
/mnt/win/d/Pan --exclude /root/.ccache --exclude /home/peter/.ccache'
USEDSPACE=$( du -sh $BACKUP_TO | grep G | awk '{print $1}' | cut -f1 -dG 
)
NUMBAKUPS=$( ls $BACKUP_TO/${HOST}-*.tar | wc -w | awk '{print $1}' )
TOTALBLOCKS=$(cat /proc/partitions|grep 
ide/host0/bus1/target0/lun0/part1|awk '{print $3}')
CAPACITY=$(( $TOTALBLOCKS/1024/1024 ))
SPACELEFT=$(( $CAPACITY-$USEDSPACE ))
AVSIZE=$(( $USEDSPACE/$NUMBAKUPS ))
ESTBKUPS=$(( $CAPACITY/$AVSIZE ))
MYDATE="${ESTBKUPS} days ago"
OLD_FILE=$BACKUP_TO/$HOST-$( date --date="$MYDATE" +"%F" )

# Variables and calculations before backup
echo "STATUS BEFORE BACKUP..."
echo "   Capacity of backup partition:       ${CAPACITY}GB"
echo "   Space occupied by backup partition: ${USEDSPACE}GB"
echo "   Space left on backup partition:     ${SPACELEFT}GB"
echo "   Number of backups:                  $NUMBAKUPS"
echo "   Average size per backup:            ${AVSIZE}GB"
echo "   Estimated total number of backups:  $ESTBKUPS"
echo

# For when there's not enough space...
if [[ ${SPACELEFT} -le ${AVSIZE} ]]; then
        ESTBKUPS=$(( $ESTBKUPS - 1 ))
        NUMBAKUPS=$( ls $BACKUP_TO/${HOST}-*.tar | wc -w | awk '{print $1}' )
        # so remove earliest
        echo "   Removing earliest archive - not enough space for backup..."
        ls $BACKUP_TO/*.tar  | sort | head -n1 | xargs rm
        ls $BACKUP_TO/*.list | sort | head -n1 | xargs rm
        echo "   Number of backups:                  $NUMBAKUPS"
        echo "   Estimated total number of backups:  $ESTBKUPS"
        echo
fi

if [ ls ${OLD_FILE}*  2> /dev/null ]; then
        echo
        echo "   Removing old archive from $MYDATE..."
        ls ${OLD_FILE}*.tar  2> /dev/null && /bin/rm -f ${OLD_FILE}*.tar
        ls ${OLD_FILE}*.list 2> /dev/null && /bin/rm -f ${OLD_FILE}*.list
fi

echo
echo "   Performing backup - it'll take about half an hour..."
echo
/bin/tar -cpvvf $FILE / $EXCLUDE > $FILE_LIST 2> /dev/null

echo "   Backup finished at `date +'%H:%M'`"
echo

# Variables and calculations after backup
USEDSPACE=$( du -sh $BACKUP_TO | grep G | awk '{print $1}' | cut -f1 -dG 
)
NUMBAKUPS=$( ls $BACKUP_TO/${HOST}-*.tar | wc -w | awk '{print $1}' )
SPACELEFT=$(( $CAPACITY-$USEDSPACE ))
AVSIZE=$(( $USEDSPACE/$NUMBAKUPS ))
ESTBKUPS=$(( $CAPACITY/$AVSIZE ))
if [[ ${SPACELEFT} -le ${AVSIZE} ]]; then
        ESTBKUPS=$(( $ESTBKUPS - 1 ))
        # so remove earliest
        echo "   Removing earliest archive - not enough space for tomorrow..."
        ls $BACKUP_TO/*.tar  | sort | head -n1 | xargs rm
        ls $BACKUP_TO/*.list | sort | head -n1 | xargs rm
        echo
        USEDSPACE=$( du -sh $BACKUP_TO | grep G | awk '{print $1}' | cut -f1 
-dG )
        NUMBAKUPS=$( ls $BACKUP_TO/${HOST}-*.tar | wc -w | awk '{print $1}' )
        SPACELEFT=$(( $CAPACITY-$USEDSPACE ))
        AVSIZE=$(( $USEDSPACE/$NUMBAKUPS ))
        ESTBKUPS=$(( $CAPACITY/$AVSIZE ))
fi

echo "STATUS AFTER BACKUP..."
echo "   Capacity of backup partition:       ${CAPACITY}GB"
echo "   Space occupied by backup partition: ${USEDSPACE}GB"
echo "   Space left on backup partition:     ${SPACELEFT}GB"
echo "   Number of backups:                  $NUMBAKUPS"
echo "   Average size per backup:            ${AVSIZE}GB"
echo "   Estimated total number of backups:  $ESTBKUPS"
echo

echo "   Unmounting boot and backup partitions..."

/bin/umount -l /boot
/bin/umount -l $BACKUP_TO

echo "   Spinning down backup disk..."
/sbin/hdparm -y /dev/hdc                # spin down disk

echo
echo " To restore a file, search for it in $FILE_LIST, e.g. etc/fstab, 
then:"
echo " # cd /"
echo " # tar -xpvf $FILE etc/fstab"
echo
#===================================================

Peter
-- 
==================================================
Gentoo Linux:   Gentoo Base System version 1.4.3.9
kernel-2.4.22_pre2-gss i686 AMD Athlon(tm) XP 1600+
==================================================


--
[EMAIL PROTECTED] mailing list

Reply via email to