def main(): usage = "%prog [options] backup|restore|purge|list disk|swift|s3 [storage args]" options = [] options.append(make_option("-p", "--prefix", type="string", default="/opt/graphite/storage/whisper", help="Root of where the whisper files live or will be restored to, default %default")) options.append(make_option("-f", "--processes", type="int", default=4, help="Number of worker processes to spawn, default %default")) options.append(make_option("-r", "--retention", type="int", default=5, help="Number of unique backups to retain for each whisper file, default %default")) options.append(make_option("-x", "--purge", type="int", default=45, help="Days to keep unknown Whisper file backups, -1 disables, default %default")) options.append(make_option("-n", "--noop", action="store_true", default=False, help="Do not modify the object store, default %default")) options.append(make_option("-b", "--bucket", type="string", default="graphite-backups", help="The AWS S3 bucket name or Swift container to use, default %default")) options.append(make_option("-m", "--metrics", type="string", default="*", help="Glob pattern of metric names to backup or restore, default %default")) options.append(make_option("-c", "--date", type="string", default=utc(), help="String in ISO-8601 date format. The last backup before this date will be used during the restore. Default is now or %s." % utc())) choices = ["gz"] if snappy is not None: choices.append("sz") options.append(make_option("-a", "--algorithm", type="choice", default="gz", choices=choices, dest="algorithm", help="Compression format to use based on installed Python modules. " \ "Choices: %s" % ", ".join(choices))) options.append(make_option("--storage-path", type="string", default="", help="Path in the bucket to store the backup, default %default")) script = CronScript(usage=usage, options=options) if len(script.args) == 0: logger.info("whisper-backup.py - A Python script for backing up whisper " \ "database trees as used with Graphite") logger.info("Copyright (c) 2014 - 2017 42 Lines, Inc.") logger.info("Original Author: Jack Neely <*****@*****.**>") logger.info("See the README for help or use the --help option.") sys.exit(1) mode = script.args[0].lower() if mode == "backup": with script: # Use splay and lockfile settings script.store = storageBackend(script) backup(script) elif mode == "restore": with script: # Use splay and lockfile settings script.store = storageBackend(script) restore(script) elif mode == "purge": with script: # Use splay and lockfile settings script.store = storageBackend(script) localMetrics = listMetrics(script.options.prefix, script.options.storage_path, script.options.metrics) purge(script, { k: True for k, p in localMetrics }) elif mode == "list": # Splay and lockfile settings make no sense here script.store = storageBackend(script) listbackups(script) else: logger.error("Command %s unknown. Must be one of backup, restore, " \ "purge, or list." % script.args[0]) sys.exit(1)
def main(): usage = "%prog [options] backup|restore|purge|list swift|s3 [storage args]" options = [] options.append( make_option( "-p", "--prefix", type="string", default="/opt/graphite/storage/whisper", help= "Root of where the whisper files live or will be restored to, default %default" )) options.append( make_option( "-f", "--processes", type="int", default=4, help="Number of worker processes to spawn, default %default")) options.append( make_option( "-r", "--retention", type="int", default=5, help= "Number of unique backups to retain for each whisper file, default %default" )) options.append( make_option( "-x", "--purge", type="int", default=45, help= "Days to keep unknown Whisper file backups, 0 disables, default %default" )) options.append( make_option("-n", "--noop", action="store_true", default=False, help="Do not modify the object store, default %default")) options.append( make_option( "-b", "--bucket", type="string", default="graphite-backups", help= "The AWS S3 bucket name or Swift container to use, default %default" )) options.append( make_option( "-m", "--metrics", type="string", default="*", help= "Glob pattern of metric names to backup or restore, default %default" )) options.append( make_option( "-c", "--date", type="string", default=utc(), help= "String in ISO-8601 date format. The last backup before this date will be used during the restore. Default is now or %s." % utc())) script = CronScript(usage=usage, options=options) if len(script.args) == 0: logger.info("whisper-backup.py - A Python script for backing up whisper " \ "database trees as used with Graphite") logger.info("Copyright 2014 42 Lines, Inc.") logger.info("Original Author: Jack Neely <*****@*****.**>") logger.info("See the README for help or use the --help option.") sys.exit(1) mode = script.args[0].lower() if mode == "backup": with script: # Use splay and lockfile settings script.store = storageBackend(script) backup(script) elif mode == "restore": with script: # Use splay and lockfile settings script.store = storageBackend(script) restore(script) elif mode == "purge": with script: # Use splay and lockfile settings script.store = storageBackend(script) purge(script, [ k for k, p in listMetrics(script.options.prefix, script.options.metrics) ]) elif mode == "list": # Splay and lockfile settings make no sense here script.store = storageBackend(script) listbackups(script) else: logger.error("Command %s unknown. Must be one of backup, restore, " \ "purge, or list." % script.args[0]) sys.exit(1)
def main(): usage = "%prog [options] backup|restore|purge|list disk|swift|s3 [storage args]" options = [] options.append( make_option( "-p", "--prefix", type="string", default="/opt/graphite/storage/whisper", help= "Root of where the whisper files live or will be restored to, default %default" )) options.append( make_option( "-f", "--processes", type="int", default=4, help="Number of worker processes to spawn, default %default")) options.append( make_option( "-r", "--retention", type="int", default=5, help= "Number of unique backups to retain for each whisper file, default %default" )) options.append( make_option( "-x", "--purge", type="int", default=45, help= "Days to keep unknown Whisper file backups, 0 disables, default %default" )) options.append( make_option("-n", "--noop", action="store_true", default=False, help="Do not modify the object store, default %default")) options.append( make_option( "-b", "--bucket", type="string", default="graphite-backups", help= "The AWS S3 bucket name or Swift container to use, default %default" )) options.append( make_option( "-m", "--metrics", type="string", default="*", help= "Glob pattern of metric names to backup or restore, default %default" )) options.append( make_option( "-c", "--date", type="string", default=utc(), help= "String in ISO-8601 date format. The last backup before this date will be used during the restore. Default is now or %s." % utc())) options.append( make_option( "--sse-c-key", type="string", dest="sse_c_key", help= "A base64-encoded encryption key for Amazon S3 to use to encrypt or decrypt the data." )) choices = ["gz"] if snappy is not None: choices.append("sz") options.append(make_option("-a", "--algorithm", type="choice", default="gz", choices=choices, dest="algorithm", help="Compression format to use based on installed Python modules. " \ "Choices: %s" % ", ".join(choices))) options.append( make_option( "--storage-path", type="string", default="", help="Path in the bucket to store the backup, default %default")) script = CronScript(usage=usage, options=options) if len(script.args) == 0: logger.info("whisper-backup.py - A Python script for backing up whisper " \ "database trees as used with Graphite") logger.info("Copyright (c) 2014 - 2017 42 Lines, Inc.") logger.info("Original Author: Jack Neely <*****@*****.**>") logger.info("See the README for help or use the --help option.") sys.exit(1) mode = script.args[0].lower() if mode == "backup": with script: # Use splay and lockfile settings script.store = storageBackend(script) backup(script) elif mode == "restore": with script: # Use splay and lockfile settings script.store = storageBackend(script) restore(script) elif mode == "purge": with script: # Use splay and lockfile settings script.store = storageBackend(script) localMetrics = listMetrics(script.options.prefix, script.options.storage_path, script.options.metrics) purge(script, {k: True for k, p in localMetrics}) elif mode == "list": # Splay and lockfile settings make no sense here script.store = storageBackend(script) listbackups(script) else: logger.error("Command %s unknown. Must be one of backup, restore, " \ "purge, or list." % script.args[0]) sys.exit(1)
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ''' Simple test of CronScript functionality ''' from pycronscript import CronScript import logging from optparse import make_option import time OPTIONS = [] OPTIONS.append( make_option("--snarf", action="store_true", help="Snarf snarf snarf")) OPTIONS.append( make_option("--foobar", type="string", default='barbaz', help="Mew mew mew, default %default")) USAGE = "usage: %prog [options] arg1 arg2" with CronScript(options=OPTIONS, usage=USAGE): LOGGER = logging.getLogger(__name__) LOGGER.info('Does this work?') time.sleep(900)
def main(): usage = "%prog [options] backup|restore|purge|list swift|s3 [storage args]" options = [] options.append( make_option( "-p", "--prefix", type="string", default="/opt/graphite/storage/whisper", help="Root of where the whisper files live or will be restored to, default %default", ) ) options.append( make_option( "-f", "--processes", type="int", default=4, help="Number of worker processes to spawn, default %default" ) ) options.append( make_option( "-r", "--retention", type="int", default=5, help="Number of unique backups to retain for each whisper file, default %default", ) ) options.append( make_option( "-x", "--purge", type="int", default=45, help="Days to keep unknown Whisper file backups, 0 disables, default %default", ) ) options.append( make_option( "-n", "--noop", action="store_true", default=False, help="Do not modify the object store, default %default" ) ) options.append( make_option( "-b", "--bucket", type="string", default="graphite-backups", help="The AWS S3 bucket name or Swift container to use, default %default", ) ) options.append( make_option( "-k", "--keyprefix", type="string", default=None, help="The AWS S3 bucket key prefix to use - if empty, all files will be put into the root of the bucket %default", ) ) options.append( make_option( "-m", "--metrics", type="string", default="*", help="Glob pattern of metric names to backup or restore, default %default", ) ) options.append( make_option( "-c", "--date", type="string", default=utc(), help="String in ISO-8601 date format. The last backup before this date will be used during the restore. Default is now or %s." % utc(), ) ) script = CronScript(usage=usage, options=options) if len(script.args) == 0: logger.info( "whisper-backup.py - A Python script for backing up whisper " "database trees as used with Graphite" ) logger.info("Copyright 2014 42 Lines, Inc.") logger.info("Original Author: Jack Neely <*****@*****.**>") logger.info("See the README for help or use the --help option.") sys.exit(1) mode = script.args[0].lower() if mode == "backup": with script: # Use splay and lockfile settings script.store = storageBackend(script) backup(script) elif mode == "restore": with script: # Use splay and lockfile settings script.store = storageBackend(script) restore(script) elif mode == "purge": with script: # Use splay and lockfile settings script.store = storageBackend(script) purge(script, [k for k, p in listMetrics(script.options.prefix, script.options.metrics)]) elif mode == "list": # Splay and lockfile settings make no sense here script.store = storageBackend(script) listbackups(script) else: logger.error("Command %s unknown. Must be one of backup, restore, " "purge, or list." % script.args[0]) sys.exit(1)