File: shared.sh.in

package info (click to toggle)
rdup 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 784 kB
  • ctags: 108
  • sloc: sh: 3,225; ansic: 1,624; perl: 565; makefile: 65
file content (65 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download
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

# source this file to get some commonly
# used functions in the rdup-utils.

# show the version of the tool
version() {
        echo "$PROGNAME: @PACKAGE_VERSION@ (rdup-utils)"
}

# cleanup any stuff and exit
cleanup() {
        _echo2 "Signal received while processing \`$path', exiting"
        if [[ ! -z $TMPDIR ]]; then
                rm -rf $TMPDIR
        fi
        unlock /var/lock/rdup
        exit 1
}

# echo to standard error
_echo2() {
        echo "** $PROGNAME: $1" >&2
}

# find out what kind of snapshot to make
what() {
        _DAYS=$1
        _BACKUPDIR=$2
        _NOW=$3
        i=1
        if [[ -d $_BACKUPDIR/$_NOW ]]; then
                # already there do not link
                return 0
        fi
        # linux thing
        while [[ $i -le $DAYS ]]; do
                dir=`$GNU_DATE +%Y%m/%d --date "$i days ago"`
                if [[ -d $_BACKUPDIR/$dir ]]; then
                        # copy 'em over
                        _echo2 "Linking dir: \`$_BACKUPDIR/$dir'"
                        $GNU_CP -plr $_BACKUPDIR/$dir $_BACKUPDIR/$_NOW
                        return 0
                fi
        (( i++ ))
        done
        return 1
}

# create ~/.rdup
create_rdup() {
	if [[ ! -d $1 ]]; then
		mkdir $1
	fi
	return 0
}

lock() {
        (umask 222; echo "Backup locked by PID: $$" >"$1" ) ||
                (cat "$1" ; echo "aborting..." ; exit 1)
        [ $? = 0 ] || exit 1
}

unlock() {
        rm -f "$1"
}