[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Question on backups using rsync



I have a 300GB external HD that contains a current / with the
exeption of /proc/ /tmp/ /mnt/ /dev/ and /sys/...

Is it possible do a bare-metal restore using this? 

Also can you think of anything useful to add to this script?

<begin backup.sh>
#!/bin/sh
# Primary Author: Brice Burgess - bhb@iceburg.net
# Secondary Author: Brad Sims  - bsims@abnt.org
# backup.sh -- backup to a local drive using rsync

# Directories to backup. Separate with a space. Exclude trailing slash!
SOURCES="/"

# Directory to backup to. This is where your backup(s) will be stored.
# Exclude trailing slash!
TARGET="/backup/backup"

# Your EXCLUDE_FILE tells rsync what NOT to backup. Leave it unchanged if you want
# to backup all files in your SOURCES. If performing a FULL SYSTEM BACKUP, ie.
# Your SOURCES is set to "/", you will need to make use of EXCLUDE_FILE.
# The file should contain directories and filenames, one per line.
# An example of a EXCLUDE_FILE would be:
# /proc/
# /tmp/
# /mnt/
# *.SOME_KIND_OF_FILE

EXCLUDE_FILE="/home/bsims/Scripts/Backup/exclude_file.txt"

###########################

# We need to mount the external usb HD

echo " Mounting external USB drive to /backup"
sudo mount -t ext3 /dev/sda1 /backup
echo " Done."
echo " "
echo " Starting backup..."

# I want a log of when I last ran this script, and a list
# of every package installed on my computer...
date >> /home/bsims/Scripts/Backup/Backup_History.txt
dpkg -l | awk '{print $2}' > /home/bsims/Scripts/Backup/dpkg-filelist

if [ ! -x $TARGET ]; then
        echo " Backup target does not exist or you don't have permission!"
        echo " Exiting..."
        exit 2
fi

echo " Verifying Sources..."
        for source in $SOURCES; do
        echo " Checking $source..."
        if [ ! -x $source ]; then
                echo " Error with $source!"
                echo " Directory either does not exist, or you do not have proper permissions."
        exit 2
        fi
        done

if [ -f $EXCLUDE_FILE ]; then
        EXCLUDE="--exclude-from=$EXCLUDE_FILE"
fi

        echo " Sources verified. Running rsync..."
        echo " "
        for source in $SOURCES; do

        # Create directories in $TARGET to mimick source directory hiearchy
        if [ ! -d $TARGET/$source ]; then
                mkdir -p $TARGET/$source
        fi

        rsync -vv --exclude=$TARGET/ $EXCLUDE -a --delete $source/ $TARGET/$source/
        done
# Now we have to umount this beast before we can remove it...
echo " "
echo " Unmounting External USB Drive from /Backup..."
sudo umount /backup
echo " Done."
echo " It is now safe to shutdown and/or remove the external USB drive."
        exit 0
<end backup.sh>
-- 
If God hadn't meant for them to be sheared, he wouldn't
have made them sheep.
	-- Calvera



Reply to: