Simple_snapshot_style_backup
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
This is a simple implementation of the snapshot style rsync method of doing backups as described by Mike Rubel at http://www.mikerubel.org/computers/rsync_snapshots/.
Simply mount an external USB hard drive at /mnt/sda1, run this script, then unmount the drive.
Key Advantages:
- Backup is on a physically separate device - no single point of failure.
- External drive is disconnected 99% of the time. This protects against power surges, accidental deletions, and also minimizes electricity usage and noise.
- Also serves as a versioned history of your files
| File: snapshot.sh |
#!/bin/bash
set -e
DEST="/mnt/sda1"
DIRS="/boot /etc /home /root /var/log /usr/portage/packages/All"
#Or use this line for a full system backup
#DIRS="/bin /boot /cvs /etc /home /lib /opt /root /sbin /usr /var"
DATE=`date +%Y%m%d%H%M%S`
initial()
{
# in the initial run, we perform a full copy.
cd ${DEST}
for DIR in ${DIRS}
do
echo "rsync ${DIR}"
mkdir -p ${DATE}/${DIR}
rsync --ignore-errors -a ${DIR}/ ${DATE}/${DIR}
done
}
backup()
{
# in the normal run, we hardlink everything, and only copy changed files.
cd ${DEST}
PREV=`/bin/ls -dl current | rev | awk '{print $1}' | rev`
echo "cp -al"
cp -al ${PREV} ${DATE}
for DIR in ${DIRS}
do
echo "rsync ${DIR}"
mkdir -p ${DATE}/${DIR}
rsync --ignore-errors -a --delete ${DIR}/ ${DATE}/${DIR}
done
}
# check privileges
if test "${USER}" != "root"
then
echo "I should be run with root privileges."
exit 1
fi
# check mount point
if test -e ${DEST}/NOT_MOUNTED
then
echo "${DEST} isn't mounted."
exit 1
fi
# run backup
if test -L ${DEST}/current
then
backup
else
echo "initial run. this may take a while..."
initial
fi
# update symlink
cd ${DEST}
rm -f current
ln -s ${DATE} current
|
Last modified: Thu, 04 Sep 2008 15:58:00 +1000 Hits: 14,291
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and list their apartments, townhouses and units.
