5 import distutils.version
7 from wizard import command, deploy, git, shell, util
10 options, args = parse_args(argv, baton)
11 backups = ".scripts/backups"
13 if not os.path.exists(backups):
14 print "No restore points available"
16 sys.stderr.write("Available backups:\n")
18 for d in reversed(sorted(os.listdir(backups))):
21 if os.listdir(os.path.join(backups, d)):
26 logging.warning("Pruned %d empty backups" % count)
31 backup = sorted(os.listdir(backups))[-1]
33 raise Exception("No restore points available")
34 bits = backup.split('-')
35 date = '-'.join(bits[-3:])
36 version = '-'.join(bits[0:-3])
37 shell.drop_priviledges(".", options.log_file)
38 d = deploy.Deployment(".")
41 tag = "%s-%s" % (d.application.name, version)
44 sh.call("git", "rev-parse", tag)
45 except shell.CallError:
46 raise Exception("Tag %s doesn't exist in repository" % tag)
47 sh.call("git", "reset", "-q", "--hard", tag)
48 d.restore(backup, options)
50 def parse_args(argv, baton):
51 usage = """usage: %prog restore [ARGS] ID
53 Takes a backup from the backups/ directory and does
54 a full restore back to it. CURRENT DATA IS DESTROYED,
55 so you may want to do a backup before you do a restore.
57 You can specify 'top' as the ID in order to restore from
59 parser = command.WizardOptionParser(usage)
60 options, args = parser.parse_all(argv)
62 parser.error("too many arguments")