diff options
author | dermoth <dermoth@nagiosplugins.org> | 2009-11-11 10:23:57 +0000 |
---|---|---|
committer | dermoth <dermoth@nagiosplugins.org> | 2009-11-11 10:34:22 +0000 |
commit | bb193973a8767547edc8626df6cea7d154812de5 (patch) | |
tree | 153a37369b22069a3b82289e1ebec7ef225ba854 /tools | |
parent | 2b442ff177751c5ea17e792c10e6d50d7b922b08 (diff) | |
download | monitoring-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-x | tools/sfsnapshot-upload | 60 | ||||
-rwxr-xr-x | tools/sfsnapshotgit | 5 |
2 files changed, 43 insertions, 22 deletions
diff --git a/tools/sfsnapshot-upload b/tools/sfsnapshot-upload index e0a2300c..5134e000 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) |
10 | set -eu | 10 | set -eu |
11 | trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT | 11 | trap '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: |
14 | export SFSNAP_REPO=~/staging/nagiosplugins | 14 | export 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 |
20 | sfsnapshot=~/sfsnapshotgit | 20 | sfsnapshot=~/sfsnapshotgit |
21 | 21 | ||
22 | # Retention time for snapshots (in minutes) | 22 | # Retention time for snapshots (in minutes), 0 for no retention. |
23 | CLEAN_TIME=1440 | 23 | CLEAN_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=$@ |
40 | fi | 40 | fi |
41 | 41 | ||
42 | # If we don't keep old snapshots we can clean up all links now | ||
43 | if [ $CLEAN_TIME -eq 0 ] | ||
44 | then | ||
45 | find $SFSNAP_DEST -type l -name '*.gz' -delete | ||
46 | fi | ||
47 | |||
42 | for head in $HEADS ; do | 48 | for 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 |
58 | done | 73 | done |
59 | 74 | ||
60 | # Cleanup old snapshots and links... | ||
61 | cd $SFSNAP_DEST | 75 | cd $SFSNAP_DEST |
62 | 76 | ||
63 | # Clean up links older than $CLEAN_TIME | 77 | # Clean up links older than $CLEAN_TIME if needed |
64 | find . -type l -name '*.gz' -mmin +$CLEAN_TIME -delete | 78 | if [ $CLEAN_TIME -gt 0 ] |
79 | then | ||
80 | find . -type l -name '*.gz' -mmin +$CLEAN_TIME -delete | ||
81 | fi | ||
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 | ||
67 | for dest in `find . -type f -name '*.gz' |xargs -n 1 basename` | 85 | for dest in `find . -type f -name '*.gz' |xargs -n 1 basename` |
68 | do | 86 | do |
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 |
78 | done | 98 | done |
79 | 99 | ||
80 | # Create MD5 sum | 100 | # Create MD5 sum |
81 | cat <<-END_README > README | 101 | cat <<-END_README > README |
82 | This is the latest snapshot of nagiosplug, consisting of the following | 102 | This is the latest snapshot of nagiosplug, consisting of the following |
83 | head(s): | 103 | head(s): |
84 | $HEADS | 104 | $HEADS |
85 | 105 | ||
86 | The 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 |
87 | corresponding snapshot (nagios-plugins-<git-describe>.tar.gz). | 107 | corresponding snapshot (nagios-plugins-<git-describe>.tar.gz). |
88 | 108 | ||
89 | For backward-compatibility, the nagios-plugins-HEAD.tar.gz and | 109 | For backward-compatibility, the nagios-plugins-HEAD.tar.gz and |
90 | nagios-plugins-trunk-<ts> point to their corresponding "master" head. | 110 | nagios-plugins-trunk-<ts> point to their corresponding "master" head. |
91 | 111 | ||
92 | The MD5SUM are: | 112 | The MD5SUM are: |
93 | END_README | 113 | END_README |
94 | md5sum *.gz | tee -a README > MD5SUM | 114 | md5sum *.gz | tee -a README > MD5SUM |
95 | 115 | ||
96 | # Sync the files | 116 | # Sync the files |
diff --git a/tools/sfsnapshotgit b/tools/sfsnapshotgit index 155259f0..af05c24b 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) |
11 | set -eu | 11 | set -eu |
12 | trap 'echo "An error occurred at line $LINENO"; exit 1' EXIT | 12 | trap '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 | |||
46 | git clean -qfdx | 46 | git clean -qfdx |
47 | # Any branch used to create snapshots must already exist | 47 | # Any branch used to create snapshots must already exist |
48 | git checkout "$HEAD" | 48 | git checkout "$HEAD" |
49 | git pull "$SFSNAP_ORIGIN" "$HEAD" | 49 | git fetch "$SFSNAP_ORIGIN" "$HEAD" |
50 | git reset --hard "$SFSNAP_ORIGIN"/"$HEAD" | ||
50 | # Tags are important for git-describe | 51 | # Tags are important for git-describe |
51 | git fetch --tags "$SFSNAP_ORIGIN" | 52 | git fetch --tags "$SFSNAP_ORIGIN" |
52 | 53 | ||