×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

UNIX Scripting FAQ

Tips and Tricks

Fast Personal Backup by gamerland
Posted: 24 Apr 03

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

Back to UNIX Scripting FAQ Index
Back to UNIX Scripting Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close