Librenix
Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

Shadow.sh: A simple directory shadowing script for Linux

Up
vote
Down

Are you ever editing away on some program or document and suddenly realize that you're progressing down the wrong path? And then realize that the version you had two hours ago was the one you now need? Yes, the earlier version that you've since edited into something quite different is the one you wish you could have back.

The following script is designed to help solve that problem as well as a few related ones, automatically. This script, shadow.sh, lets you take periodic snapshots of your document directory -- or source code directory -- and make backup copies of everything there. Further, it will keep the previous few versions of each file that you modify as well as the most recent version. The latest backup directory version of a file will have the same name as the original. The next oldest will have a .0 extension, and the version older than .0 will have a .1 extension, etc.

This little script is no replacement for a general purpose document management system, but it has its advantages. Once set up, it is automatic. It also works in situations where files change without direct human management.

I run the script automatically every hour on my main source code directory with a cron entry similar to this one:

0 * * * * /rayy/shadow.sh /rayy/sdir /rayy/bdir

This crontab line also demonstrates the parameters that shadow.sh requires which are simply the source directory name and the backup directory name:

shadow.sh [sourcedirectory] [backupdirectory]

You can, of course, run it manually using syntax similar to the above to test it out and to see how it works.

Type crontab -e from your shell prompt to create a new cron entry. If you are unfamiliar with cron, you can get more information on how to add and edit your crontab entries by typing man crontab at your shell prompt.

This version of the script keeps up to five versions of each changing file. Changing it to keep more or fewer versions of each file should be trivial. However, if you are not an experienced shell programmer, be very careful, use a test directory with no important files, and read the disclaimer below!

You can download the script by right clicking here and selecting "Save link..." and you can view it in your browser by clicking here. You can run it with no parameters for a quick synopsis of its useage.

The script is released under the terms of the GPL, version 2.

While this script is labeled 'for Linux', it should work just as well under any Unix variant by simply changing the pathnames for the commands to the appropriate locations for that system. Also, ksh can be used instead of bash on traditional Unix systems that don't have bash installed.

Disclaimer:
This script is free and comes with no guarantees of any kind. It has virtually no safeguards and might be tricky to modify since it recursively calls itself in order to copy arbitrary numbers of files and subdirectories elsewhere. It is probably possible to wipe out your files or fill up your disk drive so consider yourself warned! Neither Librenix.com or the author take any responsibility for any disasters that may arise out or your use of, or inability to use, this script.

-Ray Yeargin
mail this link | score:8818 | -Ray, May 20, 2002 (Updated: April 18, 2007)
More Sysadmin articles...

Buy Art Online with Satisfaction Guaranteed

admin headlines

Gluster 3.4.2 on Two Node Controller+Compute Neutron GRE+OVS Fedora 20 Cluster

Installing Debian testing On GPT HDDs From A Grml Live Linux

Quantum basic RDO setup (grizzly) to have original LAN as external on CentOS 6.4

Step By Step Ubuntu 13.04 (Raring Ringtail) LAMP Server Setup

How to install S3QL from source on Fedora 19

Install and use OpenVZ on Ubuntu 13.04

Virtual Users/Domains with Postfix/Courier/MySQL/SquirrelMail (Debian 7)

Create a Fiber Channel SAN with SCST and QLogic HBA on Linux Debian 6

Installing FreeIPA with Replication

Secure ISPConfig 3 And Services with GoDaddy Signed Certificate on CentOS

tutorial: Build a Debian 7 server

Setting up ProFTPd + TLS on Ubuntu 12.10

Tutorial: Install Apache2, PHP5, MySQL on OpenSUSE 12.3

KVM Virtualization on CentOS 6.4

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

 
Articles are owned by their authors.   © 2000-2012 Ray Yeargin