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