Usually when using capistrano, I will go and manually delete old releases from a deployed application. I understand that you can run cap deploy:cleanup
but that still leaves 5 releases. Is this it's intended purpose? Is there another way to cleanup old releases to just 1 previous deploy?
-
it's ever a good idea to keep some previous releases, then if you last deploy contains a big mistake you can fast rollback with capistrano (cap deploy:rollback) to the previous release until you fix it. – damoiser Dec 05 '13 at 12:00
4 Answers
You can use the :keep_releases
variable to override the default of 5. Check this out.

- 7,247
- 1
- 33
- 46

- 11,576
- 4
- 31
- 32
-
2May be worth noting that even if the find+rm command fails to remove some files the task seems to silently "succeed" when called via the `after` hook. Calling it directly shows the errors... I realized this when I was starting to run out of disk space. – conny Jul 14 '10 at 10:48
-
8@Josh You accepted this answer, but you should check if you have set the callback for "deploy:cleanup" as I said below, since it don't run by default. – Diego Plentz May 31 '12 at 00:39
You could do this automatically by setting this in your deploy.rb
set :keep_releases, 1
after "deploy:update", "deploy:cleanup"
In the past(I don't know exactly which version) this callback was the default, but later the developer decided to leave it to the user to decide. In capistrano 3 it was added back to the default deploy flow.

- 6,760
- 3
- 30
- 31
-
1
-
2Looks like [Capistrano 3 calls `deploy:cleanup` as part of the deploy flow](https://github.com/capistrano/capistrano/blob/690afc0c5c3c43d2920b0bfdeb9323c286b12106/lib/capistrano/tasks/deploy.rake#L23). – Dennis Oct 13 '15 at 13:10
If you want to delete all releases except the last 3 for example you can run:
cap deploy:cleanup -s keep_releases=3

- 583
- 4
- 8
I had a similar problem. I wanted to keep the 5 releases for normal deployments but needed for certain situations to be able to remove all previous releases.
I was able to do this with a custom task. Create a file lib/capistrano/tasks/cleanup.rake
and add the following code.
desc "Remove all but the last release"
task :cleanup_all do
set :keep_releases, 1
invoke "deploy:cleanup"
end
To run use bundle exec cap staging cleanup_all
or cap staging cleanup_all

- 527
- 5
- 17