summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordermoth <dermoth@nagiosplugins.org>2009-11-11 10:23:57 (GMT)
committerdermoth <dermoth@nagiosplugins.org>2009-11-11 10:34:22 (GMT)
commitbb193973a8767547edc8626df6cea7d154812de5 (patch)
tree153a37369b22069a3b82289e1ebec7ef225ba854 /tools
parent2b442ff177751c5ea17e792c10e6d50d7b922b08 (diff)
downloadmonitoring-plugins-bb193973a8767547edc8626df6cea7d154812de5.tar.gz
Many fixes to snapshot scripts
sfsnapshotgit: - Use fetch/reset instead to pull to avoid merges on forced updates sfsnapshot-upload: - Fix link deletion walking the entire home dir - Allow CLEAN_TIME=0 (no retention) - Re-add per-branch links when CLEAN_TIME > 0 - Add many comments
Diffstat (limited to 'tools')
-rwxr-xr-xtools/sfsnapshot-upload60
-rwxr-xr-xtools/sfsnapshotgit5
2 files changed, 43 insertions, 22 deletions
diff --git a/tools/sfsnapshot-upload b/tools/sfsnapshot-upload
index e0a2300..5134e00 100755
--- a/tools/sfsnapshot-upload
+++ b/tools/sfsnapshot-upload
@@ -8,7 +8,7 @@
8 8
9# Handle command errors (-e) and coder sleep deprivation issues (-u) 9# Handle command errors (-e) and coder sleep deprivation issues (-u)
10set -eu 10set -eu
11trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT 11trap 'echo "An error occurred in sfsnapshot-upload at line $LINENO"; exit 1' EXIT
12 12
13# This can be used to override the default in sfsnapshotgit: 13# This can be used to override the default in sfsnapshotgit:
14export SFSNAP_REPO=~/staging/nagiosplugins 14export SFSNAP_REPO=~/staging/nagiosplugins
@@ -19,7 +19,7 @@ export SFSNAP_DEST=~/staging/snapshot
19# The file we'll use to create the snapshot 19# The file we'll use to create the snapshot
20sfsnapshot=~/sfsnapshotgit 20sfsnapshot=~/sfsnapshotgit
21 21
22# Retention time for snapshots (in minutes) 22# Retention time for snapshots (in minutes), 0 for no retention.
23CLEAN_TIME=1440 23CLEAN_TIME=1440
24 24
25# Where to place the generated files 25# Where to place the generated files
@@ -39,16 +39,31 @@ else
39 HEADS=$@ 39 HEADS=$@
40fi 40fi
41 41
42# If we don't keep old snapshots we can clean up all links now
43if [ $CLEAN_TIME -eq 0 ]
44then
45 find $SFSNAP_DEST -type l -name '*.gz' -delete
46fi
47
42for head in $HEADS ; do 48for head in $HEADS ; do
49 # This runs the actual snapshot code. It creates new snapshots if needed and always
50 # return the current snapshot file (even if it wasn't modified).
43 file=$($sfsnapshot $head) 51 file=$($sfsnapshot $head)
52 # Create main head link
44 ln -sf $file $SFSNAP_DEST/nagios-plugins-$head.tar.gz 53 ln -sf $file $SFSNAP_DEST/nagios-plugins-$head.tar.gz
45 # Keep links by branch name too 54
46 [ -f "$SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-}" ] || ln -s $file $SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-} 55 # Keep links by branch name too if we keep old snapshots, so we can keep tracks of them
56 if [ $CLEAN_TIME -gt 0 -a ! -e "$SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-}" ]
57 then
58 ln -s $file $SFSNAP_DEST/nagios-plugins-$head-${file#nagios-plugins-}
59 fi
60
61 # Cleanup and re-create backward-compatibility links
47 if [ "$head" == "master" ] 62 if [ "$head" == "master" ]
48 then 63 then
49 for cclean in $COMPATCLEANUP 64 for cclean in $COMPATCLEANUP
50 do 65 do
51 find . -type l -name "nagios-plugins-$cclean.tar.gz" -delete 66 find $SFSNAP_DEST -type l -name "nagios-plugins-$cclean.tar.gz" -delete
52 done 67 done
53 for compat in $COMPATLINKS 68 for compat in $COMPATLINKS
54 do 69 do
@@ -57,40 +72,45 @@ for head in $HEADS ; do
57 fi 72 fi
58done 73done
59 74
60# Cleanup old snapshots and links...
61cd $SFSNAP_DEST 75cd $SFSNAP_DEST
62 76
63# Clean up links older than $CLEAN_TIME 77# Clean up links older than $CLEAN_TIME if needed
64find . -type l -name '*.gz' -mmin +$CLEAN_TIME -delete 78if [ $CLEAN_TIME -gt 0 ]
79then
80 find . -type l -name '*.gz' -mmin +$CLEAN_TIME -delete
81fi
65 82
66# Then clean up files that we don't need 83# Now clean up files that we don't need
84# 1. loop over actual snapshots
67for dest in `find . -type f -name '*.gz' |xargs -n 1 basename` 85for dest in `find . -type f -name '*.gz' |xargs -n 1 basename`
68do 86do
69 # Loop over the list of linked-to files 87 # 2. Loop over the list of linked-to files
70 for current in `find . -type l -name '*.gz' |xargs -n 1 readlink | uniq` 88 for current in `find . -type l -name '*.gz' |xargs -n 1 readlink | sort | uniq`
71 do 89 do
72 if [ "$current" == "$dest" ] 90 if [ "$current" == "$dest" ]
73 then 91 then
92 # File is being linked to - don't delete (continue first loop)
74 continue 2 93 continue 2
75 fi 94 fi
76 done 95 done
96 # No link to this file, we can drop it
77 rm -f $dest 97 rm -f $dest
78done 98done
79 99
80# Create MD5 sum 100# Create MD5 sum
81cat <<-END_README > README 101cat <<-END_README > README
82This is the latest snapshot of nagiosplug, consisting of the following 102 This is the latest snapshot of nagiosplug, consisting of the following
83head(s): 103 head(s):
84 $HEADS 104 $HEADS
85 105
86The nagios-plugins-<head>.tar.gz link will always point to the latest 106 The nagios-plugins-<head>.tar.gz link will always point to the latest
87corresponding snapshot (nagios-plugins-<git-describe>.tar.gz). 107 corresponding snapshot (nagios-plugins-<git-describe>.tar.gz).
88 108
89For backward-compatibility, the nagios-plugins-HEAD.tar.gz and 109 For backward-compatibility, the nagios-plugins-HEAD.tar.gz and
90nagios-plugins-trunk-<ts> point to their corresponding "master" head. 110 nagios-plugins-trunk-<ts> point to their corresponding "master" head.
91 111
92The MD5SUM are: 112 The MD5SUM are:
93END_README 113 END_README
94md5sum *.gz | tee -a README > MD5SUM 114md5sum *.gz | tee -a README > MD5SUM
95 115
96# Sync the files 116# Sync the files
diff --git a/tools/sfsnapshotgit b/tools/sfsnapshotgit
index 155259f..af05c24 100755
--- a/tools/sfsnapshotgit
+++ b/tools/sfsnapshotgit
@@ -9,7 +9,7 @@
9 9
10# Handle command errors (-e) and coder sleep deprivation issues (-u) 10# Handle command errors (-e) and coder sleep deprivation issues (-u)
11set -eu 11set -eu
12trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT 12trap 'echo "An error occurred in sfsnapshotgit at line $LINENO"; exit 1' EXIT
13 13
14# Send all command output to STDERR while allowing us to write to STDOUT 14# Send all command output to STDERR while allowing us to write to STDOUT
15# using fd 3 15# using fd 3
@@ -46,7 +46,8 @@ git reset --hard
46git clean -qfdx 46git clean -qfdx
47# Any branch used to create snapshots must already exist 47# Any branch used to create snapshots must already exist
48git checkout "$HEAD" 48git checkout "$HEAD"
49git pull "$SFSNAP_ORIGIN" "$HEAD" 49git fetch "$SFSNAP_ORIGIN" "$HEAD"
50git reset --hard "$SFSNAP_ORIGIN"/"$HEAD"
50# Tags are important for git-describe 51# Tags are important for git-describe
51git fetch --tags "$SFSNAP_ORIGIN" 52git fetch --tags "$SFSNAP_ORIGIN"
52 53