Check-in [977dfa7ac1]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Import stable-15.12.24.10 of svn backup scripts Import stable-15.12.24.10 of svn backup scripts from ansible repository. Use constants for trace levels when logging. This makes the code significantly more legible. While here, do some whitespace cleanup.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:977dfa7ac10531497cb4245559acad45e48dbe33
User & Date: cfuhrman 2015-12-24 15:23:47
Context
2016-06-02
05:34
Initial entry of script meant to cook iMac Since my iMac is overheating, write a script that will surely cause it to overheat whilst in the Apple Store. check-in: 650e8c59b1 user: cfuhrman tags: trunk
2015-12-24
15:23
Import stable-15.12.24.10 of svn backup scripts Import stable-15.12.24.10 of svn backup scripts from ansible repository. Use constants for trace levels when logging. This makes the code significantly more legible. While here, do some whitespace cleanup. check-in: 977dfa7ac1 user: cfuhrman tags: trunk
2015-08-19
16:19
Merge open leaf check-in: 8ac2e092d1 user: cfuhrman tags: trunk
Changes

Changes to scm/svnbackup.sh.

1
2
3
4
5
6
7
8
9
10
11
12
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
...
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/usr/bin/env bash
# ======================================================================
#
# $Id$
#
# Copyright (c) 2007-2009,2011-2012 Christopher M. Fuhrman
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
................................................................................
# DEPENDENCIES:
#
#   bash 2.05 or greater
#
# ======================================================================

# Includes
source trace.sh

# Globals
BACKUP_HOME=.
REPO_PATH=
LOG_LEVEL=1
USE_GZIP=0
USE_BZIP=0
................................................................................

headerDisplay ()
{

        MYREV='$Rev'

        echo "============================================="
        echo -n "SVN Backup - "
        echo '$Rev$'
        echo ""
        echo "Copyright (c) 2007-2009,2011-2012 Christopher M. Fuhrman"
        echo "---------------------------------------------"
        echo ""
        echo "SVN backup run on :"
        date
        echo ""
................................................................................

        if svnlook youngest $DIR >/dev/null; then
                return 1
        else
                return 0
        fi

        #
        # NOT REACHED
        #

} # isSubversionRepo()

##
# Backs up a repository
#
# @param repo - path to repository

