Example #1
0
func listDirectoryContents(c *cli.Context, connection connector.Connection) error {
	backupSetUUID := c.String("backup-set-uuid")
	if backupSetUUID == "" {
		return errors.New("backup-set-uuid is mandatory for list-directory-contents")
	}
	folderUUID := c.String("folder-uuid")
	if folderUUID == "" {
		return errors.New("folder-uuid is mandatory for list-directory-contents")
	}
	targetPath := c.String("path")
	if targetPath == "" {
		return errors.New("path is mandatory for list-directory-contents")
	}
	cacheDirectory := c.GlobalString("cache-directory")

	bucket, err := findBucket(c, connection, backupSetUUID, folderUUID)
	if err != nil {
		err := errors.New(fmt.Sprintf("Couldn't find backup set UUID %s, folder UUID %s.", backupSetUUID, folderUUID))
		log.Errorf("%s", err)
		return err
	}
	log.Printf("Caching tree pack sets. If this is your first run, will take a few minutes...")
	backupSet := bucket.ArqBackupSet
	backupSet.CacheTreePackSets()
	log.Printf("Cached tree pack sets.")

	tree, node, err := arq.FindNode(cacheDirectory, backupSet, bucket, targetPath)
	if err != nil {
		log.Errorf("Failed to find target path %s: %s", targetPath, err)
		return err
	}
	if node == nil || node.IsTree.IsTrue() {
		if tree == nil {
			err2 := errors.New(fmt.Sprintf("node is tree but no tree found: %s", node))
			log.Errorf("%s", err2)
			return err2
		}
		apsi, _ := arq.NewPackSetIndex(cacheDirectory, backupSet, bucket)
		for _, node := range tree.Nodes {
			if node.IsTree.IsTrue() {
				tree, err := apsi.GetPackFileAsTree(backupSet, bucket, *node.DataBlobKeys[0].SHA1)
				if err != nil {
					log.Debugf("Failed to find tree for node %s: %s", node, err)
					node.PrintOutput()
				} else if tree == nil {
					log.Debugf("directory node %s has no tree", node)
					node.PrintOutput()
				} else {
					tree.PrintOutput(node)
				}
			} else {
				node.PrintOutput()
			}
		}
	} else {
		node.PrintOutput()
	}
	return nil
}
Example #2
0
func recover(c *cli.Context, connection connector.Connection) error {
	cacheDirectory := c.GlobalString("cache-directory")
	backupSetUUID := c.String("backup-set-uuid")
	folderUUID := c.String("folder-uuid")
	sourcePath := c.String("source-path")
	destinationPath := c.String("destination-path")

	if _, err := os.Stat(destinationPath); err == nil {
		err := errors.New(fmt.Sprintf("Destination path %s already exists, won't overwrite.", destinationPath))
		log.Errorf("%s", err)
		return err
	}
	bucket, err := findBucket(c, connection, backupSetUUID, folderUUID)
	if err != nil {
		err := errors.New(fmt.Sprintf("Couldn't find backup set UUID %s, folder UUID %s.", backupSetUUID, folderUUID))
		log.Errorf("%s", err)
		return err
	}
	log.Printf("Caching tree and blob pack sets. If this is your first run, will take a few minutes...")
	backupSet := bucket.ArqBackupSet
	backupSet.CacheTreePackSets()
	backupSet.CacheBlobPackSets()
	log.Printf("Cached tree and blob pack sets.")

	tree, node, err := arq.FindNode(cacheDirectory, backupSet, bucket, sourcePath)
	log.Debugf("sourcePath: %s, tree: %s, node: %s", sourcePath, tree, node)
	if err != nil {
		log.Errorf("Failed to find source path %s: %s", sourcePath, err)
		return err
	}
	if node == nil || node.IsTree.IsTrue() {
		err = arq.DownloadTree(tree, cacheDirectory, backupSet, bucket, sourcePath, destinationPath)
	} else {
		err = arq.DownloadNode(node, cacheDirectory, backupSet, bucket, sourcePath, destinationPath)
	}
	if err != nil && err != arq.ErrorCouldNotRecoverTree {
		log.Errorf("recover failed to download node: %s", err)
		return err
	}
	return nil
}