# Circle Bug Error Restoring Cache

**URL:** <https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422>\
**Category:** Build Environment\
**Created:** [November 6, 2015, 9:29pm UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422 "2015-11-06T21:29:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravifly9](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@ravifly9](https://discuss.circleci.com/u/ravifly9)\
**Post date:** [November 6, 2015, 9:29pm UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/1 "2015-11-06T21:29:21Z")

</div>

Last 24 hours, we have been seeing this error. Any body has similar issues?

CircleCI team, can you guys help us out ?

Looks like we had a bug in our infrastructure, or that of our providers (generally GitHub or AWS) We should have automatically retried this build. We’ve been alerted of the issue and are almost certainly looking into it, please contact us if you’re interested in the cause of the problem.

---

<div class="post-metadata">

**Author:** ![frank](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/frank/32/124_2.png) [@frank](https://discuss.circleci.com/u/frank)\
**Post date:** [November 6, 2015, 11:31pm UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/2 "2015-11-06T23:31:07Z")

</div>

Hi there,

This bug typically occurs when directories outside of the `$HOME` directory have been cached. You should be able to get things working again by removing these directories from the `cache_directories` part of your `circle.yml` file. If you _really_ need to cache things outside of `$HOME`, you can do so by following these steps:

1. `cp` the files you’d like to cache into somewhere inside the `$HOME` directory before the cache is saved (e.g. `dependencies: post:` in your `circle.yml`).
2. Use `sudo cp` to put the files back to where you need them, after the cache is restored (e.g. `machine: post:` in your `circle.yml`).
3. Add the directory you created inside `$HOME` to your `cache_directories`.

Example circle.yml:

```auto
machine:
  post:
    - cp -r /usr/local/bin/git $HOME/git
dependencies:
  cache_directories:
    - $HOME/git
  post:
    - sudo cp -r $HOME/git /usr/local/bin/git

```

Hope this helps! If this solves your problem, please mark this thread as solved by clicking on the checkbox below.

Cheers,  
Frank

---

<div class="post-metadata">

**Author:** ![dleblanc](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@dleblanc](https://discuss.circleci.com/u/dleblanc)\
**Post date:** [November 7, 2015, 8:37pm UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/3 "2015-11-07T20:37:45Z")

</div>

Hi Frank - I work with Ravi – we’re still seeing an error even though we’ve removed the lines outside of /home (this really should be documented).

The issue being that when the system tries to restore the old cache, it still tries to restore the directories outside of /home. At this stage the only way we can get a green build is to manually “rebuild without cache” - but doing that doesn’t wipe out those old invalid cache entries.

Is there a way to wipe out the cache, so we can start with a blank slate?

---

<div class="post-metadata">

**Author:** ![DevendraMeena1](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/devendrameena1/32/302_2.png) [@DevendraMeena1](https://discuss.circleci.com/u/DevendraMeena1)\
**Post date:** [November 9, 2015, 3:33am UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/4 "2015-11-09T03:33:53Z")

</div>

Normally you will not have to clear the cache permanently, but if you  
feel that’s what you need, you can just remove the necessary parts of  
the cache anywhere in your circle.yml’s dependencies section,  
before the cache is saved:

dependencies:  
post:  
- rm -r ~/.gradle

---

<div class="post-metadata">

**Author:** ![dleblanc](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@dleblanc](https://discuss.circleci.com/u/dleblanc)\
**Post date:** [November 9, 2015, 6:27am UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/5 "2015-11-09T06:27:28Z")

</div>

Folks, I think you’re missing what we’re saying here.

The error now is not in the saving of the cache (that now works fine, and we’ve removed non-home entries) - it’s in the restoration of the cache from previous builds (that had entries in /var and such) - meaning there’s nothing we can do prior to that step to make it work.

The issue being the cache still has entries to /var and such (from the older builds), so whenever we perform a new build, it errors out when it tries to restore the cache.

Is there a way to wipe out the cache entirely? “build without cache” doesn’t seem to do it for us - the next automated builds just fail with the same old restore error.

---

<div class="post-metadata">

**Author:** ![DevendraMeena1](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/devendrameena1/32/302_2.png) [@DevendraMeena1](https://discuss.circleci.com/u/DevendraMeena1)\
**Post date:** [November 9, 2015, 8:38am UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/6 "2015-11-09T08:38:35Z")

</div>

hubot circle clear / - Clears the cache for the specified repo

hubot circle clear all - Clears the cache for all projects. Requires HUBOT\_GITHUB\_ORG

---

<div class="post-metadata">

**Author:** ![dleblanc](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@dleblanc](https://discuss.circleci.com/u/dleblanc)\
**Post date:** [November 9, 2015, 10:37pm UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/7 "2015-11-09T22:37:10Z")

</div>

Excellent - thanks for that tip - I forgot that cache management might be offered by your API. That looks to have solved the problems we were having.

Now on to making the build faster!

Thanks again,

-Dave

---

<div class="post-metadata">

**Author:** ![Eric](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eric/32/2759_2.png) [@Eric](https://discuss.circleci.com/u/Eric)\
**Post date:** [June 30, 2016, 11:38am UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/8 "2016-06-30T11:38:32Z")

</div>

I just want to add a little more explanation to this post for users who are reading through this today.

Cache restore downloads a tarball of a directory you specied, and then attempts to un-tar it into the location you specify. When you specify a folder not owned by the `ubuntu` user, the untar will have a permissions error.

While it’s possible to hack around this by using `sudo chown`, that doesn’t always work. I believe this is due to your build containers being unprivileged lxc containers, so certain superuser commands will be ignored. That’s why it’s best to keep anything you want to cache in the one folder you’re guaranteed full permissions to: your home folder.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:37am UTC](https://discuss.circleci.com/t/circle-bug-error-restoring-cache/422/9 "2018-06-18T11:37:35Z")

</div>

Closed on June 18, 2018, 11:37am UTC