................................................................................
repoBackup ()
{

        local REPO=$1
        local REPO_BASE=${REPO##*/}
        local REPO_BACKUP_DIR=${BACKUP_HOME}/${REPO_BASE}
        local WEEK_BACKUP_DIR=${REPO_BACKUP_DIR}/${WEEKSTAMP}
        
        Trace 4 "Backing up Subversion repository ${REPO}"

        # Does our backup directory for our week exist?
        if [ ! -d $WEEK_BACKUP_DIR ]; then
                Trace 5 "Creating directory $WEEK_BACKUP_DIR"
                
                if ! mkdir -p ${WEEK_BACKUP_DIR}; then
                        Trace 1 "Unable to make ${REPO_BACKUP_DIR}.  Aborting"
                        exit 1
                fi
                
        fi

        # Perform backup
        if [ -f ${WEEK_BACKUP_DIR}/${LASTBACKUP} ]; then
                repoBackupIncremental ${REPO} ${WEEK_BACKUP_DIR}
        else
                repoBackupFull ${REPO} ${WEEK_BACKUP_DIR}
        fi

        if [ ${SKIPFLAG} -eq 0 ]; then
                Trace 3 "(${REPO_BASE}) Backup of ${REPO} successful"
        fi

} # repoBackup()

##
# Performs full backup of repository
#
................................................................................

        local REPO=$1
        local BKPATH=$2
        local REPO_BASE=${REPO##*/}
        local REV=`svnlook youngest ${REPO} | tr -d '\n'`
        local BACKUP_FILE=`printf "%s-full-r%d" $REPO_BASE $REV`

        Trace 4 "Performing a full backup of $REPO_BASE through revision ${REV}"
        Trace 5 "CURRENT_REVISION:${REV}:BACKUP_FILE:${BACKUP_FILE}"

        # Construct command line option
        local COMMAND="${SVNADMIN}"

        # Suppress output unless we're in debug mode
        if [ ${LOG_LEVEL} -ne 5 ]; then
                COMMAND="${COMMAND} -q"
................................................................................
        elif [ ${USE_GZIP} -eq 1 ]; then
                BACKUP_FILE="${BACKUP_FILE}.gz"
                COMMAND="${COMMAND} | ${COMPZ} > ${BKPATH}/${BACKUP_FILE}"
        else
                COMMAND="${COMMAND} > ${BKPATH}/${BACKUP_FILE}"
        fi

        Trace 5 "Running command: $COMMAND"

        # Run command verifying output
        if ! eval ${COMMAND}; then
                Trace 1 "Unable to backup repository $REPO_BASE to ${BKPATH}/${BACKUP_FILE}"
                exit 1
        fi

        # Echo full backup revision to appropriate file
        echo ${REV} > "${BKPATH}/${LASTBACKUP}"

        Trace 4 "Dumped full backup of ${REPO_BASE} to ${BACKUP_FILE}"

} # repoBackupFull()

##
# Performs incremental backup of repository
#
# @param repo - full path to repository
................................................................................

        # Determine what base revision we use
        if [[ ${DIFFERENTIAL} -ne 1 \
            && -f "${BKPATH}/LAST_INCR_REV.txt" ]]; then
                LAST_INCR_REV=`cat ${BKPATH}/LAST_INCR_REV.txt | tr -d '\n'`
        else
                LAST_INCR_REV=$FULLREV
        fi        

        # Is there anything to back up?
        if [ ${LAST_INCR_REV} -eq ${REV} ]; then
                Trace 2 "($REPO_BASE) There have been no changes since revision ${LAST_INCR_REV}.  Skipping backup"
                SKIPFLAG=1
                return 1
        fi

        # If we are only backing up one revision, then name backup
        # file accordingly
        STARTREV=$((LAST_INCR_REV + 1))
        if [ ${STARTREV} -eq ${REV} ]; then
                local BACKUP_FILE=`printf "%s-${BKTYPE_ABBR}-r%d" ${REPO_BASE} ${REV}`
                Trace 4 "Performing an incremental backup of revision ${STARTREV}"
        else
                local BACKUP_FILE=`printf "%s-${BKTYPE_ABBR}-r%d-r%d" ${REPO_BASE} ${STARTREV} ${REV}`
                Trace 4 "Performing an ${BKTYPE} backup between revision ${STARTREV} and ${REV} (inclusive)"
        fi

        COMMAND="${COMMAND} dump --incremental -r${STARTREV}:${REV} ${REPO}"
        
        # Do we compress?
        if [ ${USE_BZIP} -eq 1 ]; then
                BACKUP_FILE="${BACKUP_FILE}.bz2"
                COMMAND="${COMMAND} | ${COMPJ} > ${BKPATH}/${BACKUP_FILE}"
        elif [ ${USE_GZIP} -eq 1 ]; then
                BACKUP_FILE="${BACKUP_FILE}.gz"
                COMMAND="${COMMAND} | ${COMPZ} > ${BKPATH}/${BACKUP_FILE}"
        else
                COMMAND="${COMMAND} > ${BKPATH}/${BACKUP_FILE}"
        fi

        Trace 5 "START REV:${STARTREV}:CURRENT REV:${REV}:BACKUP FILE:${BACKUP_FILE}"

        # Run command verifying output
        if ! eval ${COMMAND}; then
                Trace 1 "Unable to backup repository $REPO_BASE to ${BKPATH}/${BACKUP_FILE}"
                exit 1
        fi

        # Echo the current revision to appropriate file
        echo ${REV} > "${BKPATH}/LAST_INCR_REV.txt"

        Trace 4 "Dumped ${BKTYPE} backup of ${REPO_BASE} to ${BACKUP_FILE}"

} # repoBackupIncremental()


##
# Displays usage

