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:8843 | -Ray, May 20, 2002 (Updated: April 18, 2007)
More Sysadmin articles...

Buy Art Online with a Free Return Policy

admin headlines

Tutorial: Debian 7 Samba Server with tdbsam

Tutorial: LinOTP on OpenSuSE 12.3 with PostgreSQL

Setting up NFS on Scientific Linux 6.3

Installing Apache2 With PHP5 And MySQL Support On Fedora 18 (LAMP)

Using AoE on Ubuntu 12.10

Tutorial: PHP5-FPM with Apache2 on OpenSUSE 12.2

nginx: Block Visitors by Country with GeoIP Module (Debian/Ubuntu)

ProFTPd: Enable TLS by user or group

Howto: Unity with Dodge Windows behavior in Ubuntu 12.04

Install MySQL-Frontend Chive (A phpMyAdmin Alternative)

KVM Virtualization on OpenSUSE 12.1

Install Maia Mailguard, MySQL, Postfix on Debian 6

Set up Network RAID1 with DRBD on Ubuntu 11.10

Tutorial: Install Repcached (memcached replication) for high-availability on 2 nodes on Ubuntu 11.04

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

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