Changeset 51979
- Timestamp:
- 09/17/07 16:22:25 (2 years ago)
- Files:
-
- CPS3/products/CPSUtil/trunk/CHANGES (modified) (1 diff)
- CPS3/products/CPSUtil/trunk/bin/cpshousekeeping (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
CPS3/products/CPSUtil/trunk/CHANGES
r51804 r51979 4 4 New features 5 5 ~~~~~~~~~~~~ 6 - 6 - Added GZIP compression for ZODB backups in cpshousekeeping. 7 7 Bug fixes 8 8 ~~~~~~~~~ CPS3/products/CPSUtil/trunk/bin/cpshousekeeping
r51628 r51979 39 39 import sys 40 40 import os 41 from gzip import GzipFile 41 42 import base64 42 43 import urllib2 … … 62 63 CPS_LOGIN_URL_PATTERN = "http://%s:%s/%s/logged_in" 63 64 TIME_FORMAT = '%Y-%m-%d_%H:%M' 65 # This regexp matches file names of the form 66 # YYYY-MM-dd_hh:mm-xxxxxxxxxx 67 # Examples: 68 # 2007-09-17_11:24-Data.fs 69 # 2007-09-17_11:24-Data.fs.gz 64 70 ZODB_BACKUP_FILENAME_REGEXP = re.compile(r'\d+-\d{2}-\d{2}_\d{2}:\d{2}-.+') 65 71 SEND_NOTIFICATIONS_PATTERN = "http://%s:%s/%s/cps_subscriptions_schedule_notifications?subscription_mode=%s" … … 69 75 """Analyze command line arguments. 70 76 """ 71 usage = "usage: %prog [options]" 77 usage = """Usage: %prog [options] 78 79 Example: 80 %prog -vrlPb -u admin -w 'xxx' --host localhost -p 8080 -i cps -z /usr/local/zope/instance/cps/var/Data.fs -k /var/backups/zodb/www.mysite.net 81 """ 72 82 parser = OptionParser(usage=usage) 73 83 … … 182 192 "ZODB backups. " 183 193 "The default is %s." % DEFAULT_ZODB_BACKUP_DIR_PATH) 194 195 parser.add_option('--nocompress', 196 action='store_true', 197 dest='nocompress', 198 default=False, 199 help="Don't compress the ZODB backups.") 184 200 185 201 parser.add_option('-B', '--keep-backups-count', … … 250 266 if options.backup: 251 267 backupZodb(options.zodbfile_path, options.backupdir_path, 252 options.backups_keep_count)268 not options.nocompress, options.backups_keep_count) 253 269 254 270 … … 271 287 log("Successfully packed ZODB of host %s" % host_name) 272 288 273 def backupZodb(zodb_path, backupdir_path, backups_keep_count=0):289 def backupZodb(zodb_path, backupdir_path, compress=True, backups_keep_count=0): 274 290 """TODO : backupZodb should WARN and not perform this action if there isn't 275 enough space left on target device. 291 enough space left on target device. But unfortunately this requires parsing 292 of platform specific information and there isn't any native python-way to 293 do this yet. 276 294 """ 277 295 log("Checking for backups ...") … … 282 300 log("command = %s" % command, increment=1) 283 301 os.system(command) 302 if compress: 303 compressFile(zodb_backup_path) 304 284 305 if backups_keep_count > 0: 285 log("There are some backups to remove ...", increment=1) 306 log("Checking for potential backups to remove, " 307 "keeping only the %s ones ..." % backups_keep_count, increment=1) 286 308 file_names = os.listdir(backupdir_path) 287 309 file_names = [x for x in file_names … … 296 318 297 319 320 def compressFile(file_path): 321 """Compress a file using GZIP. 322 """ 323 log("Compressing %s ..." % file_path) 324 f = file(file_path, 'rb') 325 content = f.read() 326 f.close() 327 gzip_file_path = file_path + '.gz' 328 f = GzipFile(gzip_file_path, 'wb') 329 f.write(content) 330 f.close() 331 os.remove(file_path) 332 log("Compressing done : %s" % gzip_file_path) 333 334 298 335 def callUrl(url, username, password): 299 336 """Call urllib2.urlopen with forced HTTP Basic Auth header. … … 301 338 request = urllib2.Request(url) 302 339 base64string = base64.encodestring('%s:%s' % (username, password))[:-1] 303 request.add_header("Authorization", "Basic %s" % base64string) 340 request.add_header('Authorization', 'Basic %s' % base64string) 341 # Adding this to make the request be a POST request, 342 # because those methods need to be POST because they modify 343 # the state of the application. 344 request.add_data("This is a POST method") 304 345 try: 305 346 urllib2.urlopen(request)