................................................................................
                    -z Compress w/ gzip                     \\
                    -j Compress w/ bzip2                    \\
                    -l Log level (1 - 4)                    \\
                    -d use differential backups             \\
                    -r Recurse repostories                  \\
                    -m [default:1] Max depth to recurse     \\
                    </path/to/repository>
                     
STDERR

} # usage()

# --------------------------------------------------------------------

# Set umask as appropriate
umask 077

# Process command line options
args=`getopt hzjdrb:l:m: $*`

if [ $? -ne 0 ]; then
        usage
        exit 2
................................................................................
done

# Last item should be repository (note we strip trailing /)
REPO_PATH=${1%/}

# Validate repo path
if [ ! -d ${REPO_PATH} ]; then
        echo "ERROR : Repository path ${REPO_PATH} not found"

        usage
        exit 1
fi

Level ${LOG_LEVEL}
headerDisplay

Trace 4 "Starting"

if [ ${RECURSE} -eq 1 ]; then

        DIRECTORIES=$( find ${REPO_PATH} -type d -maxdepth ${MAXDEPTH} )

        for directory in ${DIRECTORIES};
        do
                isSubversionRepo ${directory}
                if [ $? -eq 1 ]; then
                        repoBackup ${directory}
                        Trace 4 "${directory} backed up"
                        SKIPFLAG=0
                else
                        Trace 2 "${directory} is not a subversion repository ... Skipping"
                fi

        done

else
        isSubversionRepo ${REPO_PATH}
        if [ $? -eq 1 ]; then
                repoBackup ${REPO_PATH}
        else
                Trace 2 "${REPO} is _not_ a valid SVN repository"
                Trace 1 "Aborting"
                exit 1

        fi
fi

Trace 4 "Stopping"

# Ende



<
<







 







|







 







|
<







 







<
<
<
<







 







|
|



|
|

|


|










|







 







|
|







 







|



|






|







 







|



|









|


|



|











|



|






|







 







|







|







 







|
>







|










|


|









|
|





|


1
2
3


4
5
6
7
8
9
10
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
...
103
104
105
106
107
108
109




110
111
112
113
114
115
116
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/usr/bin/env bash
# ======================================================================
#


# Copyright (c) 2007-2009,2011-2012 Christopher M. Fuhrman
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
................................................................................
# DEPENDENCIES:
#
#   bash 2.05 or greater
#
# ======================================================================

# Includes
source /usr/local/lib/trace.sh

# Globals
BACKUP_HOME=.
REPO_PATH=
LOG_LEVEL=1
USE_GZIP=0
USE_BZIP=0
................................................................................

headerDisplay ()
{

        MYREV='$Rev'

        echo "============================================="
        echo "SVN Backup"

        echo ""
        echo "Copyright (c) 2007-2009,2011-2012 Christopher M. Fuhrman"
        echo "---------------------------------------------"
        echo ""
        echo "SVN backup run on :"
        date
        echo ""
................................................................................

        if svnlook youngest $DIR >/dev/null; then
                return 1
        else
                return 0
        fi





} # isSubversionRepo()

##
# Backs up a repository
#
# @param repo - path to repository

