I wanted to have a dead simple script to create a backup of the files and the database on the deployer home folder with a capistrano task.
It could use some refactor, and it could be made more flexible in many aspects, but it works and it’s just a small bunch of lines.
There are good backup libraries that you let you encrypt, split, upload to multiple places and be notified whether has been a problem or not. They also take care of automating the restoring process, and let you switch between different versions and remove old backups. Setting that up takes more time though, this script is only valid for simple situations, it doesn’t compare to those libraries but it sure beats not having any script at all.
I added explicitely the PGPASSWORD to the dump command, but there are better ways, you can add a .pgpass file to your home folder, and add a --no-password flag (more info here). You can also add it as an environment variable
Another improvement is to make it run periodically using a cron job: cron-jobs-and-rails
After executing it, you get the lines needed to download the files