PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 1ms

/silverlining/mgr-scripts/backup-services.py

https://bitbucket.org/ianb/silverlining/
Python | 32 lines | 27 code | 4 blank | 1 comment | 5 complexity | fb5e3b4818518c266fc68ac188d080e5 MD5 | raw file
 1#!/usr/bin/env python
 2import sys
 3sys.path.insert(0, '/usr/local/share/silverlining/lib')
 4import os
 5import optparse
 6import time
 7from silversupport import appdata
 8from silversupport.appconfig import AppConfig
 9from silversupport.util import unique_name
10
11parser = optparse.OptionParser(
12    usage='%prog LOCATION')
13
14
15def main():
16    options, args = parser.parse_args()
17    location = args[0]
18    instance_name = appdata.instance_for_location(*appdata.normalize_location(location))
19    if not instance_name:
20        print 'Could not match against location: %s' % location
21        sys.exit(1)
22    app_config = AppConfig.from_instance_name(instance_name)
23    dest_dir = os.path.join('/var/lib/silverlining/backups', app_config.app_name)
24    if not os.path.exists(dest_dir):
25        os.makedirs(dest_dir)
26    dirname = 'backup-%s-%s' % (app_config.app_name, time.strftime('%Y-%m-%d'))
27    dirname = unique_name(dest_dir, dirname)
28    app_config.backup_services(dirname)
29    print 'backup="%s"' % dirname
30
31if __name__ == '__main__':
32    main()