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