Example #1
0
int cmd_list(int argc, char *argv[])
{
  storage_t storage;
  const char *elem;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "list", NULL };
    return cmd_help(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], 0)) == NULL)
    errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]);

  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    printf("%s\n", elem);
    elem = storage_list(storage, NULL);
  }

  storage_delete(storage);

  return EXIT_SUCCESS;
}
Example #2
0
int cmd_purge(int argc, char *argv[])
{
  storage_t storage;
  strset_t backups;
  strset_t objects;
  const char *elem;
  struct mark_backup_args args;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "purge", NULL };
    return cmd_help_err(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], false, true)) == NULL)
    logger(LOG_ERROR, "unable to open storage: %s", argv[1]);

  if (!storage_lock(storage, true, options_get()->force))
    logger(LOG_ERROR, "backup directory locked, use -f to force operation");

  backups = strset_new();
  objects = strset_new();

  /* Get the list of backups. */
  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    strset_add(backups, elem);
    elem = storage_list(storage, NULL);
  }

  /* Get the list of objects. */
  elem = storage_list(storage, "objects");
  while (elem != NULL)
  {
    strset_add(objects, elem);
    elem = storage_list(storage, NULL);
  }

  /*
  ** For each backup, call mark_backup, which will mark all the objects of a
  ** backup as used (it will actually remove them from the `objects` strset.
  */
  args.objects = objects;
  args.storage = storage;
  strset_foreach(backups, mark_backup, &args);

  /* Delete every object remaining in the `objects` strset. */
  strset_foreach(objects, delete_object, (void *) storage);

  strset_delete(backups);
  strset_delete(objects);
  storage_unlock(storage);
  storage_delete(storage);

  return EXIT_SUCCESS;
}