Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fast Personal Backup

Tips and Tricks

Fast Personal Backup

by  gamerland  Posted    (Edited  )
If you are going to make a number of changes or just want to backup your own home directory as needed, I came across this utility (GPL) to do it. While it can be modified to do different types of backups, in its simpliest form, you run it and it creates a backup "snapshot" of your directory. Works great:
http://www.fourmilab.ch/webtools/flashback/

I put the code here in case it should disappear. Please DOWNLOAD it from the link to ensure you have the most recent copy.

Also, do your sysadmin a favor, and do not backup things that get caught in the normal backup.


#! /bin/sh
#
# F L A S H B A C K
# -----------------
#
# by John Walker
# http://www.fourmilab.ch/
#
# Ever accidentally typed something like "rm * .o" after
# a busy day's productive editing? FLASHBACK makes
# snapshots of the directory you're working in (and any
# subdirectories) to a common backup directory from which
# you can restore clobbered files as required. FLASHBACK
# reports the size of the backup directory after adding
# the new backup so you'll know when it's time to get rid
# of old backups.
#
# WHERE is the directory in which you want backups to be kept.
# This should ideally be on an NFS (or whatever) mounted
# location on a different machine than the one you usually
# work on or, failing that, a file system stored on a
# different physical device than the one you usually edit
# within.
#
WHERE=$HOME/FLASHBACK
#
# Unless you want to fiddle with how flashback names its
# files or creates backups, you shouldn't have to change
# anything below this comment.
#
# Working directory translated to backup file name
#
WHAT=`echo $PWD | tr / - | sed s:-::`
#
# ISO 8601 date and time
#
WHEN=`date +%Y-%m-%d-%H-%M-%S`
#
# Extension to append to backup archives to indicate file type
#
HOW='.tar.gz'
#
# Command used to back up files. If you don't want to back up
# subdirectories, you'll need to create a list of non-directories
# with find and feed that to tar (or whatever archive tool you use).
#
WHO="tar cfv - ."
WHY=gzip
#
# If the backup directory doesn't exist, ask if the user
# wants to create it.
#
if [ ! -d $WHERE ]
then
echo Backup directory $WHERE does not exist.
echo -n "Would you like to create it (y/n) ? "
read confirm
if [ "$confirm" = "y" -o "$confirm" = "Y" ]
then
echo mkdir $WHERE
mkdir $WHERE
if [ ! -d $WHERE ]
then
echo Unable to create backup directory $WHERE -- exiting.
exit 1
fi
else
echo Backup aborted.
exit 1
fi
fi
#
# Okay, let 'er rip
#
$WHO | $WHY >$WHERE/$WHAT-$WHEN$HOW
if [ $? != 0 ]
then
echo $0: Error creating backup.
exit 1
fi
#
# Make the backup read-only to prevent tragedy if you
# fat-finger "c" for "v" when extracting with tar.
#
chmod 444 $WHERE/$WHAT-$WHEN$HOW
#
# Now obtain the size of the backup directory and let the
# user know, just in case it's time for some housekeeping.
# This command assumes a System V style "du" with the "-k"
# option; if you're using a BSD-style system, such as SunOS
# 4.x, you'll have to modify the following command. "du -s"
# should work on most systems.
#
HOWMUCH=`du -sk $WHERE | cut -f1`
echo $0: $HOWMUCH kbytes in $WHERE
exit 0
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top