................................................................................
repoBackup ()
{

        local REPO=$1
        local REPO_BASE=${REPO##*/}
        local REPO_BACKUP_DIR=${BACKUP_HOME}/${REPO_BASE}
        local WEEK_BACKUP_DIR=${REPO_BACKUP_DIR}/${WEEKSTAMP}

        Trace $INFO "Backing up Subversion repository ${REPO}"

        # Does our backup directory for our week exist?
        if [ ! -d $WEEK_BACKUP_DIR ]; then
                Trace $DEBG "Creating directory $WEEK_BACKUP_DIR"

                if ! mkdir -p ${WEEK_BACKUP_DIR}; then
                        Trace $CRIT "Unable to make ${REPO_BACKUP_DIR}.  Aborting"
                        exit 1
                fi

        fi

        # Perform backup
        if [ -f ${WEEK_BACKUP_DIR}/${LASTBACKUP} ]; then
                repoBackupIncremental ${REPO} ${WEEK_BACKUP_DIR}
        else
                repoBackupFull ${REPO} ${WEEK_BACKUP_DIR}
        fi

        if [ ${SKIPFLAG} -eq 0 ]; then
                Trace $DEBG "(${REPO_BASE}) Backup of ${REPO} successful"
        fi

} # repoBackup()

##
# Performs full backup of repository
#
................................................................................

        local REPO=$1
        local BKPATH=$2
        local REPO_BASE=${REPO##*/}
        local REV=`svnlook youngest ${REPO} | tr -d '\n'`
        local BACKUP_FILE=`printf "%s-full-r%d" $REPO_BASE $REV`

        Trace $INFO "Performing a full backup of $REPO_BASE through revision ${REV}"
        Trace $DEBG "CURRENT_REVISION:${REV}:BACKUP_FILE:${BACKUP_FILE}"

        # Construct command line option
        local COMMAND="${SVNADMIN}"

        # Suppress output unless we're in debug mode
        if [ ${LOG_LEVEL} -ne 5 ]; then
                COMMAND="${COMMAND} -q"
................................................................................
        elif [ ${USE_GZIP} -eq 1 ]; then
                BACKUP_FILE="${BACKUP_FILE}.gz"
                COMMAND="${COMMAND} | ${COMPZ} > ${BKPATH}/${BACKUP_FILE}"
        else
                COMMAND="${COMMAND} > ${BKPATH}/${BACKUP_FILE}"
        fi

        Trace $DEBG "Running command: $COMMAND"

        # Run command verifying output
        if ! eval ${COMMAND}; then
                Trace $CRIT "Unable to backup repository $REPO_BASE to ${BKPATH}/${BACKUP_FILE}"
                exit 1
        fi

        # Echo full backup revision to appropriate file
        echo ${REV} > "${BKPATH}/${LASTBACKUP}"

        Trace $INFO "Dumped full backup of ${REPO_BASE} to ${BACKUP_FILE}"

} # repoBackupFull()

##
# Performs incremental backup of repository
#
# @param repo - full path to repository
................................................................................

        # Determine what base revision we use
        if [[ ${DIFFERENTIAL} -ne 1 \
            && -f "${BKPATH}/LAST_INCR_REV.txt" ]]; then
                LAST_INCR_REV=`cat ${BKPATH}/LAST_INCR_REV.txt | tr -d '\n'`
        else
                LAST_INCR_REV=$FULLREV
        fi

        # Is there anything to back up?
        if [ ${LAST_INCR_REV} -eq ${REV} ]; then
                Trace $NOTI "($REPO_BASE) There have been no changes since revision ${LAST_INCR_REV}.  Skipping backup"
                SKIPFLAG=1
                return 1
        fi

        # If we are only backing up one revision, then name backup
        # file accordingly
        STARTREV=$((LAST_INCR_REV + 1))
        if [ ${STARTREV} -eq ${REV} ]; then
                local BACKUP_FILE=`printf "%s-${BKTYPE_ABBR}-r%d" ${REPO_BASE} ${REV}`
                Trace $INFO "Performing an incremental backup of revision ${STARTREV}"
        else
                local BACKUP_FILE=`printf "%s-${BKTYPE_ABBR}-r%d-r%d" ${REPO_BASE} ${STARTREV} ${REV}`
                Trace $INFO "Performing an ${BKTYPE} backup between revision ${STARTREV} and ${REV} (inclusive)"
        fi

        COMMAND="${COMMAND} dump --incremental -r${STARTREV}:${REV} ${REPO}"

        # Do we compress?
        if [ ${USE_BZIP} -eq 1 ]; then
                BACKUP_FILE="${BACKUP_FILE}.bz2"
                COMMAND="${COMMAND} | ${COMPJ} > ${BKPATH}/${BACKUP_FILE}"
        elif [ ${USE_GZIP} -eq 1 ]; then
                BACKUP_FILE="${BACKUP_FILE}.gz"
                COMMAND="${COMMAND} | ${COMPZ} > ${BKPATH}/${BACKUP_FILE}"
        else
                COMMAND="${COMMAND} > ${BKPATH}/${BACKUP_FILE}"
        fi

        Trace $DEBG "START REV:${STARTREV}:CURRENT REV:${REV}:BACKUP FILE:${BACKUP_FILE}"

        # Run command verifying output
        if ! eval ${COMMAND}; then
                Trace $CRIT "Unable to backup repository $REPO_BASE to ${BKPATH}/${BACKUP_FILE}"
                exit 1
        fi

        # Echo the current revision to appropriate file
        echo ${REV} > "${BKPATH}/LAST_INCR_REV.txt"

        Trace $NOTI "Dumped ${BKTYPE} backup of ${REPO_BASE} to ${BACKUP_FILE}"

} # repoBackupIncremental()


