Skip to content

Instantly share code, notes, and snippets.

View cpanderson's full-sized avatar

Christopher Anderson cpanderson

View GitHub Profile
@cpanderson
cpanderson / backup.rake
Last active May 2, 2021 15:29
Rails Postgres Database Snapshots
namespace :db do
desc "Backup the database to a file and manage archives"
task :backup => [:environment] do
datestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
database = Rails.env.downcase
max_backups = 48
base_path = "db"
backup_base = File.join(base_path, 'backups')
backup_file = "#{Rails.env}_#{datestamp}.db.gz"
backup_file_path = File.join(backup_base, backup_file)