bin/pvl.backup-snapshot
changeset 80 b332d99f988e
parent 65 462cecaa70d0
equal deleted inserted replaced
79:d084df6da61c 80:b332d99f988e
     8     Updates symlink <dst>/current -> <dst>/snapshots/...
     8     Updates symlink <dst>/current -> <dst>/snapshots/...
     9 
     9 
    10     Then archives <dst>/current to <dst>/<period>/<date> using --link-dest.
    10     Then archives <dst>/current to <dst>/<period>/<date> using --link-dest.
    11 """
    11 """
    12 
    12 
       
    13 import pvl.args
    13 from pvl.backup import __version__
    14 from pvl.backup import __version__
    14 from pvl.backup import rsync, invoke
    15 from pvl.backup import rsync, invoke
    15 
    16 
    16 import optparse, ConfigParser
    17 import optparse, ConfigParser
    17 import os, os.path, stat
    18 import os, os.path, stat
    37             # module docstring
    38             # module docstring
    38             # XXX: breaks multi-line descriptions..
    39             # XXX: breaks multi-line descriptions..
    39             description = __doc__,
    40             description = __doc__,
    40     )
    41     )
    41 
    42 
    42     # logging
    43     parser.add_option_group(pvl.args.parser(parser, config=False))
    43     general = optparse.OptionGroup(parser, "General Options")
       
    44 
       
    45     general.add_option('-q', '--quiet',      dest='loglevel', action='store_const', const=logging.WARNING, help="Less output")
       
    46     general.add_option('-v', '--verbose',    dest='loglevel', action='store_const', const=logging.INFO,  help="More output")
       
    47     general.add_option('-D', '--debug',      dest='loglevel', action='store_const', const=logging.DEBUG, help="Even more output")
       
    48 
       
    49     parser.add_option_group(general)
       
    50 
    44 
    51     # rsync
    45     # rsync
    52     rsync = optparse.OptionGroup(parser, "rsync Options")
    46     rsync = optparse.OptionGroup(parser, "rsync Options")
    53 
    47 
    54     rsync.add_option('--exclude-from',       metavar='FILE',
    48     rsync.add_option('--exclude-from',       metavar='FILE',
    71 
    65 
    72     parser.add_option('-n', '--noop',       action='store_true',
    66     parser.add_option('-n', '--noop',       action='store_true',
    73         help="Don't actually clean anything")
    67         help="Don't actually clean anything")
    74 
    68 
    75     #
    69     #
    76     parser.add_option('-c', '--config',     metavar='FILE/DIR', action='append',    # multi
    70     parser.add_option('-c', '--config',    metavar='FILE/DIR', action='append',    # multi
    77         help="Load configuration file(s)")
    71         help="Load configuration file(s)")
    78 
    72 
    79     parser.add_option('-r', '--run',        metavar='NAME',
    73     parser.add_option('-r', '--run',        metavar='NAME',
    80         help="Run given set of targets, per config [run/...]")
    74         help="Run given set of targets, per config [run/...]")
    81 
    75 
    90         help="Run target with given given interval(s)")
    84         help="Run target with given given interval(s)")
    91 
    85 
    92 
    86 
    93     # defaults
    87     # defaults
    94     parser.set_defaults(
    88     parser.set_defaults(
    95         loglevel            = logging.INFO,
       
    96         
       
    97         config              = [],
    89         config              = [],
    98         target_intervals    = [],
    90         target_intervals    = [],
    99     )
    91     )
   100     parser.set_defaults(**defaults)
    92     parser.set_defaults(**defaults)
   101 
    93 
   102     
       
   103     # parse
    94     # parse
   104     options, args = parser.parse_args(argv[1:])
    95     options, args = parser.parse_args(argv[1:])
   105 
    96     
   106     # configure
    97     # general logging/etc
   107     logging.basicConfig(
    98     pvl.args.apply(options)
   108         format  = argv[0] + ': %(name)s: %(levelname)s %(funcName)s : %(message)s',
       
   109         level   = options.loglevel,
       
   110     )
       
   111 
    99 
   112     if options.clean :
   100     if options.clean :
   113         options.clean_intervals = options.clean_snapshots = options.clean
   101         options.clean_intervals = options.clean_snapshots = options.clean
   114 
   102 
   115     if options.include_from :
   103     if options.include_from :