5 from wizard import command, deploy, shell
8 options, args = parse_args(argv, baton)
9 d = deploy.ProductionCopy(".")
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))):
23 if os.listdir(os.path.join(backups, d)):
28 logging.warning("Pruned %d empty backups" % count)
33 backup = sorted(os.listdir(backups))[-1]
34 logging.warning("Using backup %s" % backup)
36 raise Exception("No restore points available")
37 bits = backup.split('-')
38 date = '-'.join(bits[-3:])
39 version = '-'.join(bits[0:-3])
40 shell.drop_priviledges(".", options.log_file)
41 d = deploy.ProductionCopy(".")
44 tag = "%s-%s" % (d.application.name, version)
46 shell.call("git", "rev-parse", tag)
47 except shell.CallError:
48 raise Exception("Tag %s doesn't exist in repository" % tag)
49 shell.call("git", "reset", "-q", "--hard", tag)
50 d.restore(backup, options)
52 def parse_args(argv, baton):
53 usage = """usage: %prog restore [ARGS] ID
55 Takes a backup from the backups/ directory and does
56 a full restore back to it. CURRENT DATA IS DESTROYED,
57 so you may want to do a backup before you do a restore.
59 You can specify 'top' as the ID in order to restore from
61 parser = command.WizardOptionParser(usage)
62 options, args = parser.parse_all(argv)
64 parser.error("too many arguments")