##
# Displays usage

................................................................................
                    -z Compress w/ gzip                     \\
                    -j Compress w/ bzip2                    \\
                    -l Log level (1 - 4)                    \\
                    -d use differential backups             \\
                    -r Recurse repostories                  \\
                    -m [default:1] Max depth to recurse     \\
                    </path/to/repository>

STDERR

} # usage()

# --------------------------------------------------------------------

# Set umask as appropriate
umask 007

# Process command line options
args=`getopt hzjdrb:l:m: $*`

if [ $? -ne 0 ]; then
        usage
        exit 2
................................................................................
done

# Last item should be repository (note we strip trailing /)
REPO_PATH=${1%/}

# Validate repo path
if [ ! -d ${REPO_PATH} ]; then
        MESSAGE="ERROR : Repository path ${REPO_PATH} not found"
        Trace $CRIT $MESSAGE
        usage
        exit 1
fi

Level ${LOG_LEVEL}
headerDisplay

Trace $INFO "Starting"

if [ ${RECURSE} -eq 1 ]; then

        DIRECTORIES=$( find ${REPO_PATH} -type d -maxdepth ${MAXDEPTH} )

        for directory in ${DIRECTORIES};
        do
                isSubversionRepo ${directory}
                if [ $? -eq 1 ]; then
                        repoBackup ${directory}
                        Trace $INFO "${directory} backed up"
                        SKIPFLAG=0
                else
                        Trace $WARN "${directory} is not a subversion repository ... Skipping"
                fi

        done

else
        isSubversionRepo ${REPO_PATH}
        if [ $? -eq 1 ]; then
                repoBackup ${REPO_PATH}
        else
                Trace $WARN "${REPO} is _not_ a valid subversion repository"
                Trace $CRIT "Aborting"
                exit 1

        fi
fi

Trace $INFO "Stopping"

# Ende

scm/trace.sh became a symlink.

Changes to util/trace.sh.

1
2
3
4
5

6
7
8
9
10
11
12
13
14
..
36
37
38
39
40
41
42







43
44
45
46
47
48
49
#!/usr/bin/env bash
# ====================================================================
# File: trace.sh
#
# $Id$

#
# Copyright (c) 2010-2011 Christopher M. Fuhrman
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#    * Redistributions of source code must retain the above copyright
................................................................................
#
#   Provides tracing function for logging purposes
#

# Set default trace level
TRACE=1








# --------------------------------------------------------------------

##
# Getter/Setter for trace level
#
# @param: level - Level to set to
#


<

<
>

|







 







>
>
>
>
>
>
>







1
2

3

4
5
6
7
8
9
10
11
12
13
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# ====================================================================

#

# $Id: trace.sh 1232 2012-03-16 17:41:15Z cfuhrman $
#
# Copyright (c) 2010, Christopher M. Fuhrman
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#    * Redistributions of source code must retain the above copyright
................................................................................
#
#   Provides tracing function for logging purposes
#

# Set default trace level
TRACE=1

# Constants
export CRIT=1
export WARN=2
export NOTI=3
export INFO=4
export DEBG=5

# --------------------------------------------------------------------

##
# Getter/Setter for trace level
#
# @param: level - Level to set to
#