|
| 1 | +#!/usr/bin/env superdoit_solo |
| 2 | +instvars |
| 3 | +% |
| 4 | +options |
| 5 | +{ |
| 6 | + SuperDoitOptionalOptionWithNoArg long: 'recovery' short: 'R'. |
| 7 | +} |
| 8 | +% |
| 9 | +usage |
| 10 | +----- |
| 11 | +USAGE $basename [--help] [-R] stone-name [snapshot-file-path] [file-media-type] |
| 12 | + |
| 13 | +DESCRIPTION |
| 14 | + Copy a fresh extent file to the given stone's extent directory. |
| 15 | + |
| 16 | +OPTIONS |
| 17 | + -h, --help display usage message |
| 18 | + -R, --recovery Copy a fresh extent file to the given stones extent directory, in preparation for a restore from backup. |
| 19 | + Tranlog files are not removed, so that they can be used for recovery. |
| 20 | + See http://downloads.gemtalksystems.com/docs/GemStone64/3.2.x/GS64-SysAdmin-3.2/GS64-SysAdmin-3.2.htm for more info. |
| 21 | + |
| 22 | +EXAMPLES |
| 23 | + $basename --help |
| 24 | + $basename myStone |
| 25 | + $basename myStone /opt/snapshots/mySnapshop.dbf |
| 26 | + $basename myStone /opt/snapshots/mySnapshot.dbf.gz x-gzip |
| 27 | + %basename -R myStone /opt/snapshots/mySnapshot.dbf |
| 28 | +----- |
| 29 | +% |
| 30 | +method |
| 31 | +newExtent |
| 32 | + | stoneDirectory extentFile tempenvvalue | |
| 33 | + (self positionalArgs size == 0 or:[ self recovery & (self positionalArgs size < 2) ]) ifTrue: [ |
| 34 | + ^ Error signal: 'Wrong number of arguments (' , self positionalArgs size printString , ')' ]. |
| 35 | + tempenvvalue := System gemEnvironmentVariable: 'GEMSTONE'. |
| 36 | + System gemEnvironmentVariable: 'GEMSTONE' put: (System gemEnvironmentVariable: 'TARGET_GEMSTONE'). |
| 37 | + stoneDirectory := self gs_stoneDirectory. |
| 38 | + self stderr |
| 39 | + nextPutAll: 'New extent for '; |
| 40 | + nextPutAll: self stoneName; |
| 41 | + cr. |
| 42 | + extentFile := stoneDirectory / 'extents' / 'extent0.dbf'. |
| 43 | + extentFile exists |
| 44 | + ifTrue: [ extentFile delete ]. |
| 45 | + self mediaType = 'x-gzip' |
| 46 | + ifTrue: [ self gunzipSnapshotExtent: stoneDirectory ] |
| 47 | + ifFalse: [ self copySnapshotExtent: stoneDirectory ]. |
| 48 | + self stderr |
| 49 | + nextPutAll: 'Finished copying new extent for '; |
| 50 | + nextPutAll: self stoneName; |
| 51 | + cr. |
| 52 | + self recovery |
| 53 | + ifFalse:[ self removeTranlogs ]. |
| 54 | + System gemEnvironmentVariable: 'GEMSTONE' put: tempenvvalue. |
| 55 | +^ self noResult |
| 56 | +% |
| 57 | +method |
| 58 | +snapshotFile |
| 59 | + self positionalArgs size < 2 ifTrue: [ ^ self gs_binDirectory / 'extent0.seaside.dbf' ]. |
| 60 | + ^ (self positionalArgs at: 2) asFileReference |
| 61 | +% |
| 62 | +method |
| 63 | +mediaType |
| 64 | + self positionalArgs size < 3 ifTrue: [ ^ 'octet-stream' ]. |
| 65 | + ^ self positionalArgs at: 3 |
| 66 | +% |
| 67 | +method |
| 68 | +copySnapshotExtent: stoneDirectory |
| 69 | + "use copydbf, so that any corruption in the extent file can be found at the outset" |
| 70 | + |
| 71 | + self copySnapshotExtent: self snapshotFile to: stoneDirectory for: self stoneInfo gsVers |
| 72 | +% |
| 73 | +method |
| 74 | +copySnapshotExtent: snapshotExtentFile to: stoneDirectory for: aGsVersionString |
| 75 | + "use copydbf, so that any corruption in the extent file can be found at the outset" |
| 76 | + |
| 77 | + | extentFile cmdPath | |
| 78 | + self stderr |
| 79 | + nextPutAll: 'Copying extent file: '; |
| 80 | + nextPutAll: snapshotExtentFile pathString printString; |
| 81 | + cr. |
| 82 | + extentFile := stoneDirectory / 'extents' / 'extent0.dbf'. |
| 83 | + cmdPath := (aGsVersionString beginsWith: '2.4') |
| 84 | + ifTrue: [ |
| 85 | + "cannot use copydbf to copy extent from product tree, so unconditionally use `cp`" |
| 86 | + '/bin/cp' ] |
| 87 | + ifFalse: [ (self gs_binDirectory / 'copydbf') pathString ]. |
| 88 | + self stderr |
| 89 | + nextPutAll: (GsHostProcess execute: cmdPath, ' "',(snapshotExtentFile pathString),'" "', (extentFile pathString), '"'); |
| 90 | + cr. |
| 91 | + cmdPath := (GsHostProcess execute: '/usr/bin/which chmod') trimBoth. |
| 92 | + GsHostProcess execute: cmdPath, ' +w "' , extentFile pathString, '"' |
| 93 | +% |
| 94 | +method |
| 95 | +gunzipSnapshotExtent: stoneDirectory |
| 96 | + | extentDir cmdPath | |
| 97 | + extentDir := stoneDirectory / 'extents'. |
| 98 | + self stderr |
| 99 | + nextPutAll: 'Gunzipping extent file: '; |
| 100 | + nextPutAll: self snapshotFile pathString printString; |
| 101 | + nextPutAll: ' (copying to '; |
| 102 | + nextPutAll: extentDir pathString printString; |
| 103 | + nextPutAll: ' first)'; |
| 104 | + cr. |
| 105 | + cmdPath := '/bin/cp'. |
| 106 | + self stderr |
| 107 | + nextPutAll: (GsHostProcess execute: cmdPath,' "',(self snapshotFile pathString), '" "',((extentDir / 'extent0.dbf.gz') pathString), '"'); |
| 108 | + cr. |
| 109 | + cmdPath := (GsHostProcess execute: '/usr/bin/which gunzip') trimBoth. |
| 110 | + self stderr |
| 111 | + nextPutAll: (GsHostProcess execute: cmdPath,' "', ((extentDir / 'extent0.dbf.gz') pathString), '"'); |
| 112 | + cr |
| 113 | +% |
| 114 | +method |
| 115 | +removeTranlogs |
| 116 | + self stderr |
| 117 | + nextPutAll: 'Removing tranlogs for '; |
| 118 | + nextPutAll: self stoneName; |
| 119 | + cr. |
| 120 | + self removeTranlogs: self tranlogsHome. |
| 121 | + self stderr |
| 122 | + nextPutAll: 'Finished removing tranlogs for '; |
| 123 | + nextPutAll: self stoneName; |
| 124 | + cr. |
| 125 | +% |
| 126 | +method |
| 127 | +removeTranlogs: tranlogDirectory |
| 128 | + tranlogDirectory deleteAllChildren |
| 129 | +% |
| 130 | +method |
| 131 | +tranlogsHome |
| 132 | + ^ self gs_stoneDirectory / 'tranlogs' |
| 133 | +% |
| 134 | +method |
| 135 | +gs_stonesDirectory |
| 136 | + ^ ((System gemEnvironmentVariable: 'GS_HOME'), '/server/stones') asFileReference |
| 137 | +% |
| 138 | +method |
| 139 | +gs_stoneDirectory |
| 140 | + ^ self gs_stonesDirectory / self stoneName |
| 141 | +% |
| 142 | +method |
| 143 | +stoneName |
| 144 | + ^ self positionalArgs at: 1 |
| 145 | +% |
| 146 | +method |
| 147 | +stoneInfoClass |
| 148 | + ^ GsDevKitStoneInfo |
| 149 | +% |
| 150 | +method |
| 151 | +stoneInfoFilename |
| 152 | + ^ 'info.ston' |
| 153 | +% |
| 154 | +method |
| 155 | +stoneInfo |
| 156 | + ^ self stoneInfoClass importFrom: self gs_stoneDirectory / self stoneInfoFilename |
| 157 | +% |
| 158 | +method |
| 159 | +gs_binDirectory |
| 160 | + ^ (self gs_stoneDirectory / 'product' / 'bin') asFileReference |
| 161 | +% |
| 162 | +method |
| 163 | +doit |
| 164 | + "override doit method, because ChildError does not exist in 3.6.0" |
| 165 | + [ |
| 166 | + self getAndVerifyOptions == self noResult |
| 167 | + ifTrue: [ ^ self noResult ]. |
| 168 | + ^ self theDoit |
| 169 | + ] |
| 170 | + on: Error |
| 171 | + do: [ :ex | |
| 172 | + ((self respondsTo: #'debug') and: [ self debug ]) |
| 173 | + ifTrue: [ ex pass ]. |
| 174 | + self |
| 175 | + exit: ((ex respondsTo: #stderr) |
| 176 | + ifTrue: [ ex stderr asString trimBoth ] |
| 177 | + ifFalse: [ ex messageText ]) |
| 178 | + withStatus: 1 "does not return" ]. |
| 179 | +% |
| 180 | +doit |
| 181 | + self newExtent |
| 182 | +% |
0 commit comments