func main() {
	app := cli.NewApp()
	app.Name = "blobstash-glacier"
	app.Usage = "BlobStash glacier restore tools"
	app.Version = "0.1.0"
	app.Commands = []cli.Command{
		{
			Name:      "status",
			ShortName: "status",
			Usage:     "display information about the given vault",
			Action: func(c *cli.Context) {
				con := util.GetCon("")
				vault, _ := con.DescribeVault(c.Args().First())
				fmt.Printf("Vault name:         : %v\n", vault.VaultName)
				fmt.Printf("Creation date:      : %v\n", vault.CreationDate)
				fmt.Printf("Last inventory date : %v\n", vault.LastInventoryDate)
				fmt.Printf("Number of archives  : %v\n", vault.NumberOfArchives)
				fmt.Printf("Size                : %v\n", vault.SizeInBytes)
			},
		},
		{
			Name:      "sync",
			ShortName: "sync",
			Usage:     "fetch the latest inventory and sync the local database",
			Action: func(c *cli.Context) {
				con := util.GetCon("")
				db, err := util.GetDB()
				defer db.Close()
				if err != nil {
					panic(err)
				}
				if err := util.Sync(con, db, c.Args().First()); err != nil {
					panic(err)
				}
			},
		},
		{
			Name:      "restore",
			ShortName: "restore",
			Usage:     "restore previously synced archives from local database",
			Action: func(c *cli.Context) {
				con := util.GetCon("")
				db, err := util.GetDB()
				defer db.Close()
				if err != nil {
					panic(err)
				}
				if err := util.Restore(con, db, c.Args().First()); err != nil {
					panic(err)
				}
			},
		},
	}
	app.Run(os.Args)
}
Exemple #2
0
func New(vault, region, cacheDir string, compression bool) *GlacierBackend {
	log.Println("GlacierBackend: starting")
	accessKey := os.Getenv("S3_ACCESS_KEY")
	secretKey := os.Getenv("S3_SECRET_KEY")
	if accessKey == "" || secretKey == "" {
		panic("S3_ACCESS_KEY or S3_SECRET_KEY not set")
	}
	con := util.GetCon(region)
	//db, err := util.GetDB()
	//if err != nil {
	//	panic(fmt.Errorf("Error initializing DB at %v: %v", util.DBPath, err))
	//}
	glacierPubSub := pubsub.NewPubSub("glacier")
	cache := blobsfile.New(cacheDir, 0, compression, true)
	b := &GlacierBackend{vault, cache, con, glacierPubSub}
	if err := con.CreateVault(vault); err != nil {
		panic(fmt.Errorf("Error creating vault: %v", err))
	}
	// Move this to glacier backend to trigger the done and add a client func
	glacierPubSub.Listen()
	go func(b *GlacierBackend) {
		for {
			<-b.pubsub.Msgc
			log.Println("GlacierBackend: Upload triggered")
			if err := b.Upload(); err != nil {
				panic(fmt.Errorf("failed to upload %v", err))
			}
		}
	}(b)
	return b
}