File: filetraq

package info (click to toggle)
filetraq 0.3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 124 kB
  • sloc: sh: 182; makefile: 1
file content (92 lines) | stat: -rwxr-xr-x 2,236 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh

# FileTraq v0.2
# Copyright (c) 2000 Jeremy Weatherford
# See COPYING file included with distribution

# v0.1: first release
# v0.2: incorporates changes suggested by Chris Ausbrooks

# designed to be run periodically from any root's crontab, with output going in mail to root

# Defaults file

defaults=/etc/default/filetraq

# scans /etc/filetraq.conf unless given a different list

file=/etc/filetraq.conf

# uses /var/lib/filetraq for backups unless given a different dir

backupdir=/var/lib/filetraq

# diff options
diffopts="-p -C 1"
# diff order
difforder="newold"

# Source defaults file if available
test -f $defaults && . $defaults

if [ "$1" != "" ]; then
	if [ "$1" = "--help" ]; then
		echo "FileTraq version 0.2"
		echo "Syntax: $0 [filelist] [backupdir]";
		echo "Defaults can be set in '/etc/default/filetraq'."
		echo "If no filelist is specified, default is $file."
		echo "If no backupdir is specified, default is $backupdir."
		exit
	fi
	if [ ! -r $1 ]; then
		echo "Filelist $1 does not exist or cannot be read."
		exit
	fi
	file=$1
fi

if [ "$2" != "" ]; then
	if [ ! -d $2 ]; then
		echo "Backupdir $2 is not a directory."
		exit
	fi
	backupdir=$2
fi

# Exit quietly if there's no config file
test -r "$file" || exit 0

eval ls -1 `sed -n -e '/^[^#]/ { s/ /\\ /g; p; }' "$file"` 2> /dev/null | while read entry; do
    find "$entry" -xtype f 2> /dev/null | while read name; do
	if [ ! -e "$name" ]; then
	    echo "File not found, or pattern didn't match any files: $entry"
	    break
	else
	    bdir="$backupdir/`echo "$name"`"
	    test -d "$bdir" || mkdir -p "$bdir"
	    backup="$bdir/orig"
	    if [ ! -e "$backup" ]; then
		echo "Creating first backup of $name."
		cp -pRLf "$name" "$backup"
	    else
		if [ "$difforder" = "oldnew" ]; then
		  diff $diffopts "$backup" "$name"
		else
		  diff $diffopts "$name" "$backup"
		fi
		
		ret=$?
		if [ $ret = 1 ]; then
		    # changes to save
		    cp -pRLf "$backup" "$backup.`date +%m.%d.%y__%H.%M`"
		    cp -pRLf "$name" "$backup"
		fi
		if [ $ret = 2 ]; then
		    echo "Recording changes in binary file $name in backupdir"
		    cp -pRLf "$backup" "$backup.`date +%m.%d.%y__%H.%M`"
		    cp -pRLf "$name" "$backup"
		fi
	    fi
	fi
    done
done